diff --git a/config.yml b/config.yml index 014c36d..54f8c23 100644 --- a/config.yml +++ b/config.yml @@ -14,7 +14,4 @@ tags: animebytes.tv: AnimeBytes avistaz: Avistaz landof.tv: BroadcasTheNet - passthepopcorn: PassThePopcorn - - - + passthepopcorn: PassThePopcorn \ No newline at end of file diff --git a/qbit_manage.py b/qbit_manage.py index d83ea1f..5dccbbc 100644 --- a/qbit_manage.py +++ b/qbit_manage.py @@ -8,12 +8,15 @@ parser = argparse.ArgumentParser("qBittorrent Manager.", 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('--manage', dest='command', action='store_const', const='manage', - help='Use this if you would like to update your tags AND categories.') +parser.add_argument('-m', '--manage', dest='command', action='store_const', const='manage', + help='Use this if you would like to update your tags AND categories and remove unregistered ' + 'torrents.') 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.') +parser.add_argument('--rem-unregistered', dest='command', action='store_const', const='rem-unregistered', + help='Use this if you would like to remove unregistered torrents.') args = parser.parse_args() with open(args.config, "r") as cfg_file: @@ -21,7 +24,7 @@ with open(args.config, "r") as cfg_file: # 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() +# torrent_list = client.torrents.info() def get_category(path): @@ -36,6 +39,7 @@ def get_category(path): def update_category(): + torrent_list = client.torrents.info() num_cat = 0 for torrent in torrent_list: if torrent.category == '': @@ -62,6 +66,7 @@ def get_tags(url): def update_tags(): + torrent_list = client.torrents.info() num_tags = 0 for torrent in torrent_list: if torrent.tags == '': @@ -73,19 +78,42 @@ def update_tags(): torrent.add_tags(tags=new_tag) num_tags += 1 if num_tags >= 1: - print('Updated ', num_tags, ' new tags') + print('Updated ', num_tags, ' new tags.') else: print('No new torrents to tag.') +def rem_unregistered(): + torrent_list = client.torrents.info() + rem_unr = 0 + for torrent in torrent_list: + for status in torrent.trackers: + if 'Unregistered torrent' in status.msg: + print(torrent.name, '->', status.msg) + print(' - Deleted') + torrent.delete(hash=torrent.hash, delete_files=True) + rem_unr += 1 + if rem_unr >= 1: + print('Deleted ', rem_unr, 'torrents.') + else: + print('No unregistered torrents found.') + + def main(): if args.command == 'manage': update_category() update_tags() + rem_unregistered() elif args.command == 'tag-update': update_tags() elif args.command == 'cat-update': update_category() + elif args.command == 'rem-unregistered': + rem_unregistered() + else: + print("The script requires an argument. See below:") + print("") + parser.print_help() if __name__ == "__main__":