Skip to content

Commit

Permalink
Merge pull request #16 from buroa/buroa/config
Browse files Browse the repository at this point in the history
feat: config file; general cleanup
  • Loading branch information
buroa authored Aug 27, 2023
2 parents 5b69830 + 48851b6 commit d2089a8
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 345 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN pip install --no-cache-dir --prefix=/install -r /requirements.txt \
FROM base as app
WORKDIR /app
COPY qbittools/ .
COPY config.yaml .
RUN python3 -m compileall qbittools.py commands/

FROM base as final
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ docker run -it --rm --network host qbittools reannounce -p 12345

## Configuration

qBittools doesn't have any configuration files currently. It parses host, port and username from the qBittorrent configuration file located by default at `~/.config/qBittorrent/qBittorrent.conf`, you can specify a different qBittorrent config with `-C` flag.

You also have to specify your password every time with `-P` flag unless you enable `Web UI -> Bypass authentication for clients on localhost` in qBittorrent's settings, because there is no way for qBittools to retrieve it in plaintext.
You have to specify your password every time with `-P` flag unless you enable `Web UI -> Bypass authentication for clients on localhost` in qBittorrent's settings, because there is no way for qBittools to retrieve it in plaintext.

You also can specify host, port and username manually without a configuration file with `-s`, `-p` and `-U` flags accordingly.

There is also a `config.yaml` file which can be overrideen to add your own indexers and their corresponding requirements.

## Usage

