[+] More CLI control

This commit is contained in:
2026-03-10 22:08:02 -04:00
parent bdf9b1311e
commit 226d9d0508
2 changed files with 50 additions and 45 deletions
+4 -2
View File
@@ -30,7 +30,7 @@ def get_tt_ids_in_jellyfin(jellyfin_dir):
return found_ids return found_ids
def detect_anomalies(expected_tt_ids=None): def detect_anomalies(expected_tt_ids=None, check_missing_files=False):
print("Gathering basic info...") print("Gathering basic info...")
jellyfin_tt_ids = get_tt_ids_in_jellyfin(DEFAULT_JELLYFIN_DIR) jellyfin_tt_ids = get_tt_ids_in_jellyfin(DEFAULT_JELLYFIN_DIR)
@@ -144,6 +144,7 @@ def detect_anomalies(expected_tt_ids=None):
else: else:
print("All downloaded torrents have at least one file linked in Jellyfin.") print("All downloaded torrents have at least one file linked in Jellyfin.")
if check_missing_files:
print(f"\n=== Anomaly 7: Torrents with missing files on disk ===") print(f"\n=== Anomaly 7: Torrents with missing files on disk ===")
torrents_with_missing_files = [] torrents_with_missing_files = []
for t in torrents: for t in torrents:
@@ -183,6 +184,7 @@ def detect_anomalies(expected_tt_ids=None):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Find anomalies between torrents, local downloads, and Jellyfin folders.") parser = argparse.ArgumentParser(description="Find anomalies between torrents, local downloads, and Jellyfin folders.")
parser.add_argument("tt_ids", nargs="*", help="Optional space-separated list of IMDb IDs (e.g., tt1234567 tt7654321) to verify their presence in Jellyfin.") parser.add_argument("tt_ids", nargs="*", help="Optional space-separated list of IMDb IDs (e.g., tt1234567 tt7654321) to verify their presence in Jellyfin.")
parser.add_argument("--check-missing-files", action="store_true", help="Enable the slow check for missing files on disk for all torrents.")
args = parser.parse_args() args = parser.parse_args()
detect_anomalies(expected_tt_ids=args.tt_ids) detect_anomalies(expected_tt_ids=args.tt_ids, check_missing_files=args.check_missing_files)
+9 -6
View File
@@ -251,7 +251,7 @@ def process_local_file(fs_path: Path, title_dir: str, imdb_id: str, jellyfin_bas
apply_rename_mapping(mapping, base_src_dir=src_dir_for_mapping, base_dst_dir=jellyfin_base) apply_rename_mapping(mapping, base_src_dir=src_dir_for_mapping, base_dst_dir=jellyfin_base)
print(f"Finished processing local file: {fs_path.name}") print(f"Finished processing local file: {fs_path.name}")
def process_imdb_workflow(imdb_id: str, dl_dir: str = DEFAULT_DL_DIR, jellyfin_base_dir: str = DEFAULT_JELLYFIN_DIR, imdb_source: str = "mteam"): def process_imdb_workflow(imdb_id: str, dl_dir: str = DEFAULT_DL_DIR, jellyfin_base_dir: str = DEFAULT_JELLYFIN_DIR, imdb_source: str = "imdbapi", ignore_existing: bool = False):
""" """
Workflow to automatically find, download, and map torrents for an IMDb ID into a Jellyfin library. Workflow to automatically find, download, and map torrents for an IMDb ID into a Jellyfin library.
""" """
@@ -277,12 +277,13 @@ def process_imdb_workflow(imdb_id: str, dl_dir: str = DEFAULT_DL_DIR, jellyfin_b
new_name = sanitize_filename(f"{year} {title} [{imdb_id}]") new_name = sanitize_filename(f"{year} {title} [{imdb_id}]")
print(f"\n=== [0.2] Checking if torrent already exists in qBittorrent ===")
qb = get_qb_client() qb = get_qb_client()
existing_t_hashes = check_qbittorrent(qb, imdb_id)
hashes_to_process = [] hashes_to_process = []
if not ignore_existing:
print(f"\n=== [0.2] Checking if torrent already exists in qBittorrent ===")
existing_t_hashes = check_qbittorrent(qb, imdb_id)
if existing_t_hashes: if existing_t_hashes:
print(f"Found {len(existing_t_hashes)} existing torrent(s), skipping local check, search, and download.") print(f"Found {len(existing_t_hashes)} existing torrent(s), skipping local check, search, and download.")
for existing_t_hash in existing_t_hashes: for existing_t_hash in existing_t_hashes:
@@ -301,6 +302,7 @@ def process_imdb_workflow(imdb_id: str, dl_dir: str = DEFAULT_DL_DIR, jellyfin_b
process_local_file(fs_match_dir, title_dir, imdb_id, jellyfin_base_dir) process_local_file(fs_match_dir, title_dir, imdb_id, jellyfin_base_dir)
return return
if not hashes_to_process:
hashes_to_process = search_and_download_mteam(qb, imdb_id, new_name, dl_dir) hashes_to_process = search_and_download_mteam(qb, imdb_id, new_name, dl_dir)
# Process qB torrents # Process qB torrents
@@ -314,8 +316,9 @@ if __name__ == "__main__":
parser.add_argument("imdb_id", type=str, help="The IMDb ID to process (e.g., tt38872297)") parser.add_argument("imdb_id", type=str, help="The IMDb ID to process (e.g., tt38872297)")
parser.add_argument("--dl-dir", type=str, default=DEFAULT_DL_DIR, help="The qBittorrent download directory") parser.add_argument("--dl-dir", type=str, default=DEFAULT_DL_DIR, help="The qBittorrent download directory")
parser.add_argument("--jellyfin-dir", type=str, default=DEFAULT_JELLYFIN_DIR, help="The base Jellyfin library directory") parser.add_argument("--jellyfin-dir", type=str, default=DEFAULT_JELLYFIN_DIR, help="The base Jellyfin library directory")
parser.add_argument("--imdb-source", type=str, choices=["mteam", "imdbapi"], default="mteam", help="The source for IMDb metadata (mteam or imdbapi)") parser.add_argument("--imdb-source", type=str, choices=["mteam", "imdbapi"], default="imdbapi", help="The source for IMDb metadata (mteam or imdbapi)")
parser.add_argument("--ignore-existing", action="store_true", help="Ignore any existing torrents or local files and force a new search and download.")
args = parser.parse_args() args = parser.parse_args()
process_imdb_workflow(args.imdb_id, dl_dir=args.dl_dir, jellyfin_base_dir=args.jellyfin_dir, imdb_source=args.imdb_source) process_imdb_workflow(args.imdb_id, dl_dir=args.dl_dir, jellyfin_base_dir=args.jellyfin_dir, imdb_source=args.imdb_source, ignore_existing=args.ignore_existing)