Skip to content

Commit

Permalink
chore: clean up (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
onedr0p authored Aug 21, 2023
1 parent 48f4ea2 commit 8789e9e
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 61 deletions.
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
15 changes: 2 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
25 changes: 1 addition & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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
```
4 changes: 2 additions & 2 deletions qbittools/commands/add.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion qbittools/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion qbittools/commands/mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import collections
from datetime import datetime
import tldextract
from tqdm import tqdm
import qbittools
import qbittorrentapi
Expand Down
5 changes: 1 addition & 4 deletions qbittools/commands/orphaned.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
12 changes: 6 additions & 6 deletions qbittools/commands/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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))
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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)
1 change: 0 additions & 1 deletion qbittools/commands/unpause.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

import pathlib, hashlib, os
import qbittools

def __init__(args, logger):
Expand Down
2 changes: 1 addition & 1 deletion qbittools/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return len(linked) > 0
1 change: 1 addition & 0 deletions qbittools/qbittools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
15 changes: 7 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8789e9e

Please sign in to comment.