### Help
Expand All @@ -60,14 +60,14 @@ All commands have extensive help with all available options.
```bash
$ qbittools export -h
usage: qbittools.py reannounce [-h] [--pause-resume] [--process-seeding]
[-C ~/.config/qBittorrent/qBittorrent.conf] [-p 12345] [-s 127.0.0.1] [-U username]
[-c /app/config.yaml] [-p 12345] [-s 127.0.0.1] [-U username]
[-P password]

options:
-h, --help show this help message and exit
--pause-resume Will pause/resume torrents that are invalid.
--process-seeding Will also process seeding torrents for reannouncements.
-C ~/.config/qBittorrent/qBittorrent.conf, --config ~/.config/qBittorrent/qBittorrent.conf
-c /app/config.yaml, --config /app/config.yaml
-p 12345, --port 12345
port
-s 127.0.0.1, --server 127.0.0.1
Expand Down
219 changes: 219 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
---
trackers:
- name: aither
urls:
- aither.cc
required_seed_ratio: 0
required_seed_days: 5.5

- name: alpharatio
urls:
- alpharatio.cc
required_seed_ratio: 1.05
required_seed_days: 7.5

- name: animetorrents
urls:
- animetorrents.me
required_seed_ratio: 1.05
required_seed_days: 0

- name: animez
urls:
- animez.to
- animetorrents.me
required_seed_ratio: 1.05
required_seed_days: 1.5

- name: anthelion
urls:
- anthelion.me
required_seed_ratio: 1.05
required_seed_days: 0

- name: avistaz
urls:
- avistaz.to
required_seed_ratio: 1
required_seed_days: 10.5

- name: beyond-hd
urls:
- beyond-hd.me
required_seed_ratio: 0
required_seed_days: 30.5

- name: blutopia
urls:
- blutopia.cc
- blutopia.xyz
required_seed_ratio: 0
required_seed_days: 7.5

- name: broadcasthenet
urls:
- landof.tv
required_seed_ratio: 1.05
required_seed_days: 5.5

- name: cinemaz
urls:
- cinemaz.to
required_seed_ratio: 1.05
required_seed_days: 10.5

- name: divteam
urls:
- divteam.com
required_seed_ratio: 0
required_seed_days: 2.5

- name: exoticaz
urls:
- exoticaz.to
required_seed_ratio: 1.05
required_seed_days: 10.5

- name: filelist
urls:
- filelist.io
- flro.org
required_seed_ratio: 1.05
required_seed_days: 2.5

- name: hd-olimpo
urls:
- hd-olimpo.club
required_seed_ratio: 0
required_seed_days: 3.5

- name: hd-space
urls:
- hd-space.pw
required_seed_ratio: 1.05
required_seed_days: 10.5

- name: hd-torrents
urls:
- hdts-announce.ru
required_seed_ratio: 1.05
required_seed_days: 10.5

- name: iptorrents
urls:
- bgp.technology
- empirehost.me
- stackoverflow.tech
required_seed_ratio: 1.05
required_seed_days: 14.5

- name: karagarga
urls:
- karagarga.in
required_seed_ratio: 1.05
required_seed_days: 0

- name: kraytracker
urls:
- kraytracker.com
required_seed_ratio: 1.05
required_seed_days: 2.5

- name: morethantv
urls:
- morethantv.me
required_seed_ratio: 1.05
required_seed_days: 7.5

- name: myanonamouse
urls:
- myanonamouse.net
required_seed_ratio: 0
required_seed_days: 3.5

- name: myspleen
urls:
- myspleen.org
required_seed_ratio: 1.05
required_seed_days: 0

- name: orpheus
urls:
- home.opsfet.ch
required_seed_ratio: 1.05
required_seed_days: 0

- name: passthepopcorn
urls:
- passthepopcorn.me
required_seed_ratio: 0
required_seed_days: 0

- name: privatehd
urls:
- privatehd.to
required_seed_ratio: 1
required_seed_days: 10.5

- name: redbits
urls:
- redbits.xyz
required_seed_ratio: 0
required_seed_days: 4.5

- name: redacted
urls:
- flacsfor.me
required_seed_ratio: 1.05
required_seed_days: 0

- name: scenetime
urls:
- scenetime.com
required_seed_ratio: 0
required_seed_days: 3.5

- name: superbits
urls:
- sptracker.cc
- superbits.org
required_seed_ratio: 1.15
required_seed_days: 2.5

- name: torrentday
urls:
- jumbohostpro.eu
- td-peers.com
required_seed_ratio: 1.05
required_seed_days: 3.5

- name: torrentland
urls:
- torrentland.li
required_seed_ratio: 0
required_seed_days: 4.5

- name: torrentleech
urls:
- tleechreload.org
- torrentleech.org
required_seed_ratio: 1.05
required_seed_days: 10.5

- name: torrentseeds
urls:
- torrentseeds.org
required_seed_ratio: 1.05
required_seed_days: 5.5

- name: xbytesv2
urls:
- xbytesv2.li
required_seed_ratio: 1.05
required_seed_days: 3.5

- name: uhdbits
urls:
- uhdbits.org
required_seed_ratio: 1.05
required_seed_days: 7.5
1 change: 0 additions & 1 deletion qbittools/_version.py

This file was deleted.

4 changes: 1 addition & 3 deletions qbittools/commands/orphaned.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3

import os
import shutil
from fnmatch import fnmatch
Expand All @@ -11,7 +9,7 @@ def __init__(args, logger):

client = qbittools.qbit_client(args)

completed_dir = str(qbittools.config.save_path)
completed_dir = client.application.preferences.save_path
completed_dir_list = completed_dir.split(os.sep)
exclude_patterns = [i for s in args.exclude_pattern for i in s]

Expand Down
6 changes: 1 addition & 5 deletions qbittools/commands/prune.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#!/usr/bin/env python3

import commands.utils as utils

import qbittools

def __init__(args, logger):
Expand All @@ -21,7 +17,7 @@ def __init__(args, logger):

logger.info(f"Deleting torrents with tags [{' AND '.join(include_tags)}] but does not contain tags [{' OR '.join(exclude_tags)}]...")
for t in filtered_torrents:
logger.info(f"Removed torrent {t['name']} with category [{t.category}] and tags [{t.tags}] and ratio [{round(t['ratio'], 2)}] and seeding time [{utils.dhms(t['seeding_time'])}]")
logger.info(f"Removed torrent {t['name']} with category [{t.category}] and tags [{t.tags}] and ratio [{round(t['ratio'], 2)}] and seeding time [{qbittools.utils.dhms(t['seeding_time'])}]")
if not args.dry_run:
t.delete(delete_files=args.with_data)

Expand Down
5 changes: 1 addition & 4 deletions qbittools/commands/reannounce.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python3

import time

import qbittools

def __init__(args, logger):
Expand Down Expand Up @@ -68,7 +65,7 @@ def process_seeding():
if args.process_seeding:
process_seeding()
except Exception as e:
logger.exception(e)
logger.error(e)

time.sleep(timeout)

Expand Down
14 changes: 6 additions & 8 deletions qbittools/commands/tagging.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#!/usr/bin/env python3

import tldextract
import collections
from datetime import datetime
import tldextract
import commands.utils as utils

import qbittools

Expand Down Expand Up @@ -57,6 +54,7 @@

def __init__(args, logger):
client = qbittools.qbit_client(args)
trackers = qbittools.get_config(args, "trackers", [])

extractTLD = tldextract.TLDExtract(cache_dir=None)
today = datetime.today()
Expand All @@ -79,7 +77,7 @@ def __init__(args, logger):
# TODO: Optimize - this slows down the script a lot
filtered_trackers = list(filter(lambda s: not s.url in DHT_MATCHES, t.trackers))
domain = extractTLD(sorted(filtered_trackers, key=lambda x: x.url)[0].url).registered_domain
tracker = utils.filter_tracker_by_domain(domain)
tracker = qbittools.utils.filter_tracker_by_domain(domain, trackers)

if args.added_on:
added_on = datetime.fromtimestamp(t.added_on)
Expand Down Expand Up @@ -134,7 +132,7 @@ def __init__(args, logger):
if args.expired and tracker:
if tracker['required_seed_ratio'] != 0 and t.ratio >= tracker['required_seed_ratio']:
tags_to_add.append('expired')
elif tracker['required_seed_days'] != 0 and t.seeding_time >= utils.seconds(tracker['required_seed_days']):
elif tracker['required_seed_days'] != 0 and t.seeding_time >= qbittools.utils.seconds(tracker['required_seed_days']):
tags_to_add.append('expired')

if args.duplicates:
Expand All @@ -147,7 +145,7 @@ def __init__(args, logger):

content_paths.append((t.hash, t.content_path, t.size))

if args.not_linked and not utils.is_linked(t.content_path):
if args.not_linked and not qbittools.utils.is_linked(t.content_path):
tags_to_add.append('not-linked')

for tag in tags_to_add:
Expand Down Expand Up @@ -175,7 +173,7 @@ def __init__(args, logger):

for tag in tag_hashes:
if args.size:
size = utils.format_bytes(tag_sizes[tag])
size = qbittools.utils.format_bytes(tag_sizes[tag])
client.torrents_add_tags(tags=f"{tag} [{size}]", torrent_hashes=tag_hashes[tag])
else:
client.torrents_add_tags(tags=tag, torrent_hashes=tag_hashes[tag])
Expand Down
Loading

0 comments on commit d2089a8

Please sign in to comment.