mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-03-09 06:14:17 +08:00
First push
This commit is contained in:
commit
42a01921f7
2 changed files with 117 additions and 0 deletions
20
config.yml
Normal file
20
config.yml
Normal file
|
@ -0,0 +1,20 @@
|
|||
qbt:
|
||||
host: 'localhost:8080'
|
||||
user: 'username'
|
||||
pass: 'password'
|
||||
cat:
|
||||
# <File path keyword>: <Category Name>
|
||||
anime: anime
|
||||
movies: movies
|
||||
tv: tv
|
||||
tags:
|
||||
# <Tracker URL Keyword>: <Tag Name>
|
||||
awesome-hd: AHD
|
||||
beyond-hd: Beyond-HD
|
||||
animebytes.tv: AnimeBytes
|
||||
avistaz: Avistaz
|
||||
landof.tv: BroadcasTheNet
|
||||
passthepopcorn: PassThePopcorn
|
||||
|
||||
|
||||
|
97
qbit_scripts.py
Normal file
97
qbit_scripts.py
Normal file
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from qbittorrentapi import Client
|
||||
import yaml
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser("qBittorrent scripts.",
|
||||
description='A mix of scripts combined for managing qBittorrent.')
|
||||
parser.add_argument('-c', '--config-file',
|
||||
dest='config',
|
||||
action='store',
|
||||
default='config.yml',
|
||||
help='This is used if you want to use different names for your config.yml. Example: tv.yml')
|
||||
parser.add_argument('--cat-update',
|
||||
dest='command',
|
||||
action='store_const',
|
||||
const='cat-update',
|
||||
help='Use this if you would like to update your categories.')
|
||||
parser.add_argument('--tag-update',
|
||||
dest='command',
|
||||
action='store_const',
|
||||
const='tag-update',
|
||||
help='Use this if you would like to update your tags.')
|
||||
args = parser.parse_args()
|
||||
|
||||
with open(args.config, "r") as cfg_file:
|
||||
cfg = yaml.load(cfg_file, Loader=yaml.FullLoader)
|
||||
|
||||
# Actual API call to connect to qbt.
|
||||
client = Client(host=cfg["qbt"]["host"], username=cfg["qbt"]["user"], password=cfg["qbt"]["pass"])
|
||||
torrent_list = client.torrents.info()
|
||||
|
||||
|
||||
def get_category(path):
|
||||
cat_path = cfg["cat"]
|
||||
for p, c in cat_path.items():
|
||||
if p in path:
|
||||
category = c
|
||||
return category
|
||||
else:
|
||||
category = ''
|
||||
return category
|
||||
|
||||
|
||||
# Main command that does the work.
|
||||
def update_category():
|
||||
num_cat = 0
|
||||
for torrent in torrent_list:
|
||||
if torrent.category == '':
|
||||
new_cat = get_category(torrent.save_path)
|
||||
print('Torrent Name: ' + torrent.name)
|
||||
print(' - New Category: ' + new_cat)
|
||||
torrent.set_category(category=new_cat)
|
||||
num_cat += 1
|
||||
if num_cat >= 1:
|
||||
print('Updated ', num_cat, ' new categories')
|
||||
else:
|
||||
print('No new torrents to categorize.')
|
||||
|
||||
|
||||
def get_tags(url):
|
||||
tag_path = cfg["tags"]
|
||||
for t, n in tag_path.items():
|
||||
if t in url:
|
||||
tag = n
|
||||
return tag
|
||||
else:
|
||||
tag = ''
|
||||
return tag
|
||||
|
||||
|
||||
def update_tags():
|
||||
num_tags = 0
|
||||
for torrent in torrent_list:
|
||||
if torrent.tags == '':
|
||||
for x in torrent.trackers:
|
||||
if x.url.startswith('http'):
|
||||
new_tag = get_tags(x.url)
|
||||
print('Torrent Name: ' + torrent.name)
|
||||
print(' - New Tag: ' + new_tag)
|
||||
torrent.add_tags(tags=new_tag)
|
||||
num_tags += 1
|
||||
if num_tags >= 1:
|
||||
print('Updated ', num_tags, ' new tags')
|
||||
else:
|
||||
print('No new torrents to tag.')
|
||||
|
||||
|
||||
def main():
|
||||
if args.command == 'cat-update':
|
||||
update_category()
|
||||
elif args.command == 'tag-update':
|
||||
update_tags()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in a new issue