diff --git a/src/module/core/program.py b/src/module/core/program.py index fb142dab4..c31828654 100644 --- a/src/module/core/program.py +++ b/src/module/core/program.py @@ -1,6 +1,7 @@ import logging from .sub_thread import RenameThread, RSSThread +from .rss_feed import add_rss_feed from module.conf import settings, VERSION from module.update import data_migration @@ -30,7 +31,7 @@ def startup(self): "Legacy data detected, starting data migration, please wait patiently." ) data_migration() - # TODO: Add rss feed to downloader + add_rss_feed() self.start() def start(self): diff --git a/src/module/core/rss_feed.py b/src/module/core/rss_feed.py new file mode 100644 index 000000000..39f046bb9 --- /dev/null +++ b/src/module/core/rss_feed.py @@ -0,0 +1,33 @@ +import logging + +from module.downloader import DownloadClient +from module.conf import settings + +logger = logging.getLogger(__name__) + + +def add_rss_feed(): + with DownloadClient() as client: + # Check Feed if exists + add = True + remove = False + feeds = client.get_rss_feed() + for item_path, value in feeds.items(): + if value.url == settings.rss_link: + add = False + break + elif item_path == "Mikan_RSS": + remove = True + if remove: + client.remove_rss_feed("Mikan_RSS") + logger.info("Remove Old RSS Feed: Mikan_RSS") + # Add Feed + if add: + client.add_rss_feed(settings.rss_link) + logger.info(f"Add RSS Feed: {settings.rss_link}") + + +if __name__ == '__main__': + from module.conf import setup_logger + setup_logger() + add_rss_feed() \ No newline at end of file diff --git a/src/module/downloader/client/qb_downloader.py b/src/module/downloader/client/qb_downloader.py index 85cfc747a..fadefdd7b 100644 --- a/src/module/downloader/client/qb_downloader.py +++ b/src/module/downloader/client/qb_downloader.py @@ -87,35 +87,8 @@ def torrents_rename_file(self, torrent_hash, old_path, new_path) -> bool: logger.debug(f"Conflict409Error: {old_path} >> {new_path}") return False - def check_rss(self, url, item_path) -> tuple[str | None, bool]: - items = self._client.rss_items() - for key, value in items.items(): - rss_url = value.get("url") - if key == item_path: - if rss_url != url: - return key, False - return None, True - else: - if rss_url == url: - return key, True - return None, False - def rss_add_feed(self, url, item_path): - path, added = self.check_rss(url, item_path) - if path: - if not added: - logger.info("RSS Exist, Update URL.") - self._client.rss_remove_item(path) - self._client.rss_add_feed(url, item_path) - else: - logger.info("RSS Exist.") - else: - if added: - logger.info("RSS Exist.") - else: - logger.info("Add new RSS") - self._client.rss_add_feed(url, item_path) - logger.info("Successfully added RSS") + self._client.rss_add_feed(url, item_path) def rss_remove_item(self, item_path): try: @@ -125,6 +98,9 @@ def rss_remove_item(self, item_path): logger.info("Add new RSS") raise ConflictError() + def rss_get_feeds(self): + return self._client.rss_items() + def rss_set_rule(self, rule_name, rule_def): self._client.rss_set_rule(rule_name, rule_def) diff --git a/src/module/downloader/download_client.py b/src/module/downloader/download_client.py index c3b87efcd..f3becdd81 100644 --- a/src/module/downloader/download_client.py +++ b/src/module/downloader/download_client.py @@ -30,9 +30,7 @@ def __getClient(): def __enter__(self): if not self.authed: - logger.debug("Authing to downloader...") self.auth() - logger.debug("Authed.") return self def __exit__(self, exc_type, exc_val, exc_tb): @@ -42,6 +40,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): def auth(self): self.authed = self.client.auth() + logger.debug("Authed.") def init_downloader(self): prefs = { @@ -82,10 +81,6 @@ def set_rule(self, data: BangumiData): data.added = True logger.info(f"Add {data.official_title} Season {data.season} to auto download rules.") - def add_collection_feed(self, rss_link, item_path): - self.client.rss_add_feed(url=rss_link, item_path=item_path) - logger.info("Add Collection RSS Feed successfully.") - def set_rules(self, bangumi_info: list[BangumiData]): logger.debug("Start adding rules.") for info in bangumi_info: @@ -114,9 +109,15 @@ def add_torrent(self, torrent: dict): def move_torrent(self, hashes, location): self.client.move_torrent(hashes=hashes, new_location=location) + # RSS Parts def add_rss_feed(self, rss_link, item_path="Mikan_RSS"): self.client.rss_add_feed(url=rss_link, item_path=item_path) - logger.info("Add RSS Feed successfully.") + + def remove_rss_feed(self, item_path): + self.client.rss_remove_item(item_path=item_path) + + def get_rss_feed(self): + return self.client.rss_get_feeds() def get_download_rules(self): return self.client.get_download_rule()