diff --git a/app/chain/transfer.py b/app/chain/transfer.py index d8dd3632..33b6afd6 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -255,19 +255,19 @@ class TransferChain(ChainBase): medias[file_mediainfo.tmdb_id] = file_mediainfo transfers[file_mediainfo.tmdb_id] = transferinfo else: - # 合并元数据剧集 + # 合并元数据集 if (metas[file_mediainfo.tmdb_id].begin_episode or 0) > (file_meta.begin_episode or 0): metas[file_mediainfo.tmdb_id].begin_episode = file_meta.begin_episode if (metas[file_mediainfo.tmdb_id].end_episode or 0) < (file_meta.end_episode or 0): metas[file_mediainfo.tmdb_id].end_episode = file_meta.end_episode metas[file_mediainfo.tmdb_id].total_episode += file_meta.total_episode - # 合并元数据季度 + # 合并元数据季 if (metas[file_mediainfo.tmdb_id].begin_season or 0) > (file_meta.begin_season or 0): metas[file_mediainfo.tmdb_id].begin_season = file_meta.begin_season if (metas[file_mediainfo.tmdb_id].end_season or 0) < (file_meta.end_season or 0): metas[file_mediainfo.tmdb_id].end_season = file_meta.end_season metas[file_mediainfo.tmdb_id].total_season += file_meta.total_season - # 合并转移 + # 合并转移数据 transfers[file_mediainfo.tmdb_id].file_count += transferinfo.file_count transfers[file_mediainfo.tmdb_id].file_list.extend(transferinfo.file_list) transfers[file_mediainfo.tmdb_id].file_list_new.extend(transferinfo.file_list_new) @@ -502,7 +502,7 @@ class TransferChain(ChainBase): """ 新增转移成功历史记录 """ - self.transferhis.add( + self.transferhis.add_force( src=str(src_path), dest=str(transferinfo.target_path), mode=settings.TRANSFER_TYPE, @@ -525,10 +525,10 @@ class TransferChain(ChainBase): def __insert_fail_history(self, src_path: Path, download_hash: str, meta: MetaBase, transferinfo: TransferInfo = None, mediainfo: MediaInfo = None): """ - 新增转移失败历史记录,不能按download_hash判重 + 新增转移失败历史记录 """ if mediainfo and transferinfo: - his = self.transferhis.add( + his = self.transferhis.add_force( src=str(src_path), dest=str(transferinfo.target_path), mode=settings.TRANSFER_TYPE, @@ -549,7 +549,7 @@ class TransferChain(ChainBase): files=json.dumps(transferinfo.file_list) ) else: - his = self.transferhis.add( + his = self.transferhis.add_force( title=meta.name, year=meta.year, src=str(src_path), @@ -562,8 +562,8 @@ class TransferChain(ChainBase): ) return his - def send_transfer_message(self, meta: MetaBase, mediainfo: MediaInfo, transferinfo: TransferInfo, - season_episode: str = None): + def send_transfer_message(self, meta: MetaBase, mediainfo: MediaInfo, + transferinfo: TransferInfo, season_episode: str = None): """ 发送入库成功的消息 """ diff --git a/app/db/models/downloadhistory.py b/app/db/models/downloadhistory.py index 0c39bc80..cf406bf1 100644 --- a/app/db/models/downloadhistory.py +++ b/app/db/models/downloadhistory.py @@ -89,3 +89,36 @@ class DownloadHistory(Base): DownloadHistory.seasons == season, DownloadHistory.episodes == episode).order_by( DownloadHistory.id.desc()).all() + + +class DownloadFiles(Base): + """ + 下载文件记录 + """ + id = Column(Integer, Sequence('id'), primary_key=True, index=True) + # 下载任务Hash + download_hash = Column(String, index=True) + # 下载器 + downloader = Column(String) + # 完整路径 + fullpath = Column(String, index=True) + # 保存路径 + savepath = Column(String, index=True) + # 文件相对路径/名称 + filepath = Column(String) + # 种子名称 + torrentname = Column(String) + # 状态 0-已删除 1-正常 + state = Column(Integer, nullable=False, default=1) + + @staticmethod + def get_by_hash(db: Session, download_hash: str): + return db.query(DownloadFiles).filter(DownloadFiles.download_hash == download_hash).all() + + @staticmethod + def get_by_full_path(db: Session, fullpath: str): + return db.query(DownloadFiles).filter(DownloadFiles.fullpath == fullpath).first() + + @staticmethod + def get_by_save_path(db: Session, savepath: str): + return db.query(DownloadFiles).filter(DownloadFiles.savepath == savepath).all() diff --git a/app/modules/filetransfer/__init__.py b/app/modules/filetransfer/__init__.py index 89955aaf..90831cad 100644 --- a/app/modules/filetransfer/__init__.py +++ b/app/modules/filetransfer/__init__.py @@ -354,7 +354,7 @@ class FileTransferModule(_ModuleBase): and mediainfo.genre_ids \ and set(mediainfo.genre_ids).intersection(set(settings.ANIME_GENREIDS)): # 动漫 - target_dir = target_dir / settings.LIBRARY_ANIME_NAME / mediainfo.category + target_dir = target_dir / settings.LIBRARY_ANIME_NAME elif settings.LIBRARY_TV_NAME: # 电视剧 target_dir = target_dir / settings.LIBRARY_TV_NAME / mediainfo.category @@ -390,7 +390,7 @@ class FileTransferModule(_ModuleBase): # 返回转移后的路径 return TransferInfo(path=in_path, target_path=new_path, - total_size=in_path.stat().st_size, + total_size=new_path.stat().st_size, is_bluray=bluray_flag) else: # 转移单个文件 @@ -444,9 +444,9 @@ class FileTransferModule(_ModuleBase): logger.info(f"文件 {in_path} 转移成功") return TransferInfo(path=in_path, - target_path=new_file, + target_path=new_file.parent, file_count=1, - total_size=in_path.stat().st_size, + total_size=new_file.stat().st_size, is_bluray=False, file_list=[in_path], file_list_new=[new_file]) diff --git a/app/plugins/dirmonitor/__init__.py b/app/plugins/dirmonitor/__init__.py index ba7dc5cc..578ec964 100644 --- a/app/plugins/dirmonitor/__init__.py +++ b/app/plugins/dirmonitor/__init__.py @@ -490,7 +490,7 @@ class DirMonitor(_PluginBase): def get_download_hash(self, src: Path, tmdb_id: int): """ - 获取download_hash + FIXME 从表中获取download_hash,避免连接下载器 """ file_name = src.name downloadHis = self.downloadhis.get_last_by(tmdbid=tmdb_id)