fix 尝试补充mp之外下载的download_hash

This commit is contained in:
thsrite 2023-08-21 13:09:17 +08:00
parent 6afdfa3b97
commit 1e7f5bf04e

View File

@ -263,8 +263,8 @@ class DirMonitor(_PluginBase):
return return
# 获取downloadhash # 获取downloadhash
download_hash = self.get_download_hash(file_name=os.path.basename(event_path), download_hash = self.get_download_hash(src=event_path,
tmdb_id=mediainfo.tmdb_id,) tmdb_id=mediainfo.tmdb_id, )
# 新增转移成功历史记录 # 新增转移成功历史记录
self.transferhis.add_force( self.transferhis.add_force(
@ -305,10 +305,11 @@ class DirMonitor(_PluginBase):
except Exception as e: except Exception as e:
logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc())) logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc()))
def get_download_hash(self, file_name, tmdb_id): def get_download_hash(self, src, tmdb_id):
""" """
获取download_hash 获取download_hash
""" """
file_name = os.path.basename(src)
downloadHis = self.downloadhis.get_last_by(tmdbid=tmdb_id) downloadHis = self.downloadhis.get_last_by(tmdbid=tmdb_id)
if downloadHis: if downloadHis:
for his in downloadHis: for his in downloadHis:
@ -328,6 +329,37 @@ class DirMonitor(_PluginBase):
torrent_file_name = file.name torrent_file_name = file.name
if str(file_name) == str(os.path.basename(torrent_file_name)): if str(file_name) == str(os.path.basename(torrent_file_name)):
return his.download_hash return his.download_hash
else:
# 尝试获取下载任务补充download_hash
logger.debug(f"转移记录 {src} 缺失download_hash尝试补充……")
# 获取tr、qb所有种子
qb_torrents, _ = self.qb.get_torrents()
tr_torrents, _ = self.tr.get_torrents()
# 种子名称
torrent_name = str(src).split("/")[-1]
torrent_name2 = str(src).split("/")[-2]
# 处理下载器
for torrent in qb_torrents:
if str(torrent.get("name")) == str(torrent_name) \
or str(torrent.get("name")) == str(torrent_name2):
return torrent.get("hash")
# 处理辅种器 遍历所有种子,按照添加升序升序,第一个种子是初始种子
mate_torrents = []
for torrent in tr_torrents:
if str(torrent.get("name")) == str(torrent_name) \
or str(torrent.get("name")) == str(torrent_name2):
mate_torrents.append(torrent)
# 匹配上则按照时间升序
if mate_torrents:
if len(mate_torrents) > 1:
mate_torrents = sorted(mate_torrents, key=lambda x: x.added_date)
# 最早添加的hash是下载的hash
return mate_torrents[0].get("hashString")
return None return None