Skip to content

Commit

Permalink
Merge branch 'develop' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
bobokun authored Sep 29, 2023
2 parents 1a959e9 + 256977a commit 4243e74
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
body: '{ "application": "qbitmanage", "branch": "nightly" }'

- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
Expand All @@ -38,11 +38,11 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
body: '{ "application": "qbitmanage", "branch": "release" }'

- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
Expand All @@ -34,11 +34,11 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fetch-depth: 0

- name: Login to Docker Hub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
Expand All @@ -30,15 +30,15 @@ jobs:

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Get the version
id: get_version
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
uses: docker/build-push-action@v5
with:
context: ./
file: ./Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.0.4
4.0.5-develop6
4 changes: 4 additions & 0 deletions config/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ share_limits:
# If the torrent has not yet reached this minimum seeding time, it will change the share limits back to no limits and resume the torrent to continue seeding.
# Will default to 0 if not specified for the group.
min_seeding_time: 43200
# <OPTIONAL> last_active <int>: Will prevent torrent deletion by cleanup variable if torrent has been active within the last x minutes.
# If the torrent has been active within the last x minutes, it will change the share limits back to no limits and resume the torrent to continue seeding.
# Will default to 0 if not specified for the group.
last_active: 43200
# <OPTIONAL> Limit Upload Speed <int>: Will limit the upload speed KiB/s (KiloBytes/second) (`-1` : No Limit)
limit_upload_speed: 0
# <OPTIONAL> cleanup <bool>: WARNING!! Setting this as true Will remove and delete contents of any torrents that satisfies the share limits
Expand Down
12 changes: 5 additions & 7 deletions modules/bhd.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ def search(self, json, path="torrents/"):
logger.trace(response)
response_json = response.json()
except JSONDecodeError as err:
if response.status_code >= 400:
raise Failed(err) from err
elif "Expecting value" in err:
logger.debug(err)
logger.debug(err)
return {}
if response.status_code >= 400:
logger.debug(f"Response: {response_json}")
raise Failed(f"({response.status_code} [{response.reason}]) {response_json}")
if not response_json["success"]:
raise Failed(f"BHD Error: {response_json['status_message']}")
return response.json()
if not response_json.get("success"):
raise Failed(f"BHD Error: {response_json.get('status_message','Issue receiving response from BHD API.')}")
return response_json
13 changes: 12 additions & 1 deletion modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,17 @@ def _sort_share_limits(share_limits):
do_print=False,
save=False,
)
self.share_limits[group]["last_active"] = self.util.check_for_attribute(
self.data,
"last_active",
parent="share_limits",
subparent=group,
var_type="int",
min_int=0,
default=0,
do_print=False,
save=False,
)
self.share_limits[group]["resume_torrent_after_change"] = self.util.check_for_attribute(
self.data,
"resume_torrent_after_change",
Expand Down Expand Up @@ -656,7 +667,7 @@ def cleanup_dirs(self, location):
ex = logger.print_line(
f"{location} Warning - FileNotFound: No such file or directory: {file} ", "WARNING"
)
self.config.notify(ex, "Cleanup Dirs", False)
self.notify(ex, "Cleanup Dirs", False)
continue
now = time.time() # in seconds
days = (now - last_modified) / (60 * 60 * 24)
Expand Down
4 changes: 4 additions & 0 deletions modules/core/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, qbit_manager):
self.stats = 0
self.torrents_updated = [] # List of torrents updated
self.notify_attr = [] # List of single torrent attributes to send to notifiarr
self.uncategorized_mapping = "Uncategorized"

self.category()
self.config.webhooks_factory.notify(self.torrents_updated, self.notify_attr, group_by="category")
Expand All @@ -23,6 +24,9 @@ def category(self):
torrent_list = self.qbt.get_torrents({"category": "", "status_filter": "completed"})
for torrent in torrent_list:
new_cat = self.qbt.get_category(torrent.save_path)
if new_cat == self.uncategorized_mapping:
logger.print_line(f"{torrent.name} remains uncategorized.", self.config.loglevel)
continue
self.update_cat(torrent, new_cat, False)

# Change categories
Expand Down
3 changes: 1 addition & 2 deletions modules/core/remove_unregistered.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def check_for_unregistered_torrents_using_bhd_api(self, tracker, msg_up, torrent
):
json = {"info_hash": torrent_hash}
response = self.config.beyond_hd.search(json)
if response["total_results"] == 0:
if response.get("total_results") == 0:
return True
return False

Expand Down Expand Up @@ -122,7 +122,6 @@ def process_torrent_issues(self):
# Tag any error torrents
if self.cfg_tag_error and self.tag_error not in check_tags:
self.tag_tracker_error(msg, tracker, torrent)

except NotFound404Error:
continue
except Exception as ex:
Expand Down
47 changes: 44 additions & 3 deletions modules/core/share_limits.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from datetime import timedelta
from time import time

from modules import util
from modules.util import is_tag_in_torrent
Expand All @@ -9,6 +10,7 @@

MIN_SEEDING_TIME_TAG = "MinSeedTimeNotReached"
MIN_NUM_SEEDS_TAG = "MinSeedsNotMet"
LAST_ACTIVE_TAG = "LastActiveLimitNotReached"


