From 9ece2ecf40d8c5085e46ec7e256c6a0788cc4832 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Mon, 9 Mar 2026 02:51:31 -0400 Subject: [PATCH] [O] Remove opposite tag if exists --- utils_qb.py | 16 ++++++++++++++++ workflow.py | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/utils_qb.py b/utils_qb.py index 56ca998..e422e4d 100644 --- a/utils_qb.py +++ b/utils_qb.py @@ -140,3 +140,19 @@ def rename_torrent_and_folder(qb_client: Client, torrent_hash: str, new_name: st time.sleep(1) print("Warning: Rename may not have fully propagated yet.") + +def remove_tag_if_exists(qb_client: Client, torrent_hash: str, tag_to_remove: str) -> None: + """ + Checks if a tag exists on a torrent, and removes it if it does. + """ + info = qb_client.torrents_info(hashes=torrent_hash) + if not info: + return + + t_info = info[0] + tags = getattr(t_info, "tags", "") + if tags: + tag_list = [t.strip() for t in tags.split(",") if t.strip()] + if tag_to_remove in tag_list: + print(f"Removing existing tag '{tag_to_remove}' from torrent.") + qb_client.torrents_remove_tags(tags=tag_to_remove, torrent_hashes=torrent_hash) diff --git a/workflow.py b/workflow.py index 443ce43..a72b4b6 100644 --- a/workflow.py +++ b/workflow.py @@ -13,7 +13,8 @@ from utils_qb import ( download_torrent, get_torrent_file_tree, get_torrent_hash, - rename_torrent_and_folder + rename_torrent_and_folder, + remove_tag_if_exists ) from utils_ai import ( @@ -186,11 +187,14 @@ def process_imdb_workflow(imdb_id: str, dl_dir: str = "/data/QB", jellyfin_base_ is_tv = True tag = "Jellyfin TV" if is_tv else "Jellyfin Movie" + opposite_tag = "Jellyfin Movie" if is_tv else "Jellyfin TV" + jellyfin_dir = f"{jellyfin_base_dir}/TV" if is_tv else f"{jellyfin_base_dir}/Movie" jellyfin_base = Path(jellyfin_dir) / f"{title_dir} [{imdb_id}]" print(f"\n=== [6.5] Adding '{tag}' tag to torrent ===") qb.torrents_add_tags(tags=tag, torrent_hashes=t_hash) + remove_tag_if_exists(qb, t_hash, opposite_tag) print(f"\n=== [7] Creating symbolic links ===") apply_rename_mapping(mapping, base_src_dir=src_dir_for_mapping, base_dst_dir=jellyfin_base)