mirror of
https://github.com/StuffAnThings/qbit_manage.git
synced 2025-10-22 19:56:07 +08:00
Fixes #650
This commit is contained in:
parent
08810c5d6d
commit
40592192ed
2 changed files with 21 additions and 3 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
4.1.11-develop2
|
||||
4.1.11-develop3
|
||||
|
|
|
@ -427,15 +427,19 @@ class Qbt:
|
|||
else:
|
||||
recycle_path = self.config.recycle_dir
|
||||
# Create recycle bin if not exists
|
||||
torrent_path = os.path.join(recycle_path, "torrents")
|
||||
torrent_path = os.path.join(recycle_path, "torrents") # Export torrent/fastresume from BT_backup
|
||||
torrent_export_path = os.path.join(recycle_path, "torrents_export") # Exported torrent file (qbittorrent v4.5.0+)
|
||||
torrents_json_path = os.path.join(recycle_path, "torrents_json")
|
||||
torrent_name = info["torrents"][0]
|
||||
torrent_exportable = self.current_version >= "4.5.0"
|
||||
os.makedirs(recycle_path, exist_ok=True)
|
||||
if self.config.recyclebin["save_torrents"]:
|
||||
if os.path.isdir(torrent_path) is False:
|
||||
os.makedirs(torrent_path)
|
||||
if os.path.isdir(torrents_json_path) is False:
|
||||
os.makedirs(torrents_json_path)
|
||||
if torrent_exportable and os.path.isdir(torrent_export_path) is False:
|
||||
os.makedirs(torrent_export_path)
|
||||
torrent_json_file = os.path.join(torrents_json_path, f"{torrent_name}.json")
|
||||
torrent_json = util.load_json(torrent_json_file)
|
||||
if not torrent_json:
|
||||
|
@ -445,6 +449,20 @@ class Qbt:
|
|||
else:
|
||||
logger.info(f"Adding {info['torrent_tracker']} to existing {os.path.basename(torrent_json_file)}")
|
||||
dot_torrent_files = []
|
||||
# Exporting torrent via Qbit API (v4.5.0+)
|
||||
if torrent_exportable:
|
||||
hash_suffix = f"{info_hash[-8:]}" # Get the last 8 hash characters of the torrent
|
||||
torrent_export_file = os.path.join(torrent_export_path, f"{torrent_name} [{hash_suffix}].torrent")
|
||||
truncated_torrent_export_file = util.truncate_filename(torrent_export_file, offset=11)
|
||||
try:
|
||||
with open(f"{truncated_torrent_export_file}", "wb") as file:
|
||||
file.write(torrent.export())
|
||||
except Exception as ex:
|
||||
logger.stacktrace()
|
||||
self.config.notify(ex, "Deleting Torrent", False)
|
||||
logger.warning(f"RecycleBin Warning: {ex}")
|
||||
dot_torrent_files.append(os.path.basename(truncated_torrent_export_file))
|
||||
# Exporting torrent via torrent directory (backwards compatibility)
|
||||
for file in os.listdir(self.config.torrents_dir):
|
||||
if file.startswith(info_hash):
|
||||
dot_torrent_files.append(file)
|
||||
|
@ -466,7 +484,7 @@ class Qbt:
|
|||
backup_str += val
|
||||
else:
|
||||
backup_str += f" and {val.replace(info_hash, '')}"
|
||||
backup_str += f" to {torrent_path}"
|
||||
backup_str += f" to {torrent_export_path if torrent_exportable else torrent_path}"
|
||||
logger.info(backup_str)
|
||||
torrent_json["tracker_torrent_files"] = tracker_torrent_files
|
||||
if "files" not in torrent_json:
|
||||
|
|
Loading…
Add table
Reference in a new issue