[O] Remove opposite tag if exists
This commit is contained in:
+16
@@ -140,3 +140,19 @@ def rename_torrent_and_folder(qb_client: Client, torrent_hash: str, new_name: st
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print("Warning: Rename may not have fully propagated yet.")
|
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)
|
||||||
|
|||||||
+5
-1
@@ -13,7 +13,8 @@ from utils_qb import (
|
|||||||
download_torrent,
|
download_torrent,
|
||||||
get_torrent_file_tree,
|
get_torrent_file_tree,
|
||||||
get_torrent_hash,
|
get_torrent_hash,
|
||||||
rename_torrent_and_folder
|
rename_torrent_and_folder,
|
||||||
|
remove_tag_if_exists
|
||||||
)
|
)
|
||||||
|
|
||||||
from utils_ai import (
|
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
|
is_tv = True
|
||||||
|
|
||||||
tag = "Jellyfin TV" if is_tv else "Jellyfin Movie"
|
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_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}]"
|
jellyfin_base = Path(jellyfin_dir) / f"{title_dir} [{imdb_id}]"
|
||||||
|
|
||||||
print(f"\n=== [6.5] Adding '{tag}' tag to torrent ===")
|
print(f"\n=== [6.5] Adding '{tag}' tag to torrent ===")
|
||||||
qb.torrents_add_tags(tags=tag, torrent_hashes=t_hash)
|
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 ===")
|
print(f"\n=== [7] Creating symbolic links ===")
|
||||||
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user