From 8789e9ea84389f18e92600b9e6c313c8e4f9692a Mon Sep 17 00:00:00 2001 From: Devin Buhl Date: Mon, 21 Aug 2023 12:59:28 -0400 Subject: [PATCH] chore: clean up (#6) --- .editorconfig | 23 +++++++++++++++++++++++ Dockerfile | 15 ++------------- README.md | 25 +------------------------ qbittools/commands/add.py | 4 ++-- qbittools/commands/export.py | 2 +- qbittools/commands/mover.py | 1 - qbittools/commands/orphaned.py | 5 +---- qbittools/commands/tagging.py | 12 ++++++------ qbittools/commands/unpause.py | 1 - qbittools/commands/utils.py | 2 +- qbittools/qbittools.py | 1 + requirements.txt | 15 +++++++-------- 12 files changed, 45 insertions(+), 61 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6650f18 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,23 @@ +; https://editorconfig.org/ + +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[{Makefile,go.mod,go.sum,*.go,.gitmodules}] +indent_style = tab +indent_size = 4 + +[*.md] +indent_size = 4 +trim_trailing_whitespace = false + +[{Dockerfile,*.bash,*.sh,*.py}] +indent_style = space +indent_size = 4 diff --git a/Dockerfile b/Dockerfile index 9dc9389..1524093 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,29 +1,18 @@ -FROM python:3.11-slim-bullseye as base +FROM python:3.12-slim-bullseye as base FROM base as pip - WORKDIR /install - COPY requirements.txt /requirements.txt - RUN pip install --no-cache-dir --prefix=/install -r /requirements.txt - -RUN python3 -c "import compileall; \ - compileall.compile_path(maxlevels=10)" +RUN python3 -c "import compileall; compileall.compile_path(maxlevels=10)" FROM base as app - WORKDIR /app - COPY qbittools/ . - RUN python3 -m compileall qbittools.py commands/ FROM base as final - WORKDIR /app - COPY --from=pip /install /usr/local COPY --from=app /app . - ENTRYPOINT ["python3", "qbittools.py"] diff --git a/README.md b/README.md index 8694024..d44ee04 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ qbittools is a feature rich CLI for the management of torrents in qBittorrent. ## Table of contents +- [Upstream](#upstream) - [Description](#description) - [Table of contents](#table-of-contents) - [Requirements](#requirements) @@ -33,7 +34,6 @@ qbittools is a feature rich CLI for the management of torrents in qBittorrent. - [Mover](#mover) - [Automatic moving with Cron](#automatic-moving-with-cron) - [Orphaned](#orphaned) - - [FlexGet](#flexget) ## Requirements @@ -318,26 +318,3 @@ Find files no longer associated with any torrent, but still present in download ```bash $ qbittools orphaned ``` - -### FlexGet - -qbittools can be used together with FlexGet via `exec` plugin, configuration example: - -```yml -taskname: - rss: - url: https://site/feed.rss - all_entries: no - seen: - local: yes - accept_all: yes - download: - path: ~/torrents/rss/ - overwrite: yes - exec: - auto_escape: yes - fail_entries: yes - on_output: - for_accepted: - - /usr/local/bin/qbittools add "{{location}}" -c books --rename "{{title}}" --content-layout Subfolder -``` diff --git a/qbittools/commands/add.py b/qbittools/commands/add.py index 286b760..a68cc26 100755 --- a/qbittools/commands/add.py +++ b/qbittools/commands/add.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import pathlib, os +import pathlib import qbittools import commands.utils as utils from humanfriendly import format_size, parse_size @@ -29,7 +29,7 @@ def __init__(args, logger): if args.category and client.application.preferences.auto_tmm_enabled and args.tmm != False: category = client.torrent_categories.categories.get(args.category) - + if category and category.savePath != '': logger.info(f"Checking free space in {category.savePath}") free = utils.free_space(category.savePath) diff --git a/qbittools/commands/export.py b/qbittools/commands/export.py index d0d15a2..eea573f 100755 --- a/qbittools/commands/export.py +++ b/qbittools/commands/export.py @@ -12,7 +12,7 @@ def __init__(args, logger): torrents = list(map(lambda x: (x.hash, x.name, x.trackers), matches)) else: torrents = list(map(lambda x: (x.hash, x.name, x.trackers), client.torrents.info(category=args.category))) - + logger.info(f"Matched {len(torrents)} torrents") Path(args.output).expanduser().mkdir(parents=True, exist_ok=True) diff --git a/qbittools/commands/mover.py b/qbittools/commands/mover.py index 99e4382..07caa25 100644 --- a/qbittools/commands/mover.py +++ b/qbittools/commands/mover.py @@ -2,7 +2,6 @@ import collections from datetime import datetime -import tldextract from tqdm import tqdm import qbittools import qbittorrentapi diff --git a/qbittools/commands/orphaned.py b/qbittools/commands/orphaned.py index 26ea4ca..f8a1dd0 100644 --- a/qbittools/commands/orphaned.py +++ b/qbittools/commands/orphaned.py @@ -1,12 +1,9 @@ #!/usr/bin/env python3 -import collections from datetime import datetime -import tldextract from tqdm import tqdm import qbittools -import qbittorrentapi -import os, operator, sys +import os, operator import pathlib3x as pathlib import commands.utils as utils diff --git a/qbittools/commands/tagging.py b/qbittools/commands/tagging.py index 1af5458..c7ccb8f 100755 --- a/qbittools/commands/tagging.py +++ b/qbittools/commands/tagging.py @@ -43,9 +43,10 @@ def __init__(args, logger): 'problem with', 'specifically banned', 'trumped', + 'torrent existiert nicht', 'i\'m sorry dave, i can\'t do that' # weird stuff from racingforme ] - + maintenance_matches = [ 'tracker is down', 'maintenance' @@ -69,7 +70,6 @@ def __init__(args, logger): logger.info('Collecting tags info...') filtered_torrents = client.torrents.info() - all_torrents = client.torrents.info() if args.categories: filtered_torrents = list(filter(lambda x: x.category in args.categories, filtered_torrents)) @@ -84,7 +84,7 @@ def __init__(args, logger): client.torrents_remove_tags(tags=tags_to_delete, torrent_hashes=hashes) logger.info('Pruning old tags...') - + empty_tags = list(filter(lambda tag: len(list(filter(lambda t: tag in t.tags, client.torrents.info()))) == 0, tqdm(tags_to_delete))) client.torrents_delete_tags(tags=empty_tags) @@ -126,7 +126,7 @@ def __init__(args, logger): # trackers call is expensive for large amount of torrents working = len(list(filter(lambda s: s.status == 2, t.trackers))) > 0 real_trackers = list(filter(lambda s: not s.url in dht_matches, t.trackers)) - + if args.trackers and len(real_trackers) > 0: domain = tldextract.extract(sorted(real_trackers, key=lambda x: x.url)[0].url).registered_domain if len(domain) > 0: @@ -155,7 +155,7 @@ def __init__(args, logger): tag_sizes["Duplicates"] += match[0][2] content_paths.append((t.hash, t.content_path, t.size)) - + if args.not_linked and not utils.is_linked(t.content_path): tags_to_add.append("Not Linked") @@ -193,5 +193,5 @@ def add_arguments(subparser): parser.add_argument('--tracker-down', action='store_true', help='Tag torrents with temporarily down trackers. Significantly increases script execution time') parser.add_argument('--size', action='store_true', help='Add size of tagged torrents to created tags') parser.add_argument('--not-linked', action='store_true', help='Tag torrents with files without hardlinks or symlinks, use with filtering by category/tag. Significantly increases script execution time') - + qbittools.add_default_args(parser) diff --git a/qbittools/commands/unpause.py b/qbittools/commands/unpause.py index ec985f6..6ba0f78 100755 --- a/qbittools/commands/unpause.py +++ b/qbittools/commands/unpause.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 -import pathlib, hashlib, os import qbittools def __init__(args, logger): diff --git a/qbittools/commands/utils.py b/qbittools/commands/utils.py index ab54e04..e18d390 100644 --- a/qbittools/commands/utils.py +++ b/qbittools/commands/utils.py @@ -49,4 +49,4 @@ def is_linked(path): if os.path.isdir(path): linked = [os.path.join(path, x) for path, subdirs, files in os.walk(path) for x in files if os.lstat(os.path.join(path, x)).st_nlink > 1 or os.path.islink(os.path.join(path, x))] - return len(linked) > 0 \ No newline at end of file + return len(linked) > 0 diff --git a/qbittools/qbittools.py b/qbittools/qbittools.py index db60e56..5668689 100755 --- a/qbittools/qbittools.py +++ b/qbittools/qbittools.py @@ -96,6 +96,7 @@ def config_values(path): if not host is None: try: host = ipaddress.ip_address(host) + host = 'http://' + str(host) except ValueError as e: host = "127.0.0.1" diff --git a/requirements.txt b/requirements.txt index b574043..72dd143 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,7 @@ -qbittorrent-api -tldextract -tqdm -requests -packaging -pathlib3x -humanfriendly -dulwich +qbittorrent-api==2023.7.52 +tldextract==3.4.4 +tqdm==4.66.1 +requests==2.31.0 +packaging==23.1 +pathlib3x==2.0.3 +humanfriendly==10.0