diff --git a/app/chain/__init__.py b/app/chain/__init__.py index 6bdc2ead..ac67e090 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -40,7 +40,7 @@ class _ChainBase(AbstractSingleton, metaclass=Singleton): else: return result is None - logger.info(f"请求模块执行:{method} ...") + logger.debug(f"请求模块执行:{method} ...") result = None modules = self.modulemanager.get_modules(method) for module in modules: diff --git a/app/chain/douban_sync.py b/app/chain/douban_sync.py index c48defb4..ff50e5b2 100644 --- a/app/chain/douban_sync.py +++ b/app/chain/douban_sync.py @@ -50,6 +50,8 @@ class DoubanSyncChain(_ChainBase): title = result.get("title", "")[2:] if dtype not in ["想看"]: continue + if not result.get("link"): + continue douban_id = result.get("link", "").split("/")[-2] if not douban_id or douban_id in caches: continue diff --git a/app/chain/search.py b/app/chain/search.py index 7e004c50..05b4ec41 100644 --- a/app/chain/search.py +++ b/app/chain/search.py @@ -57,6 +57,7 @@ class SearchChain(_ChainBase): # 过滤 if torrent_mediainfo.tmdb_id == mediainfo.tmdb_id \ and torrent_mediainfo.type == mediainfo.type: + logger.info(f'{mediainfo.title} 匹配到资源:{torrent.title}') _match_torrents.append(torrent) else: _match_torrents = torrents diff --git a/app/helper/rss.py b/app/helper/rss.py index 949f8511..8ea2c433 100644 --- a/app/helper/rss.py +++ b/app/helper/rss.py @@ -53,7 +53,6 @@ class RssHelper: # 部分RSS只有link没有enclosure if not enclosure and link: enclosure = link - link = None # 大小 size = DomUtils.tag_value(item, "enclosure", "length", default=0) if size and str(size).isdigit(): diff --git a/app/modules/filter/RuleParser.py b/app/modules/filter/RuleParser.py index 90678033..2e81b556 100644 --- a/app/modules/filter/RuleParser.py +++ b/app/modules/filter/RuleParser.py @@ -41,6 +41,7 @@ class RuleParser: if __name__ == '__main__': # 测试代码 - expression1 = "!BLU & (1080P | CN)" - parsed_expr1 = RuleParser().parse(expression1) - print(parsed_expr1.as_list()) + expression = "!BLU & 4K & CN > !BLU & 1080P & CN > !BLU & 4K > !BLU & 1080P" + for exp in expression.split('>'): + parsed_expr = RuleParser().parse(exp) + print(parsed_expr.as_list()) diff --git a/app/modules/filter/__init__.py b/app/modules/filter/__init__.py index 94838689..0417262f 100644 --- a/app/modules/filter/__init__.py +++ b/app/modules/filter/__init__.py @@ -111,15 +111,18 @@ class FilterModule(_ModuleBase): if not isinstance(rule_group, list): # 不是列表,说明是规则名称 return self.__match_rule(torrent, rule_group) - if rule_group[0] == "not": + elif isinstance(rule_group, list) and len(rule_group) == 1: + # 只有一个规则项 + return self.__match_rule(torrent, rule_group[0]) + elif rule_group[0] == "not": # 非操作 - return not self.__match_group(torrent, rule_group[1]) + return not self.__match_group(torrent, rule_group[1:]) elif rule_group[1] == "and": # 与操作 - return self.__match_group(torrent, rule_group[0]) and self.__match_group(torrent, rule_group[2]) + return self.__match_group(torrent, rule_group[0]) and self.__match_group(torrent, rule_group[2:]) elif rule_group[1] == "or": # 或操作 - return self.__match_group(torrent, rule_group[0]) or self.__match_group(torrent, rule_group[2]) + return self.__match_group(torrent, rule_group[0]) or self.__match_group(torrent, rule_group[2:]) def __match_rule(self, torrent: TorrentInfo, rule_name: str) -> bool: """ diff --git a/app/modules/qbittorrent/qbittorrent.py b/app/modules/qbittorrent/qbittorrent.py index 8ae18038..50dec96a 100644 --- a/app/modules/qbittorrent/qbittorrent.py +++ b/app/modules/qbittorrent/qbittorrent.py @@ -18,6 +18,8 @@ class Qbittorrent(metaclass=Singleton): _username: str = None _passowrd: str = None + qbc: Client = None + def __init__(self): host = settings.QB_HOST if host and host.find(":") != -1: @@ -44,7 +46,7 @@ class Qbittorrent(metaclass=Singleton): try: qbt.auth_log_in() except qbittorrentapi.LoginFailed as e: - print(str(e)) + logger.error(f"qbittorrent 登录失败:{e}") return qbt except Exception as err: logger.error(f"qbittorrent 连接出错:{err}") diff --git a/app/modules/transmission/transmission.py b/app/modules/transmission/transmission.py index 97811a9c..555499ae 100644 --- a/app/modules/transmission/transmission.py +++ b/app/modules/transmission/transmission.py @@ -16,6 +16,8 @@ class Transmission(metaclass=Singleton): _username: str = None _passowrd: str = None + trc: Optional[Client] = None + # 参考transmission web,仅查询需要的参数,加速种子搜索 _trarg = ["id", "name", "status", "labels", "hashString", "totalSize", "percentDone", "addedDate", "trackerStats", "leftUntilDone", "rateDownload", "rateUpload", "recheckProgress", "rateDownload", "rateUpload", @@ -46,7 +48,7 @@ class Transmission(metaclass=Singleton): timeout=60) return trt except Exception as err: - logger.error(f"连接出错:{err}") + logger.error(f"transmission 连接出错:{err}") return None def get_torrents(self, ids: Union[str, list] = None, status: Union[str, list] = None, diff --git a/tests/run.py b/tests/run.py index 5aa52913..a7fbebba 100644 --- a/tests/run.py +++ b/tests/run.py @@ -1,7 +1,10 @@ import unittest +from tests.test_cookiecloud import CookieCloudTest +from tests.test_doubansync import DoubanSyncTest from tests.test_metainfo import MetaInfoTest from tests.test_recognize import RecognizeTest +from tests.test_transfer import TransferTest if __name__ == '__main__': suite = unittest.TestSuite() @@ -9,6 +12,12 @@ if __name__ == '__main__': suite.addTest(MetaInfoTest('test_metainfo')) # 测试媒体识别 suite.addTest(RecognizeTest('test_recognize')) + # 测试CookieCloud同步 + suite.addTest(CookieCloudTest('test_cookiecloud')) + # 测试文件转移 + suite.addTest(TransferTest('test_transfer')) + # 测试豆瓣同步 + suite.addTest(DoubanSyncTest('test_doubansync')) # 运行测试 runner = unittest.TextTestRunner() runner.run(suite) diff --git a/tests/test_cookiecloud.py b/tests/test_cookiecloud.py new file mode 100644 index 00000000..59879b62 --- /dev/null +++ b/tests/test_cookiecloud.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase + +from app.chain.cookiecloud import CookieCloudChain + + +class CookieCloudTest(TestCase): + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def test_cookiecloud(self): + result = CookieCloudChain().process() + self.assertEqual(result[0], True) diff --git a/tests/test_doubansync.py b/tests/test_doubansync.py new file mode 100644 index 00000000..e2b78f66 --- /dev/null +++ b/tests/test_doubansync.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase + +from app.chain.douban_sync import DoubanSyncChain + + +class DoubanSyncTest(TestCase): + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def test_doubansync(self): + result = DoubanSyncChain().process() + self.assertEqual(result[0], True) diff --git a/tests/test_transfer.py b/tests/test_transfer.py new file mode 100644 index 00000000..9e18ce19 --- /dev/null +++ b/tests/test_transfer.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from unittest import TestCase + +from app.chain.transfer import TransferChain + + +class TransferTest(TestCase): + def setUp(self) -> None: + pass + + def tearDown(self) -> None: + pass + + def test_transfer(self): + result = TransferChain().process() + self.assertEqual(result[0], True)