Skip to content

Commit

Permalink
Merge pull request #204 from ManiMatter/dev
Browse files Browse the repository at this point in the history
Ignore download clients + Bug fixes
  • Loading branch information
ManiMatter authored Dec 6, 2024
2 parents 5d609fe + 568fd69 commit 295275d
Show file tree
Hide file tree
Showing 18 changed files with 398 additions and 365 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ jobs:
fetch-depth: '0'

- name: Bump version and push tag
if: ${{ github.ref_name == 'stable' }}
if: ${{ github.ref_name == 'latest' }}
id: setversion
uses: anothrNick/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
RELEASE_BRANCHES: stable
RELEASE_BRANCHES: latest

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Expand All @@ -96,7 +96,7 @@ jobs:
BRANCH_NAME="${{ github.ref_name }}"
if [[ "$BRANCH_NAME" == "dev" ]]; then
IMAGE_TAG="dev"
elif [[ "$BRANCH_NAME" == "stable" ]]; then
elif [[ "$BRANCH_NAME" == "latest" ]]; then
IMAGE_TAG=${{ steps.setversion.outputs.new_tag }}
else
IMAGE_TAG=$BRANCH_NAME
Expand All @@ -116,7 +116,7 @@ jobs:
run: |
BRANCH_NAME="${{ github.ref_name }}"
TAG_LATEST=""
if [[ "$BRANCH_NAME" == "stable" ]]; then
if [[ "$BRANCH_NAME" == "latest" ]]; then
TAG_LATEST="-t $IMAGE_NAME:latest"
fi
Expand Down
552 changes: 312 additions & 240 deletions README.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions config/config.conf-Example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ PERMITTED_ATTEMPTS = 3
NO_STALLED_REMOVAL_QBIT_TAG = Don't Kill
IGNORE_PRIVATE_TRACKERS = FALSE
FAILED_IMPORT_MESSAGE_PATTERNS = ["Not a Custom Format upgrade for existing", "Not an upgrade for existing"]
IGNORED_DOWNLOAD_CLIENTS = ["emulerr"]

[radarr]
RADARR_URL = http://radarr:7878
Expand Down
1 change: 1 addition & 0 deletions config/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
NO_STALLED_REMOVAL_QBIT_TAG = get_config_value('NO_STALLED_REMOVAL_QBIT_TAG', 'feature_settings', False, str, 'Don\'t Kill')
IGNORE_PRIVATE_TRACKERS = get_config_value('IGNORE_PRIVATE_TRACKERS', 'feature_settings', False, bool, True)
FAILED_IMPORT_MESSAGE_PATTERNS = get_config_value('FAILED_IMPORT_MESSAGE_PATTERNS','feature_settings', False, list, [])
IGNORED_DOWNLOAD_CLIENTS = get_config_value('IGNORED_DOWNLOAD_CLIENTS', 'feature_settings', False, list, [])

# Radarr
RADARR_URL = get_config_value('RADARR_URL', 'radarr', False, str)
Expand Down
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ async def main(settingsDict):
# Start Cleaning
while True:
logger.verbose("-" * 50)

# Refresh qBit Cookie
if settingsDict["QBITTORRENT_URL"]:
await qBitRefreshCookie(settingsDict)
if not settingsDict["QBIT_COOKIE"]:
logger.error("Cookie Refresh failed - exiting decluttarr")
exit()

