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/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/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/manager/renamer.py b/src/module/manager/renamer.py index 8c49d06b..0c8db6c8 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, @@ -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 = subtitle_path.split(os.path.sep)[-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, @@ -129,7 +131,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 +144,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 @@ -165,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: @@ -181,26 +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) - 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 diff --git a/src/module/models/config.py b/src/module/models/config.py index 1690cafe..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.me", 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/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/module/parser/analyser/torrent_parser.py b/src/module/parser/analyser/torrent_parser.py index 8db2825b..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"(.*)E(\d{1,4})(.*)", + r"(.*)(?