#!/usr/bin/python3 # # qBittorrent-api: # https://qbittorrent-api.readthedocs.io/en/v2023.4.47/introduction.html # # # # Make sure to set the folling variables. # # # # # import re import sys import qbittorrentapi # qbittorrent webui login crendentials. qbitt_username = '' qbitt_password = '' # qbittorrent webui address. #url = 'http://192.168.1.59:8080' url = 'http://:' # The categories to use for matching torrents. Change as needed. category_1080_shows = "1080+ | Shows" category_1080_movies = "1080+ | Movies" # Connect to the qBittorrent API qb = qbittorrentapi.Client(host=url) # Log in qbittorrent API qb.auth_log_in(username=qbitt_username, password=qbitt_password) # Get information about all torrents in the download queue torrents = qb.torrents_info() # loop through the torrents for torrent in torrents: # Get the name of the completed torrent from the command line arguments inside qbittorrent torrent_name = sys.argv[1] # Name of the added torrent as defined by "%N" in qbittorrent settings. torrent_hash = sys.argv[2] # Hash of the added torrent as defined by "%I" in qbittorrent settings. # Define the regular expression pattern for 'SxxExx' or 'sxxexx' format. pattern = r"[Ss]\d{2}[Ee]\d{2}" # Check for 'SxxExx' or 'sxxexx' episode pattern and '1080p' or '2160p' # If so, assign 1080 show category. if re.search(pattern, torrent_name) and ("1080p" in torrent_name or "2160p" in torrent_name): qb.torrents_set_category(category=category_1080_shows, hashes=torrent_hash) qb.torrents_set_auto_management(hashes=torrent_hash, enable=True) # Then check for movies criteria. elif ("1080p" in torrent_name or "2160p" in torrent_name) and "YTS.MX" in torrent_name: qb.torrents_set_category(category=category_1080_movies, hashes=torrent_hash) qb.torrents_set_auto_management(hashes=torrent_hash, enable=True) # Disconnect from the qBittorrent API qb.auth_log_out()