Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Xientraa/The-Sims-Resource-Downloader
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.4.1
Choose a base ref
...
head repository: Xientraa/The-Sims-Resource-Downloader
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.4.2
Choose a head ref
  • 3 commits
  • 3 files changed
  • 1 contributor

Commits on Jan 19, 2024

  1. Copy the full SHA
    70697ab View commit details

Commits on Jan 24, 2024

  1. fix: invalid captcha code

    Xientraa committed Jan 24, 2024
    Copy the full SHA
    27b5c14 View commit details
  2. Copy the full SHA
    639a01d View commit details
Showing with 67 additions and 52 deletions.
  1. +9 −1 README.md
  2. +1 −1 src/TSRSession.py
  3. +57 −50 src/main.py
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -6,15 +6,23 @@ I created this tool because I found it infuriating to download stuff from The Si

With this tool you can download multiple items at once, to download items copy the url of the item, the tool monitors your clipboard for valid URLs to download from, and will automatically start downloading the item to the supplied directory in the `config.json` file.

For a fully in-depth guide of how to setup and use this tool, check out the [Wiki](https://github.com/Xientraa/The-Sims-Resource-Downloader/wiki).

## Configuration

| Option | Description | type |
| - | - | - |
| downloadDirectory | Path to a directory where the files will be downloaded to. | string |
| maxActiveDownloads | Limits the max amount of active downloads to the value set. | integer |
| maxActiveDownloads | Limits the amount of concurrent downloads. | integer |
| saveDownloadQueue | Toggles saving & loading of active downloads & queued downloads. | boolean |
| debug | Toggles debug messages from the logger. | boolean |

## Setting Up Environment

```sh
python -m venv ./env/
```

## Installing Requirements

```pip
2 changes: 1 addition & 1 deletion src/TSRSession.py
Original file line number Diff line number Diff line change
@@ -87,6 +87,6 @@ def __openImageInBrowser(self) -> None:
def __getTSRDLTicketCookie(self) -> str:
logger.debug("Getting TSRDLTicket cookie")
response = self.session.get(
f"https://www.thesimsresource.com/ajax.php?c=downloads&a=initDownload&itemid=1646133&format=zip"
f"https://www.thesimsresource.com/ajax.php?c=downloads&a=initDownload&itemid=1646133&setItems=&format=zip"
)
return response.cookies.get("tsrdlticket")
107 changes: 57 additions & 50 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ def processTarget(url: TSRUrl, tsrdlsession: str, downloadPath: str):


def callback(url: TSRUrl):
logger.debug(f"Removing {url.url} from queue")
runningDownloads.remove(url.url)
logger.debug(f"Removing {url.itemId} from queue")
runningDownloads.remove(url.itemId)
updateUrlFile()
if len(runningDownloads) == 0:
logger.info("All downloads have been completed")
@@ -32,14 +32,17 @@ def updateUrlFile():
logger.debug(f"Updating URL file")
if CONFIG["saveDownloadQueue"]:
open(CURRENT_DIR + "/urls.txt", "w").write(
"\n".join([*runningDownloads, *downloadQueue])
"\n".join(
[DETAILS_URL + str(id) for id in [*runningDownloads, *downloadQueue]]
)
)


if __name__ == "__main__":
DETAILS_URL = "https://www.thesimsresource.com/downloads/details/id/"
lastPastedText = ""
runningDownloads: list[str] = []
downloadQueue: list[str] = []
runningDownloads: list[int] = []
downloadQueue: list[int] = []

logger.debug(f'downloadDirectory: {CONFIG["downloadDirectory"]}')
logger.debug(f'maxActiveDownloads: {CONFIG["maxActiveDownloads"]}')
@@ -70,20 +73,24 @@ def updateUrlFile():

if os.path.exists(CURRENT_DIR + "/urls.txt") and CONFIG["saveDownloadQueue"]:
for url in open(CURRENT_DIR + "/urls.txt", "r").read().split("\n"):
if url.strip() == "" or url in downloadQueue:
try:
url = TSRUrl(url)
if url.itemId in downloadQueue:
continue
downloadQueue.append(url.itemId)
except InvalidURL:
continue
downloadQueue.append(url.strip())

while True:
pastedText = clipboard.paste()
if lastPastedText == pastedText:
for url in downloadQueue:
for id in downloadQueue:
if len(runningDownloads) == CONFIG["maxActiveDownloads"]:
break

url = TSRUrl(url)
runningDownloads.append(url.url)
downloadQueue.remove(url.url)
url = TSRUrl(DETAILS_URL + str(id))
runningDownloads.append(url.itemId)
downloadQueue.remove(url.itemId)
logger.info(f"Moved {url.url} from queue to downloading")
pool = Pool(1)
pool.apply_async(
@@ -101,50 +108,50 @@ def updateUrlFile():
else:
lastPastedText = pastedText
for line in pastedText.split("\n"):
if line in runningDownloads:
try:
url = TSRUrl(line)
except InvalidURL:
continue

if url.itemId in runningDownloads:
logger.info(f"Url is already being downloaded: {line}")
continue
if line in downloadQueue:
if url.itemId in downloadQueue:
logger.info(
f"Url is already in queue (#{downloadQueue.index(line)}): {line}"
)
continue

try:
url = TSRUrl(line)
requirements = TSRUrl.getRequiredItems(url)
logger.info(f"Found valid url in clipboard: {url.url}")
if len(requirements) != 0:
logger.info(f"{url.url} has {len(requirements)} requirements")

for url in [url, *requirements]:
if url.url in runningDownloads:
logger.info(f"Url is already being downloaded: {url.url}")
continue
if url.url in downloadQueue:
logger.info(
f"Url is already in queue (#{downloadQueue.index(url.url)}): {url.url}"
)
continue

if len(runningDownloads) == CONFIG["maxActiveDownloads"]:
logger.info(
f"Added url to queue (#{len(downloadQueue)}): {url.url}"
)
downloadQueue.append(url.url)
else:
runningDownloads.append(url.url)
pool = Pool(1)
pool.apply_async(
processTarget,
args=[
url,
session.tsrdlsession,
CONFIG["downloadDirectory"],
],
callback=callback,
)
updateUrlFile()
except InvalidURL:
pass
requirements = TSRUrl.getRequiredItems(url)
logger.info(f"Found valid url in clipboard: {url.url}")
if len(requirements) != 0:
logger.info(f"{url.url} has {len(requirements)} requirements")
for url in [url, *requirements]:
if url.url in runningDownloads:
logger.info(f"Url is already being downloaded: {url.url}")
continue
if url.url in downloadQueue:
logger.info(
f"Url is already in queue (#{downloadQueue.index(url.itemId)}): {url.url}"
)
continue
if len(runningDownloads) == CONFIG["maxActiveDownloads"]:
logger.info(
f"Added url to queue (#{len(downloadQueue)}): {url.url}"
)
downloadQueue.append(url.itemId)
else:
runningDownloads.append(url.itemId)
pool = Pool(1)
pool.apply_async(
processTarget,
args=[
url,
session.tsrdlsession,
CONFIG["downloadDirectory"],
],
callback=callback,
)
updateUrlFile()

time.sleep(0.1)