diff --git a/Dockerfile b/Dockerfile index 94d51631..6bc6abbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,10 +8,11 @@ ENV LANG="C.UTF-8" \ WORKDIR="/MoviePilot" \ CONFIG_DIR="/config" \ API_TOKEN="moviepilot" \ - LIBRARY_PATH="" \ - DOWNLOAD_PATH="/downloads" \ SUPERUSER="admin" \ SUPERUSER_PASSWORD="password" \ + LIBRARY_PATH="" \ + DOWNLOAD_PATH="/downloads" \ + TORRENT_TAG="MOVIEPILOT" \ SEARCH_SOURCE="themoviedb" \ SCRAP_SOURCE="themoviedb" \ INDEXER_SITES="" \ diff --git a/app/command.py b/app/command.py index 0a4a5eff..12d85fc5 100644 --- a/app/command.py +++ b/app/command.py @@ -6,6 +6,7 @@ from app.chain import ChainBase from app.chain.cookiecloud import CookieCloudChain from app.chain.douban_sync import DoubanSyncChain from app.chain.subscribe import SubscribeChain +from app.chain.transfer import TransferChain from app.core import eventmanager, PluginManager, EventManager from app.core.event_manager import Event as ManagerEvent from app.log import logger @@ -44,6 +45,11 @@ class Command(metaclass=Singleton): "data": { 'state': 'R', } + }, + "/transfer": { + "func": TransferChain().process, + "description": "下载文件整理", + "data": {} } } diff --git a/app/core/config.py b/app/core/config.py index e637773b..a6081350 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -96,7 +96,7 @@ class Settings(BaseSettings): # Transmission密码 TR_PASSWORD: str = None # 种子标签 - TORRENT_TAG: str = "MP" + TORRENT_TAG: str = "MOVIEPILOT" # 下载保存目录,容器内映射路径需要一致 DOWNLOAD_PATH: str = "/downloads" # 媒体服务器 emby/jellyfin/plex diff --git a/app/modules/qbittorrent/qbittorrent.py b/app/modules/qbittorrent/qbittorrent.py index 344fb1d7..c5581fc7 100644 --- a/app/modules/qbittorrent/qbittorrent.py +++ b/app/modules/qbittorrent/qbittorrent.py @@ -9,6 +9,7 @@ from qbittorrentapi.client import Client from app.core import settings from app.log import logger from app.utils.singleton import Singleton +from app.utils.string import StringUtils class Qbittorrent(metaclass=Singleton): @@ -21,10 +22,7 @@ class Qbittorrent(metaclass=Singleton): qbc: Client = None def __init__(self): - host = settings.QB_HOST - if host and host.find(":") != -1: - self._host = settings.QB_HOST.split(":")[0] - self._port = settings.QB_HOST.split(":")[1] + self._host, self._port = StringUtils.get_domain_address(settings.QB_HOST) self._username = settings.QB_USER self._password = settings.QB_PASSWORD if self._host and self._port and self._username and self._password: diff --git a/app/modules/telegram/telegram.py b/app/modules/telegram/telegram.py index 28e5b80b..c5bc5bfc 100644 --- a/app/modules/telegram/telegram.py +++ b/app/modules/telegram/telegram.py @@ -33,13 +33,13 @@ class Telegram(metaclass=Singleton): @_bot.message_handler(func=lambda message: True) def echo_all(message): - RequestUtils(timeout=10).post_res(self._ds_url, json=message.json) + RequestUtils(timeout=5).post_res(self._ds_url, json=message.json) def run_polling(): """ 定义线程函数来运行 infinity_polling """ - _bot.infinity_polling() + _bot.infinity_polling(long_polling_timeout=5) # 启动线程来运行 infinity_polling self._polling_thread = threading.Thread(target=run_polling) diff --git a/app/modules/transmission/transmission.py b/app/modules/transmission/transmission.py index 1d97768c..7056595f 100644 --- a/app/modules/transmission/transmission.py +++ b/app/modules/transmission/transmission.py @@ -7,6 +7,7 @@ from transmission_rpc import Client, Torrent, File from app.core import settings from app.log import logger from app.utils.singleton import Singleton +from app.utils.string import StringUtils class Transmission(metaclass=Singleton): @@ -25,10 +26,7 @@ class Transmission(metaclass=Singleton): "error", "errorString", "doneDate", "queuePosition", "activityDate", "trackers"] def __init__(self): - host = settings.TR_HOST - if host and host.find(":") != -1: - self._host = settings.TR_HOST.split(":")[0] - self._port = settings.TR_HOST.split(":")[1] + self._host, self._port = StringUtils.get_domain_address(settings.QB_HOST) self._username = settings.TR_USER self._password = settings.TR_PASSWORD if self._host and self._port and self._username and self._password: diff --git a/app/utils/string.py b/app/utils/string.py index 614e391d..8759e99e 100644 --- a/app/utils/string.py +++ b/app/utils/string.py @@ -530,3 +530,24 @@ class StringUtils: parses = re.sub(r"([_*\[\]()~`>#+\-=|.!{}])", r"\\\1", content) reparse = re.sub(r"\\\\([_*\[\]()~`>#+\-=|.!{}])", r"\1", parses) return reparse + + @staticmethod + def get_domain_address(address: str) -> Tuple[Optional[str], Optional[int]]: + """ + 从地址中获取域名和端口号 + """ + if not address.startswith("http"): + address = "http://" + address + parts = address.split(":") + if len(parts) > 3: + # 处理不希望包含多个冒号的情况(除了协议后的冒号) + return None, None + domain = ":".join(parts[:-1]) + # 检查是否包含端口号 + try: + port = int(parts[-1]) + except ValueError: + # 端口号不是整数,返回 None 表示无效 + return None, None + return domain, port + diff --git a/tests/run.py b/tests/run.py index 9dcb2032..ed4cfb9d 100644 --- a/tests/run.py +++ b/tests/run.py @@ -11,17 +11,17 @@ if __name__ == '__main__': suite = unittest.TestSuite() # 测试过滤器 - suite.addTest(FilterTest('test_filter')) + # suite.addTest(FilterTest('test_filter')) # 测试名称识别 - suite.addTest(MetaInfoTest('test_metainfo')) + # suite.addTest(MetaInfoTest('test_metainfo')) # 测试媒体识别 # suite.addTest(RecognizeTest('test_recognize')) # 测试CookieCloud同步 # suite.addTest(CookieCloudTest('test_cookiecloud')) # 测试文件转移 - # suite.addTest(TransferTest('test_transfer')) + suite.addTest(TransferTest('test_transfer')) # 测试豆瓣同步 - suite.addTest(DoubanSyncTest('test_doubansync')) + # suite.addTest(DoubanSyncTest('test_doubansync')) # 运行测试 runner = unittest.TextTestRunner()