Skip to content

Commit

Permalink
rework 2; use .get to resolve testing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dark3clipse committed Jan 18, 2025
1 parent 2222592 commit 53093b2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ Steers which type of cleaning is applied to the downloads queue
- Is Mandatory: No (Defaults to False)

**SET_OBSOLETE_QBIT_TAG**
- Set a tag on torrents in qBittorrent that can be removed, but are kept because they are private torrents.
- If this feature is turned on, private torrents in qBittorrent are not removed once the conditions for removal are met; instead, they are tagged with the obsolete-tag
- Note: Has no effect when `IGNORE_PRIVATE_TRACKERS==False`.
- The tag can be used by third-party tools to remove these torrents after required seeding time has passed.
- The tag can be used by third-party tools (such as [qbit_manage](https://github.com/StuffAnThings/qbit_manage)) to remove these torrents after required seeding time has passed.
- Tag is automatically created in qBittorrent (required qBittorrent is reachable on `QBITTORRENT_URL`)
- Type: Boolean
- Permissible Values: True, False
Expand Down Expand Up @@ -331,7 +331,7 @@ If it you face issues, please first check the closed issues before opening a new

**OBSOLETE_QBIT_TAG**
- Downloads in qBittorrent will receive this tag when: (1) `SET_OBSOLETE_QBIT_TAG==True`, (2) `IGNORE_PRIVATE_TRACKERS==True`, (3) torrent is private, (4) torrent is due for removal.
- Note: the tag can be used by third-party tools to remove these torrents after required seeding time has passed.
- Note: the tag can be used by third-party tools (such as [qbit_manage](https://github.com/StuffAnThings/qbit_manage)) to remove these torrents after required seeding time has passed.
- Tag is automatically created in qBittorrent (required qBittorrent is reachable on `QBITTORRENT_URL`)
- Type: String
- Is Mandatory: No (Defaults to `Obsolete`)
Expand Down
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ async def main(settingsDict):
await createQbitProtectionTag(settingsDict)

# Create qBit obsolete tag if not existing
await createQbitObsoleteTag(settingsDict)
if settingsDict['SET_OBSOLETE_QBIT_TAG']
await createQbitObsoleteTag(settingsDict)

# Show Logger Level
showLoggerLevel(settingsDict)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/loadScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def showSettings(settingsDict):
logger.info('%s | Removing slow downloads (%s)', str(settingsDict['REMOVE_SLOW']), 'REMOVE_SLOW')
logger.info('%s | Removing stalled downloads (%s)', str(settingsDict['REMOVE_STALLED']), 'REMOVE_STALLED')
logger.info('%s | Removing downloads belonging to unmonitored items (%s)', str(settingsDict['REMOVE_UNMONITORED']), 'REMOVE_UNMONITORED')
logger.info('%s | Setting obsolete tag on private torrents that are due for removal (%s)', str(settingsDict['SET_OBSOLETE_QBIT_TAG']), 'SET_OBSOLETE_QBIT_TAG')
logger.info("%s | Keeping private torrents in qBit due for removal and tagging instead (tag: '%s')", str(settingsDict['SET_OBSOLETE_QBIT_TAG']), 'SET_OBSOLETE_QBIT_TAG')
for arr_type, RESCAN_SETTINGS in settingsDict['RUN_PERIODIC_RESCANS'].items():
logger.info('%s/%s (%s) | Search missing/cutoff-unmet items. Max queries/list: %s. Min. days to re-search: %s (%s)', RESCAN_SETTINGS['MISSING'], RESCAN_SETTINGS['CUTOFF_UNMET'], arr_type, RESCAN_SETTINGS['MAX_CONCURRENT_SCANS'], RESCAN_SETTINGS['MIN_DAYS_BEFORE_RESCAN'], 'RUN_PERIODIC_RESCANS')
logger.info('')
Expand All @@ -103,7 +103,7 @@ def showSettings(settingsDict):
logger.info('Permitted number of times before stalled/missing metadata/slow downloads are removed: %s', str(settingsDict['PERMITTED_ATTEMPTS']))
if settingsDict['QBITTORRENT_URL']:
logger.info('Downloads with this tag will be skipped: \"%s\"', settingsDict['NO_STALLED_REMOVAL_QBIT_TAG'])
if settingsDict['SET_OBSOLETE_QBIT_TAG'] and settingsDict['OBSOLETE_QBIT_TAG']:
if settingsDict['SET_OBSOLETE_QBIT_TAG']:
logger.info('Obsolete private torrents will be given this tag: \"%s\"', settingsDict['OBSOLETE_QBIT_TAG'])
logger.info('Private Trackers will be skipped: %s', settingsDict['IGNORE_PRIVATE_TRACKERS'])
if settingsDict['IGNORED_DOWNLOAD_CLIENTS']:
Expand Down
9 changes: 5 additions & 4 deletions src/utils/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,11 @@ async def remove_download(
if removeFromClient:
logger.info(">>> Removing %s download: %s", failType, affectedItem["title"])
else:
if settingsDict['SET_OBSOLETE_QBIT_TAG'] and settingsDict['OBSOLETE_QBIT_TAG']:
if settingsDict.get('SET_OBSOLETE_QBIT_TAG'):
logger.info(
">>> Removing %s download (without removing from torrent client but with setting obsolete tag): %s",
">>> Removing %s download (keeping it in torrent client and adding tag '%s'): %s",
failType,
settingsDict['OBSOLETE_QBIT_TAG'],
affectedItem["title"],
)
else:
Expand All @@ -333,7 +334,7 @@ async def remove_download(
API_KEY,
{"removeFromClient": removeFromClient, "blocklist": addToBlocklist},
)
if not removeFromClient and settingsDict['QBITTORRENT_URL'] and settingsDict['SET_OBSOLETE_QBIT_TAG'] and settingsDict['OBSOLETE_QBIT_TAG'] and affectedItem["downloadId"]:
if not removeFromClient and settingsDict['QBITTORRENT_URL'] and settingsDict.get('SET_OBSOLETE_QBIT_TAG') and affectedItem["downloadId"]:
await rest_post(url=settingsDict['QBITTORRENT_URL']+'/torrents/createTags', data={'hashes': affectedItem["downloadId"], 'tags': settingsDict['OBSOLETE_QBIT_TAG']}, headers={'content-type': 'application/x-www-form-urlencoded'}, cookies=settingsDict['QBIT_COOKIE'])

deleted_downloads.dict.append(affectedItem["downloadId"])
Expand Down Expand Up @@ -423,4 +424,4 @@ async def qBitRefreshCookie(settingsDict):
logger.error('> %s', error)
logger.error('> Details:')
logger.error(response.text)
settingsDict['QBIT_COOKIE'] = {}
settingsDict['QBIT_COOKIE'] = {}
2 changes: 1 addition & 1 deletion tests/utils/remove_download/test_remove_download_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_obsolete_removal_with_removal_messages(monkeypatch, caplog):
settingsDict = {"TEST_RUN": True, "SET_OBSOLETE_QBIT_TAG": True}
removeFromClient = False
expected_removal_messages = {
">>> Removing failed import download (without removing from torrent client but with setting obsolete tag): Sonarr Title 1",
">>> Removing failed import download (keeping it in torrent client and adding tag 'Obsolete'): Sonarr Title 1",
">>>>> Tracked Download State: importBlocked",
">>>>> Status Messages (matching specified patterns):",
">>>>> - Episode XYZ was not found in the grabbed release: Sonarr Title 2.mkv",
Expand Down

0 comments on commit 53093b2

Please sign in to comment.