mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-14 02:20:53 +08:00
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
@@ -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"
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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"(.*)(?<!\w)EP?(\d+)(?!\w)(.*)",
|
||||
]
|
||||
|
||||
SUBTITLE_LANG = {
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
|
||||
@@ -136,3 +159,10 @@ def torrent_parser(
|
||||
info = rename_init(file_name, folder_name, season, suffix)
|
||||
return METHODS[method.lower()](info)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
title = "[MagicStar] 假面骑士Geats / 仮面ライダーギーツ EP33 [WEBDL] [1080p] [TTFC]【生】"
|
||||
folder_name = "名侦探柯南"
|
||||
season = 1
|
||||
suffix = ".mp4"
|
||||
print(torrent_parser(title, folder_name, season, suffix, method="pn"))
|
||||
@@ -50,3 +50,12 @@ def test_raw_parser():
|
||||
assert info.resolution == "1080P"
|
||||
assert info.episode == 2
|
||||
assert info.season == 1
|
||||
|
||||
content = "[MagicStar] 假面骑士Geats / 仮面ライダーギーツ EP33 [WEBDL] [1080p] [TTFC]【生】"
|
||||
info = raw_parser(content)
|
||||
assert info.group == "MagicStar"
|
||||
assert info.title_zh == "假面骑士Geats"
|
||||
assert info.title_jp == "仮面ライダーギーツ"
|
||||
assert info.resolution == "1080p"
|
||||
assert info.episode == 33
|
||||
assert info.season == 1
|
||||
|
||||
@@ -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
|
||||
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
|
||||
|
||||
@@ -23,4 +23,18 @@ def test_torrent_parser():
|
||||
season = 1
|
||||
suffix = ".mkv"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "pn") == "Heavenly Delusion S01E01.mkv"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "天国大魔境(2023) S01E01.mkv"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "天国大魔境(2023) S01E01.mkv"
|
||||
|
||||
file_name = "[SBSUB][Kanojo mo Kanojo][01][GB][1080P](456E234).mp4"
|
||||
folder_name = "女友也要有"
|
||||
season = 1
|
||||
suffix = ".mp4"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "pn") == "Kanojo mo Kanojo S01E01.mp4"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "女友也要有 S01E01.mp4"
|
||||
|
||||
file_name = "[SBSUB][CONAN][1082][V2][1080P][AVC_AAC][CHS_JP](C1E4E331).mp4"
|
||||
folder_name = "名侦探柯南(1996)"
|
||||
season = 1
|
||||
suffix = ".mp4"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "pn") == "CONAN S01E1082.mp4"
|
||||
assert torrent_parser(file_name, folder_name, season, suffix, "advance") == "名侦探柯南(1996) S01E1082.mp4"
|
||||
Reference in New Issue
Block a user