From 4b655dfac4b9769cbcb71426115fc4de36bb5005 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 28 Oct 2023 17:41:22 +0800 Subject: [PATCH 1/4] fix #957 fix #982 --- app/api/endpoints/history.py | 8 ++++++-- app/chain/transfer.py | 14 ++++++++++---- app/plugins/autoclean/__init__.py | 5 ++--- app/schemas/history.py | 2 ++ 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index 786b02f7..3aca0475 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -75,10 +75,14 @@ def delete_transfer_history(history_in: schemas.TransferHistory, return schemas.Response(success=False, msg="记录不存在") # 册除媒体库文件 if deletedest and history.dest: - TransferChain().delete_files(Path(history.dest)) + state, msg = TransferChain().delete_files(Path(history.dest)) + if not state: + return schemas.Response(success=False, msg=msg) # 删除源文件 if deletesrc and history.src: - TransferChain().delete_files(Path(history.src)) + state, msg = TransferChain().delete_files(Path(history.src)) + if not state: + return schemas.Response(success=False, msg=msg) # 发送事件 eventmanager.send_event( EventType.DownloadFileDeleted, diff --git a/app/chain/transfer.py b/app/chain/transfer.py index fac02d58..1cfd0c28 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -617,14 +617,15 @@ class TransferChain(ChainBase): title=msg_title, text=msg_str, image=mediainfo.get_message_image())) @staticmethod - def delete_files(path: Path): + def delete_files(path: Path) -> Tuple[bool, str]: """ 删除转移后的文件以及空目录 :param path: 文件路径 + :return: 成功标识,错误信息 """ logger.info(f"开始删除文件以及空目录:{path} ...") if not path.exists(): - return + return True, f"文件或目录不存在:{path}" if path.is_file(): # 删除文件、nfo、jpg等同名文件 pattern = path.stem.replace('[', '?').replace(']', '?') @@ -636,7 +637,7 @@ class TransferChain(ChainBase): elif str(path.parent) == str(path.root): # 根目录,不删除 logger.warn(f"根目录 {path} 不能删除!") - return + return False, f"根目录 {path} 不能删除!" else: # 非根目录,才删除目录 shutil.rmtree(path) @@ -662,5 +663,10 @@ class TransferChain(ChainBase): # 父目录非根目录,才删除父目录 if not SystemUtils.exits_files(parent_path, settings.RMT_MEDIAEXT): # 当前路径下没有媒体文件则删除 - shutil.rmtree(parent_path) + try: + shutil.rmtree(parent_path) + except Exception as e: + logger.error(f"删除目录 {parent_path} 失败:{str(e)}") + return False, f"删除目录 {parent_path} 失败:{str(e)}" logger.warn(f"目录 {parent_path} 已删除") + return True, "" diff --git a/app/plugins/autoclean/__init__.py b/app/plugins/autoclean/__init__.py index d5e370d0..c38556f9 100644 --- a/app/plugins/autoclean/__init__.py +++ b/app/plugins/autoclean/__init__.py @@ -159,7 +159,6 @@ class AutoClean(_PluginBase): # 输出分组结果 for key, downloadhis_list in downloadhis_grouped_dict.items(): logger.info(f"开始清理 {key}") - result = [] del_transferhis_cnt = 0 del_media_name = downloadhis_list[0].title del_media_user = downloadhis_list[0].username @@ -208,7 +207,7 @@ class AutoClean(_PluginBase): f"下载媒体用户 {del_media_user}\n" f"删除历史记录 {del_transferhis_cnt}") - result.append({ + history.append({ "type": del_media_type, "title": del_media_name, "year": del_media_year, @@ -219,7 +218,7 @@ class AutoClean(_PluginBase): }) # 保存历史 - self.save_data("history", result) + self.save_data("history", history) def get_state(self) -> bool: return self._enabled diff --git a/app/schemas/history.py b/app/schemas/history.py index 749f5399..c10f2c78 100644 --- a/app/schemas/history.py +++ b/app/schemas/history.py @@ -38,6 +38,8 @@ class DownloadHistory(BaseModel): torrent_site: Optional[str] = None # 下载用户 userid: Optional[str] = None + # 下载用户名 + username: Optional[str] = None # 下载渠道 channel: Optional[str] = None # 创建时间 From d03771f8abc2f0f2dc3b268cc98512a209962c6a Mon Sep 17 00:00:00 2001 From: WithdewHua Date: Sat, 28 Oct 2023 15:03:17 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20qb=20=E6=94=AF=E6=8C=81=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E7=BB=A7=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + app/core/config.py | 2 ++ app/modules/qbittorrent/__init__.py | 8 +++++++- config/app.env | 2 ++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32f47f9e..3008b1da 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,7 @@ MoviePilot需要配套下载器和媒体服务器配合使用。 - **QB_PASSWORD:** qbittorrent密码 - **QB_CATEGORY:** qbittorrent分类自动管理,`true`/`false`,默认`false`,开启后会将下载二级分类传递到下载器,由下载器管理下载目录,需要同步开启`DOWNLOAD_CATEGORY` - **QB_SEQUENTIAL:** qbittorrent按顺序下载,`true`/`false`,默认`true` + - **QB_FORCE_RESUME:** qbittorrent忽略队列限制,强制继续,`true`/`false`,默认 `false` - `transmission`设置项: diff --git a/app/core/config.py b/app/core/config.py index 6131e626..c4e99b96 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -131,6 +131,8 @@ class Settings(BaseSettings): QB_CATEGORY: bool = False # Qbittorrent按顺序下载 QB_SEQUENTIAL: bool = True + # Qbittorrent忽略队列限制,强制继续 + QB_FORCE_RESUME: bool = False # Transmission地址,IP:PORT TR_HOST: str = None # Transmission用户名 diff --git a/app/modules/qbittorrent/__init__.py b/app/modules/qbittorrent/__init__.py index 4d370d97..922e09d2 100644 --- a/app/modules/qbittorrent/__init__.py +++ b/app/modules/qbittorrent/__init__.py @@ -101,9 +101,15 @@ class QbittorrentModule(_ModuleBase): # 选择文件 self.qbittorrent.set_files(torrent_hash=torrent_hash, file_ids=file_ids, priority=0) # 开始任务 - self.qbittorrent.start_torrents(torrent_hash) + if settings.QB_FORCE_RESUME: + # 强制继续 + self.qbittorrent.torrents_set_force_start(torrent_hash) + else: + self.qbittorrent.start_torrents(torrent_hash) return torrent_hash, f"添加下载成功,已选择集数:{sucess_epidised}" else: + if settings.QB_FORCE_RESUME: + self.qbittorrent.torrents_set_force_start(torrent_hash) return torrent_hash, "添加下载成功" def list_torrents(self, status: TorrentStatus = None, diff --git a/config/app.env b/config/app.env index ffb01a14..cc40755e 100644 --- a/config/app.env +++ b/config/app.env @@ -143,6 +143,8 @@ QB_PASSWORD= QB_CATEGORY=false # Qbittorrent按顺序下载 QB_SEQUENTIAL=true +# Qbittorrent忽略队列限制,强制继续 +QB_FORCE_RESUME=false # Transmission地址,IP:PORT TR_HOST= # Transmission用户名 From dea78f4bfd5a87e7686c1b86b9ac2bbeecf2e27c Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 28 Oct 2023 17:45:28 +0800 Subject: [PATCH 3/4] fix --- app/plugins/iyuuautoseed/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/plugins/iyuuautoseed/__init__.py b/app/plugins/iyuuautoseed/__init__.py index 71c0f646..0056f2f1 100644 --- a/app/plugins/iyuuautoseed/__init__.py +++ b/app/plugins/iyuuautoseed/__init__.py @@ -11,11 +11,9 @@ from lxml import etree from ruamel.yaml import CommentedMap from app.core.config import settings +from app.core.event import eventmanager from app.db.site_oper import SiteOper from app.helper.sites import SitesHelper - -from app.core.event import eventmanager -from app.db.models.site import Site from app.helper.torrent import TorrentHelper from app.log import logger from app.modules.qbittorrent import Qbittorrent From f2d0bec0ac3f0143563d48e461a8e7c1179cb877 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 28 Oct 2023 17:46:57 +0800 Subject: [PATCH 4/4] fix README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3008b1da..168c3fc2 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,6 @@ MoviePilot需要配套下载器和媒体服务器配合使用。 - **PUID**:运行程序用户的`uid`,默认`0`(仅支持环境变量配置) - **PGID**:运行程序用户的`gid`,默认`0`(仅支持环境变量配置) - **UMASK**:掩码权限,默认`000`,可以考虑设置为`022`(仅支持环境变量配置) -- **WALLPAPER:** 登录首页电影海报,`tmdb`/`bing`,默认`tmdb` - **PROXY_HOST:** 网络代理,访问themoviedb或者重启更新需要使用代理访问,格式为`http(s)://ip:port`、`socks5://user:pass@host:port`(仅支持环境变量配置) - **MOVIEPILOT_AUTO_UPDATE**:重启更新,`true`/`false`,默认`true` **注意:如果出现网络问题可以配置`PROXY_HOST`**(仅支持环境变量配置) - **MOVIEPILOT_AUTO_UPDATE_DEV**:重启时更新到未发布的开发版本代码,`true`/`false`,默认`false`(仅支持环境变量配置) @@ -70,6 +69,7 @@ MoviePilot需要配套下载器和媒体服务器配合使用。 - **❗API_TOKEN:** API密钥,默认`moviepilot`,在媒体服务器Webhook、微信回调等地址配置中需要加上`?token=`该值,建议修改为复杂字符串 - **TMDB_API_DOMAIN:** TMDB API地址,默认`api.themoviedb.org`,也可配置为`api.tmdb.org`或其它中转代理服务地址,能连通即可 - **TMDB_IMAGE_DOMAIN:** TMDB图片地址,默认`image.tmdb.org`,可配置为其它中转代理以加速TMDB图片显示,如:`static-mdb.v.geilijiasu.com` +- **WALLPAPER:** 登录首页电影海报,`tmdb`/`bing`,默认`tmdb` --- - **SCRAP_METADATA:** 刮削入库的媒体文件,`true`/`false`,默认`true` - **SCRAP_SOURCE:** 刮削元数据及图片使用的数据源,`themoviedb`/`douban`,默认`themoviedb`