# Cache protected (via Tag) and private torrents
protectedDownloadIDs, privateDowloadIDs = await getProtectedAndPrivateFromQbit(
settingsDict
Expand Down
2 changes: 1 addition & 1 deletion src/decluttarr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async def queueCleaner(
logger.verbose("Cleaning queue on %s:", NAME)
# Refresh queue:
try:
full_queue = await get_queue(BASE_URL, API_KEY, params={full_queue_param: True})
full_queue = await get_queue(BASE_URL, API_KEY, settingsDict, params={full_queue_param: True})
if full_queue:
logger.debug("queueCleaner/full_queue at start:")
logger.debug(full_queue)
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/remove_failed.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def remove_failed(
# Detects failed and triggers delete. Does not add to blocklist
try:
failType = "failed"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_failed/queue IN: %s", formattedQueueInfo(queue))

if not queue:
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/remove_failed_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async def remove_failed_imports(
# Detects downloads stuck downloading meta data and triggers repeat check and subsequent delete. Adds to blocklist
try:
failType = "failed import"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_failed_imports/queue IN: %s", formattedQueueInfo(queue))
if not queue:
return 0
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/remove_metadata_missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def remove_metadata_missing(
# Detects downloads stuck downloading meta data and triggers repeat check and subsequent delete. Adds to blocklist
try:
failType = "missing metadata"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_metadata_missing/queue IN: %s", formattedQueueInfo(queue))
if not queue:
return 0
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/remove_missing_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def remove_missing_files(
# Detects downloads broken because of missing files. Does not add to blocklist
try:
failType = "missing files"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_missing_files/queue IN: %s", formattedQueueInfo(queue))
if not queue:
return 0
Expand Down
10 changes: 7 additions & 3 deletions src/jobs/remove_orphans.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ async def remove_orphans(
# Removes downloads belonging to movies/tv shows that have been deleted in the meantime. Does not add to blocklist
try:
failType = "orphan"
full_queue = await get_queue(BASE_URL, API_KEY, params={full_queue_param: True})
queue = await get_queue(BASE_URL, API_KEY)
full_queue = await get_queue(
BASE_URL, API_KEY, settingsDict, params={full_queue_param: True}
)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_orphans/full queue IN: %s", formattedQueueInfo(full_queue))
if not full_queue:
return 0 # By now the queue may be empty
Expand Down Expand Up @@ -63,7 +65,9 @@ async def remove_orphans(
logger.debug(
"remove_orphans/full queue OUT: %s",
formattedQueueInfo(
await get_queue(BASE_URL, API_KEY, params={full_queue_param: True})
await get_queue(
BASE_URL, API_KEY, settingsDict, params={full_queue_param: True}
)
),
)
return len(affectedItems)
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/remove_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def remove_slow(
# Detects slow downloads and triggers delete. Adds to blocklist
try:
failType = "slow"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_slow/queue IN: %s", formattedQueueInfo(queue))
if not queue:
return 0
Expand All @@ -56,7 +56,7 @@ async def remove_slow(
continue
if queueItem["status"] == "downloading":
if (
queueItem["sizeleft"] == 0
queueItem["size"] > 0 and queueItem["sizeleft"] == 0
): # Skip items that are finished downloading but are still marked as downloading. May be the case when files are moving
logger.info(
">>> Detected %s download that has completed downloading - skipping check (torrent files likely in process of being moved): %s",
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/remove_stalled.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def remove_stalled(
# Detects stalled and triggers repeat check and subsequent delete. Adds to blocklist
try:
failType = "stalled"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_stalled/queue IN: %s", formattedQueueInfo(queue))
if not queue:
return 0
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/remove_unmonitored.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async def remove_unmonitored(
# Removes downloads belonging to movies/tv shows that are not monitored. Does not add to blocklist
try:
failType = "unmonitored"
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
logger.debug("remove_unmonitored/queue IN: %s", formattedQueueInfo(queue))
if not queue:
return 0
Expand Down
2 changes: 1 addition & 1 deletion src/jobs/run_periodic_rescans.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async def run_periodic_rescans(
if not arr_type in settingsDict["RUN_PERIODIC_RESCANS"]:
return
try:
queue = await get_queue(BASE_URL, API_KEY)
queue = await get_queue(BASE_URL, API_KEY, settingsDict)
check_on_endpoint = []
RESCAN_SETTINGS = settingsDict["RUN_PERIODIC_RESCANS"][arr_type]
if RESCAN_SETTINGS["MISSING"]:
Expand Down
18 changes: 6 additions & 12 deletions src/utils/loadScripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from dateutil.relativedelta import relativedelta as rd
import requests
from src.utils.rest import rest_get, rest_post #
from src.utils.shared import qBitRefreshCookie
import asyncio
from packaging import version

Expand All @@ -28,6 +29,7 @@ async def getArrInstanceName(settingsDict, arrApp):
settingsDict[arrApp + '_NAME'] = arrApp.title()
return settingsDict


async def getProtectedAndPrivateFromQbit(settingsDict):
# Returns two lists containing the hashes of Qbit that are either protected by tag, or are private trackers (if IGNORE_PRIVATE_TRACKERS is true)
protectedDownloadIDs = []
Expand Down Expand Up @@ -101,7 +103,8 @@ def showSettings(settingsDict):
if settingsDict['QBITTORRENT_URL']:
logger.info('Downloads with this tag will be skipped: \"%s\"', settingsDict['NO_STALLED_REMOVAL_QBIT_TAG'])
logger.info('Private Trackers will be skipped: %s', settingsDict['IGNORE_PRIVATE_TRACKERS'])

if settingsDict['IGNORED_DOWNLOAD_CLIENTS']:
logger.info('Download clients skipped: %s',", ".join(settingsDict['IGNORED_DOWNLOAD_CLIENTS']))
logger.info('')
logger.info('*** Configured Instances ***')

Expand Down Expand Up @@ -187,18 +190,9 @@ async def instanceChecks(settingsDict):
# Check Bittorrent
if settingsDict['QBITTORRENT_URL']:
# Checking if qbit can be reached, and checking if version is OK
try:
response = await asyncio.get_event_loop().run_in_executor(None, lambda: requests.post(settingsDict['QBITTORRENT_URL']+'/auth/login', data={'username': settingsDict['QBITTORRENT_USERNAME'], 'password': settingsDict['QBITTORRENT_PASSWORD']}, headers={'content-type': 'application/x-www-form-urlencoded'}, verify=settingsDict['SSL_VERIFICATION']))
if response.text == 'Fails.':
raise ConnectionError('Login failed.')
response.raise_for_status()
settingsDict['QBIT_COOKIE'] = {'SID': response.cookies['SID']}
except Exception as error:
await qBitRefreshCookie(settingsDict)
if not settingsDict['QBIT_COOKIE']:
error_occured = True
logger.error('!! %s Error: !!', 'qBittorrent')
logger.error('> %s', error)
logger.error('> Details:')
logger.error(response.text)

if not error_occured:
qbit_version = await rest_get(settingsDict['QBITTORRENT_URL']+'/app/version',cookies=settingsDict['QBIT_COOKIE'])
Expand Down
89 changes: 0 additions & 89 deletions src/utils/main.py

This file was deleted.

Loading

0 comments on commit 295275d

Please sign in to comment.