class ShareLimits:
Expand Down Expand Up @@ -57,6 +59,7 @@ def update_share_limits(self):
"torrent_min_seeding_time": group_config["min_seeding_time"],
"torrent_min_num_seeds": group_config["min_num_seeds"],
"torrent_limit_upload_speed": group_config["limit_upload_speed"],
"torrent_last_active": group_config["last_active"],
}
if len(self.torrents_updated) > 0:
self.config.send_notifications(attr)
Expand Down Expand Up @@ -209,8 +212,10 @@ def update_share_limits_for_group(self, group_name, group_config, torrents):
if (
check_max_ratio or check_max_seeding_time or check_limit_upload_speed or share_limits_not_yet_tagged
) and hash_not_prev_checked:
if not is_tag_in_torrent(MIN_SEEDING_TIME_TAG, torrent.tags) and not is_tag_in_torrent(
MIN_NUM_SEEDS_TAG, torrent.tags
if (
not is_tag_in_torrent(MIN_SEEDING_TIME_TAG, torrent.tags)
and not is_tag_in_torrent(MIN_NUM_SEEDS_TAG, torrent.tags)
and not is_tag_in_torrent(LAST_ACTIVE_TAG, torrent.tags)
):
logger.print_line(logger.insert_space(f"Torrent Name: {t_name}", 3), self.config.loglevel)
logger.print_line(logger.insert_space(f'Tracker: {tracker["url"]}', 8), self.config.loglevel)
Expand All @@ -226,6 +231,7 @@ def update_share_limits_for_group(self, group_name, group_config, torrents):
max_seeding_time=group_config["max_seeding_time"],
min_seeding_time=group_config["min_seeding_time"],
min_num_seeds=group_config["min_num_seeds"],
last_active=group_config["last_active"],
resume_torrent=group_config["resume_torrent_after_change"],
tracker=tracker["url"],
)
Expand Down Expand Up @@ -371,11 +377,13 @@ def set_tags_and_limits(self, torrent, max_ratio, max_seeding_time, limit_upload
return []
if is_tag_in_torrent(MIN_NUM_SEEDS_TAG, torrent.tags):
return []
if is_tag_in_torrent(LAST_ACTIVE_TAG, torrent.tags):
return []
torrent.set_share_limits(max_ratio, max_seeding_time)
return body

def has_reached_seed_limit(
self, torrent, max_ratio, max_seeding_time, min_seeding_time, min_num_seeds, resume_torrent, tracker
self, torrent, max_ratio, max_seeding_time, min_seeding_time, min_num_seeds, last_active, resume_torrent, tracker
):
"""Check if torrent has reached seed limit"""
body = ""
Expand Down Expand Up @@ -440,6 +448,36 @@ def _is_less_than_min_num_seeds():
torrent.resume()
return True

def _has_reached_last_active_time_limit():
print_log = []
now = int(time())
inactive_time_minutes = round((now - torrent.last_activity) / 60)
if inactive_time_minutes >= last_active * 60:
if is_tag_in_torrent(LAST_ACTIVE_TAG, torrent.tags):
if not self.config.dry_run:
torrent.remove_tags(tags=LAST_ACTIVE_TAG)
return True
else:
if not is_tag_in_torrent(LAST_ACTIVE_TAG, torrent.tags):
print_log += logger.print_line(logger.insert_space(f"Torrent Name: {torrent.name}", 3), self.config.loglevel)
print_log += logger.print_line(logger.insert_space(f"Tracker: {tracker}", 8), self.config.loglevel)
print_log += logger.print_line(
logger.insert_space(
f"Min inactive time not met: {timedelta(seconds=inactive_time_minutes)} <="
f" {timedelta(minutes=last_active)}. Removing Share Limits so qBittorrent can continue"
" seeding.",
8,
),
self.config.loglevel,
)
print_log += logger.print_line(logger.insert_space(f"Adding Tag: {LAST_ACTIVE_TAG}", 8), self.config.loglevel)
if not self.config.dry_run:
torrent.add_tags(LAST_ACTIVE_TAG)
torrent.set_share_limits(-1, -1)
if resume_torrent:
torrent.resume()
return False

def _has_reached_seeding_time_limit():
nonlocal body
seeding_time_limit = None
Expand All @@ -464,6 +502,9 @@ def _has_reached_seeding_time_limit():
if min_num_seeds is not None:
if _is_less_than_min_num_seeds():
return body
if last_active is not None:
if not _has_reached_last_active_time_limit():
return body
if max_ratio is not None:
if max_ratio >= 0:
if torrent.ratio >= max_ratio and _has_reached_min_seeding_time_limit():
Expand Down
2 changes: 2 additions & 0 deletions modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class TorrentMessages:
"EXPECTED VALUE (LIST, DICT, INT OR STRING) IN BENCODED STRING",
"COULD NOT PARSE BENCODED DATA",
"STREAM TRUNCATED",
"GATEWAY TIMEOUT", # BHD Gateway Timeout
"ANNOUNCE IS CURRENTLY UNAVAILABLE", # BHD Announce unavailable
]

EXCEPTIONS_MSGS = [
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bencodepy==0.9.5
GitPython==3.1.35
GitPython==3.1.37
qbittorrent-api==2023.9.53
requests==2.31.0
retrying==1.3.4
ruamel.yaml==0.17.32
ruamel.yaml==0.17.33
schedule==1.2.0

0 comments on commit 4243e74

Please sign in to comment.