From b781ca72ac17ff75e4915d609fe57633625b83bb Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 3 May 2023 17:44:34 +0800 Subject: [PATCH 1/6] Fix #228 --- src/module/manager/renamer.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/module/manager/renamer.py b/src/module/manager/renamer.py index 8c49d06b..81be1c49 100644 --- a/src/module/manager/renamer.py +++ b/src/module/manager/renamer.py @@ -46,7 +46,7 @@ class Renamer: def rename_file(self, info, media_path: str, rename_method: str, bangumi_name: str, season: int, remove_bad_torrents: bool): torrent_name = info.name suffix = os.path.splitext(media_path)[-1] - compare_name = media_path.split(os.path.sep)[-1] + compare_name = self.get_file_name(media_path) new_path = self._renamer.torrent_parser( torrent_name=torrent_name, bangumi_name=bangumi_name, @@ -71,7 +71,7 @@ class Renamer: path_len = len(media_path.split(os.path.sep)) if path_len <= 2: suffix = os.path.splitext(media_path)[-1] - torrent_name = media_path.split(os.path.sep)[-1] + torrent_name = self.get_file_name(media_path) new_name = self._renamer.torrent_parser( torrent_name=torrent_name, bangumi_name=bangumi_name, @@ -99,7 +99,7 @@ class Renamer: ): for subtitle_path in subtitle_list: suffix = os.path.splitext(subtitle_path)[-1] - old_name = subtitle_path.split(os.path.sep)[-1] + old_name = self.get_file_name(subtitle_path) new_name = self._renamer.torrent_parser( method="subtitle", torrent_name=old_name, @@ -129,7 +129,7 @@ class Renamer: if PurePath(save_path).name != save_path \ else PureWindowsPath(save_path).parts # Get folder name - folder_name = path_parts[1] if path_parts[0] == "/" else path_parts[0] + folder_name = path_parts[1] if path_parts[0] == "/" or path_parts[0] == "\\" else path_parts[0] # Get season try: if re.search(r"S\d{1,2}|[Ss]eason", path_parts[-1]) is not None: @@ -142,6 +142,16 @@ class Renamer: season = 1 return folder_name, season + @staticmethod + def get_file_name(file_path: str): + # Check windows or linux path + path_parts = PurePath(file_path).parts \ + if PurePath(file_path).name != file_path \ + else PureWindowsPath(file_path).parts + # Get file name + file_name = path_parts[-1] + return file_name + def rename(self): # Get torrent info download_path = self.settings.downloader.path @@ -192,15 +202,6 @@ if __name__ == '__main__': setup_logger() client = DownloadClient(settings) renamer = Renamer(client, settings) - info, _ = renamer.get_torrent_info(category="BangumiCollection") - for i in info: - _hash = i.hash - _, subtitle_list = renamer.check_files(i) - print(_hash) - bangumi_name, season = renamer.get_season_info(i.save_path, settings.downloader.path) - renamer.rename_subtitles( - subtitle_list, - bangumi_name=bangumi_name, - season=season, - _hash=_hash - ) \ No newline at end of file + save_path = "D:\Videos\Bangumi\我推的孩子\Season 1\[XKsub][Oshi no Ko][01][CHS][1080P][WEBrip][MP4].mp4" + path = renamer.get_file_name(save_path) + print(path) \ No newline at end of file From 476adc308d025e9d7b5fe4c68a639ea90677ca92 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 3 May 2023 20:24:45 +0800 Subject: [PATCH 2/6] Add advance to subtitle rename --- src/module/manager/renamer.py | 16 ++++--------- src/module/parser/analyser/torrent_parser.py | 25 +++++++++++++++++++- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/module/manager/renamer.py b/src/module/manager/renamer.py index 81be1c49..0c8db6c8 100644 --- a/src/module/manager/renamer.py +++ b/src/module/manager/renamer.py @@ -95,13 +95,15 @@ class Renamer: subtitle_list: list[str], bangumi_name: str, season: int, + method: str, _hash ): + method = "subtitle_" + method for subtitle_path in subtitle_list: suffix = os.path.splitext(subtitle_path)[-1] old_name = self.get_file_name(subtitle_path) new_name = self._renamer.torrent_parser( - method="subtitle", + method=method, torrent_name=old_name, bangumi_name=bangumi_name, season=season, @@ -175,6 +177,7 @@ class Renamer: subtitle_list=subtitle_list, bangumi_name=bangumi_name, season=season, + method=rename_method, _hash=info.hash ) elif len(media_list) > 1: @@ -191,17 +194,8 @@ class Renamer: subtitle_list=subtitle_list, bangumi_name=bangumi_name, season=season, + method=rename_method, _hash=info.hash ) else: logger.warning(f"{info.name} has no media file") - - -if __name__ == '__main__': - from module.conf import settings, setup_logger - setup_logger() - client = DownloadClient(settings) - renamer = Renamer(client, settings) - save_path = "D:\Videos\Bangumi\我推的孩子\Season 1\[XKsub][Oshi no Ko][01][CHS][1080P][WEBrip][MP4].mp4" - path = renamer.get_file_name(save_path) - print(path) \ No newline at end of file diff --git a/src/module/parser/analyser/torrent_parser.py b/src/module/parser/analyser/torrent_parser.py index 8db2825b..241e8958 100644 --- a/src/module/parser/analyser/torrent_parser.py +++ b/src/module/parser/analyser/torrent_parser.py @@ -116,13 +116,36 @@ def rename_subtitle(info: DownloadInfo): return new_name +def rename_subtitle_advance(info: DownloadInfo): + subtitle_lang = "zh" + break_flag = False + for key, value in SUBTITLE_LANG.items(): + for lang in value: + if lang in info.name: + subtitle_lang = key + break_flag = True + break + if break_flag: + break + for rule in RULES: + match_obj = re.match(rule, info.file_name, re.I) + if match_obj is not None: + new_name = re.sub( + r"[\[\]]", + "", + f"{info.folder_name} S{info.season}E{match_obj.group(2)}.{subtitle_lang}{info.suffix}", + ) + return new_name + + METHODS = { "normal": rename_normal, "pn": rename_pn, "advance": rename_advance, "no_season_pn": rename_no_season_pn, "none": rename_none, - "subtitle": rename_subtitle, + "subtitle_pn": rename_subtitle, + "subtitle_advance": rename_subtitle_advance, } From 1e8a02595b00b90cdfe2d6f5a4178751181d9f7e Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 3 May 2023 20:40:49 +0800 Subject: [PATCH 3/6] Add new domain of mikanani --- src/module/conf/config.py | 3 +++ src/module/models/config.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/module/conf/config.py b/src/module/conf/config.py index 683067e4..b5bd6e12 100644 --- a/src/module/conf/config.py +++ b/src/module/conf/config.py @@ -20,6 +20,9 @@ class Setting(Config): def reload(): load_config_from_file(CONFIG_PATH) + def save(self): + save_config_to_file(self, CONFIG_PATH) + def save_config_to_file(config: Config, path: str): config_dict = config.dict() diff --git a/src/module/models/config.py b/src/module/models/config.py index 1690cafe..b6cc31b5 100644 --- a/src/module/models/config.py +++ b/src/module/models/config.py @@ -22,7 +22,7 @@ class RSSParser(BaseModel): enable: bool = Field(True, description="Enable RSS parser") type: str = Field("mikan", description="RSS parser type") token: str = Field("token", description="RSS parser token") - custom_url: str = Field("mikanani.me", description="Custom RSS host url") + custom_url: str = Field("mikanani.tv", description="Custom RSS host url") enable_tmdb: bool = Field(False, description="Enable TMDB") filter: list[str] = Field(["720", r"\d+-\d"], description="Filter") language: str = "zh" From 20ca72204cb915915a661932585c355142f68fda Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 3 May 2023 21:08:21 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=20EP=20E=20?= =?UTF-8?q?=E7=9A=84=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/parser/analyser/raw_parser.py | 5 ++--- src/test/test_rss_parser.py | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/module/parser/analyser/raw_parser.py b/src/module/parser/analyser/raw_parser.py index 8279f378..68b8eb8f 100644 --- a/src/module/parser/analyser/raw_parser.py +++ b/src/module/parser/analyser/raw_parser.py @@ -1,6 +1,5 @@ import logging import re -from dataclasses import dataclass from module.models import Episode @@ -8,7 +7,7 @@ logger = logging.getLogger(__name__) EPISODE_RE = re.compile(r"\d+") TITLE_RE = re.compile( - r"(.*|\[.*])( -? \d+|\[\d+]|\[\d+.?[vV]\d{1}]|[第]?\d+[话話集]|\[\d+.?END])(.*)" + r"(.*|\[.*])( -? \d+|\[\d+]|\[\d+.?[vV]\d]|[ 第]?\d+[话話集]|\[\d+.?END]|[Ee][Pp]?\d+)(.*)" ) RESOLUTION_RE = re.compile(r"1080|720|2160|4K") SOURCE_RE = re.compile(r"B-Global|[Bb]aha|[Bb]ilibili|AT-X|Web") @@ -81,7 +80,7 @@ def name_process(name: str): name_en, name_zh, name_jp = None, None, None name = name.strip() name = re.sub(r"[((]仅限港澳台地区[))]", "", name) - split = re.split("/|\s{2}|-\s{2}", name) + split = re.split(r"/|\s{2}|-\s{2}", name) while "" in split: split.remove("") if len(split) == 1: diff --git a/src/test/test_rss_parser.py b/src/test/test_rss_parser.py index 3aaf4c6a..a1b5430c 100644 --- a/src/test/test_rss_parser.py +++ b/src/test/test_rss_parser.py @@ -11,4 +11,11 @@ def test_rss_analyser(): assert data.title_raw == "Yamada-kun to Lv999 no Koi wo Suru" assert data.official_title == "和山田谈场 Lv999 的恋爱" - assert data.season == 1 \ No newline at end of file + assert data.season == 1 + + url = "http://dmhy.org/topics/rss/rss.xml?keyword=假面骑士+Geats&sort_id=0&team_id=648&order=date-desc" + data = rss_analyser.rss_to_data(url=url) + + assert data.title_raw == "假面骑士Geats" + assert data.official_title == "假面骑士Geats" + assert data.season == 1 From 1cf28654ad67fbbc3b2892fa873602fc2c6fa780 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Wed, 3 May 2023 21:17:22 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AF=B9=20EP=20E=20?= =?UTF-8?q?=E7=9A=84=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/core/api_func.py | 6 +++--- src/module/models/config.py | 2 +- src/module/parser/analyser/torrent_parser.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/module/core/api_func.py b/src/module/core/api_func.py index 69bc482a..46b841ea 100644 --- a/src/module/core/api_func.py +++ b/src/module/core/api_func.py @@ -86,16 +86,16 @@ class APIProcess: return json_config.load(CONFIG_PATH) def get_rss(self, full_path: str): - url = f"https://mikanani.me/RSS/{full_path}" + url = f"https://mikanime.tv/RSS/{full_path}" custom_url = self._custom_url if "://" not in custom_url: custom_url = f"https://{custom_url}" with RequestContent() as request: content = request.get_html(url) - return re.sub(r"https://mikanani.me", custom_url, content) + return re.sub(r"https://mikanime.tv", custom_url, content) @staticmethod def get_torrent(full_path): - url = f"https://mikanani.me/Download/{full_path}" + url = f"https://mikanime.tv/Download/{full_path}" with RequestContent() as request: return request.get_content(url) diff --git a/src/module/models/config.py b/src/module/models/config.py index b6cc31b5..d591160f 100644 --- a/src/module/models/config.py +++ b/src/module/models/config.py @@ -22,7 +22,7 @@ class RSSParser(BaseModel): enable: bool = Field(True, description="Enable RSS parser") type: str = Field("mikan", description="RSS parser type") token: str = Field("token", description="RSS parser token") - custom_url: str = Field("mikanani.tv", description="Custom RSS host url") + custom_url: str = Field("mikanime.tv", description="Custom RSS host url") enable_tmdb: bool = Field(False, description="Enable TMDB") filter: list[str] = Field(["720", r"\d+-\d"], description="Filter") language: str = "zh" diff --git a/src/module/parser/analyser/torrent_parser.py b/src/module/parser/analyser/torrent_parser.py index 241e8958..096bd0f1 100644 --- a/src/module/parser/analyser/torrent_parser.py +++ b/src/module/parser/analyser/torrent_parser.py @@ -19,7 +19,7 @@ RULES = [ r"(.*)[\[ E](\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?: )?(?:END)?[\] ](.*)", r"(.*)\[(?:第)?(\d*\.*\d*)[话集話](?:END)?\](.*)", r"(.*)第(\d*\.*\d*)[话話集](?:END)?(.*)", - r"(.*)E(\d{1,4})(.*)", + r"(.*)EP?(\d{1,4})(.*)", ] SUBTITLE_LANG = { From 1734d8a37869cdba5d93cab6df1cb177a92700c4 Mon Sep 17 00:00:00 2001 From: EstrellaXD Date: Thu, 4 May 2023 12:18:22 +0800 Subject: [PATCH 6/6] =?UTF-8?q?Fix=20renamer=20=E4=B8=8D=E8=83=BD=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D1000=E9=9B=86=E4=BB=A5=E4=B8=8A=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/module/downloader/qb_downloader.py | 2 +- src/module/parser/analyser/torrent_parser.py | 11 +++++++++-- src/test/test_raw_parser.py | 9 +++++++++ src/test/test_torrent_parser.py | 16 +++++++++++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/module/downloader/qb_downloader.py b/src/module/downloader/qb_downloader.py index 9074c916..ecb12693 100644 --- a/src/module/downloader/qb_downloader.py +++ b/src/module/downloader/qb_downloader.py @@ -58,7 +58,7 @@ class QbDownloader: def torrents_delete(self, hash): return self._client.torrents_delete( - delete_files=False, + delete_files=True, torrent_hashes=hash ) diff --git a/src/module/parser/analyser/torrent_parser.py b/src/module/parser/analyser/torrent_parser.py index 096bd0f1..a54dc7e7 100644 --- a/src/module/parser/analyser/torrent_parser.py +++ b/src/module/parser/analyser/torrent_parser.py @@ -16,10 +16,10 @@ class DownloadInfo: RULES = [ r"(.*) - (\d{1,4}|\d{1,4}\.\d{1,2})(?:v\d{1,2})?(?: )?(?:END)?(.*)", - r"(.*)[\[ E](\d{1,3}|\d{1,3}\.\d{1,2})(?:v\d{1,2})?(?: )?(?:END)?[\] ](.*)", + r"(.*)[\[\ E](\d{1,4}|\d{1,4}\.\d{1,2})(?:v\d{1,2})?(?: )?(?:END)?[\]\ ](.*)", r"(.*)\[(?:第)?(\d*\.*\d*)[话集話](?:END)?\](.*)", r"(.*)第(\d*\.*\d*)[话話集](?:END)?(.*)", - r"(.*)EP?(\d{1,4})(.*)", + r"(.*)(?