[O] Rename torrent in qb
This commit is contained in:
+24
@@ -86,3 +86,27 @@ def get_torrent_hash(source: str | bytes) -> str:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Could not parse torrent hash: {e}")
|
print(f"Could not parse torrent hash: {e}")
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
def rename_torrent_and_folder(qb_client: Client, torrent_hash: str, new_name: str) -> None:
|
||||||
|
"""
|
||||||
|
Renames the torrent display name and the top-level folder on disk to the given `new_name`.
|
||||||
|
"""
|
||||||
|
info = qb_client.torrents_info(hashes=torrent_hash)
|
||||||
|
if not info:
|
||||||
|
print(f"Torrent {torrent_hash} not found to rename.")
|
||||||
|
return
|
||||||
|
|
||||||
|
t_info = info[0]
|
||||||
|
old_name = t_info.name
|
||||||
|
|
||||||
|
print(f"Renaming torrent and top-level dir from '{old_name}' to '{new_name}'")
|
||||||
|
try:
|
||||||
|
qb_client.torrents_rename(torrent_hash=torrent_hash, new_torrent_name=new_name)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to rename torrent: {e}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
qb_client.torrents_rename_folder(torrent_hash=torrent_hash, old_path=old_name, new_path=new_name)
|
||||||
|
except Exception as e:
|
||||||
|
# Might be a single-file torrent or no root folder
|
||||||
|
print(f"Failed to rename folder: {e}")
|
||||||
|
|||||||
+5
-1
@@ -12,7 +12,8 @@ from utils_qb import (
|
|||||||
get_qb_client,
|
get_qb_client,
|
||||||
download_torrent,
|
download_torrent,
|
||||||
get_torrent_file_tree,
|
get_torrent_file_tree,
|
||||||
get_torrent_hash
|
get_torrent_hash,
|
||||||
|
rename_torrent_and_folder
|
||||||
)
|
)
|
||||||
|
|
||||||
from utils_ai import (
|
from utils_ai import (
|
||||||
@@ -107,6 +108,9 @@ def process_imdb_workflow(imdb_id: str, dl_dir: str = "/data/qb", jellyfin_base_
|
|||||||
|
|
||||||
print(f"Tracking torrent Hash: {t_hash}")
|
print(f"Tracking torrent Hash: {t_hash}")
|
||||||
|
|
||||||
|
new_name = f"{year} {title}".strip()
|
||||||
|
rename_torrent_and_folder(qb, t_hash, new_name)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
info = qb.torrents_info(hashes=t_hash)
|
info = qb.torrents_info(hashes=t_hash)
|
||||||
if not info:
|
if not info:
|
||||||
|
|||||||
Reference in New Issue
Block a user