Merge branch '3.0-dev' into 3.1-dev

# Conflicts:
#	backend/src/module/checker/checker.py
#	backend/src/module/database/bangumi.py
#	backend/src/module/notification/notification.py
#	backend/src/module/notification/plugin/bark.py
#	backend/src/module/parser/analyser/tmdb_parser.py
This commit is contained in:
EstrellaXD
2023-06-13 22:02:48 +08:00
16 changed files with 177 additions and 160 deletions

View File

@@ -179,3 +179,8 @@ def raw_parser(raw: str) -> Episode | None:
return Episode(
name_en, name_zh, name_jp, season, sr, episode, sub, group, dpi, source
)
if __name__ == '__main__':
title = "[动漫国字幕组&LoliHouse] THE MARGINAL SERVICE - 08 [WebRip 1080p HEVC-10bit AAC][简繁内封字幕]"
print(raw_parser(title))

View File

@@ -2,8 +2,8 @@ import re
import time
from dataclasses import dataclass
from module.conf import TMDB_API
from module.network import RequestContent
from module.conf import TMDB_API
@dataclass
@@ -16,15 +16,16 @@ class TMDBInfo:
year: str
LANGUAGE = {"zh": "zh-CN", "jp": "ja-JP", "en": "en-US"}
LANGUAGE = {
"zh": "zh-CN",
"jp": "ja-JP",
"en": "en-US"
}
def search_url(e):
return f"https://api.themoviedb.org/3/search/tv?api_key={TMDB_API}&page=1&query={e}&include_adult=false"
def info_url(e, key):
return f"https://api.themoviedb.org/3/tv/{e}?api_key={TMDB_API}&language={LANGUAGE[key]}"
search_url = lambda e: \
f"https://api.themoviedb.org/3/search/tv?api_key={TMDB_API}&page=1&query={e}&include_adult=false"
info_url = lambda e, key: \
f"https://api.themoviedb.org/3/tv/{e}?api_key={TMDB_API}&language={LANGUAGE[key]}"
def is_animation(tv_id, language) -> bool:
@@ -38,10 +39,11 @@ def is_animation(tv_id, language) -> bool:
def get_season(seasons: list) -> int:
for season in seasons:
ss = sorted(seasons, key=lambda e: e.get("air_date"), reverse=True)
for season in ss:
if re.search(r"\d 季", season.get("season")) is not None:
date = season.get("air_date").split("-")
[year, _, _] = date
[year, _ , _] = date
now_year = time.localtime().tm_year
if int(year) <= now_year:
return int(re.findall(r"\d", season.get("season"))[0])
@@ -62,30 +64,16 @@ def tmdb_parser(title, language) -> TMDBInfo | None:
break
url_info = info_url(id, language)
info_content = req.get_json(url_info)
season = [
{
"season": s.get("name"),
"air_date": s.get("air_date"),
"poster_path": s.get("poster_path"),
}
for s in info_content.get("seasons")
]
season = [{"season": s.get("name"), "air_date": s.get("air_date"), "poster_path": s.get("poster_path")} for s in info_content.get("seasons")]
last_season = get_season(season)
original_title = info_content.get("original_name")
official_title = info_content.get("name")
year_number = info_content.get("first_air_date").split("-")[0]
return TMDBInfo(
id,
official_title,
original_title,
season,
last_season,
str(year_number),
)
return TMDBInfo(id, official_title, original_title, season, last_season, str(year_number))
else:
return None
if __name__ == '__main__':
title = "鬼灭之刃"
print(tmdb_parser(title, "zh"))
title = "海盗战记"
print(tmdb_parser(title, "zh").last_season)

View File

@@ -13,13 +13,13 @@ RULES = [
r"(.*) - (\d{1,4}(?!\d|p)|\d{1,4}\.\d{1,2}(?!\d|p))(?: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"(.*)第?(\d*\.*\d*)[话話集](?:END)?(.*)",
r"(.*)(?:S\d{2})?EP?(\d+)(.*)",
]
SUBTITLE_LANG = {
"zh-tw": ["TC", "CHT", "cht", "", "zh-tw"],
"zh": ["SC", "CHS", "chs", "", "zh"],
"zh-tw": ["tc", "cht", "", "zh-tw"],
"zh": ["sc", "chs", "", "zh"],
}
@@ -54,7 +54,7 @@ def get_season_and_title(season_and_title) -> tuple[str, int]:
def get_subtitle_lang(subtitle_name: str) -> str:
for key, value in SUBTITLE_LANG.items():
for v in value:
if v in subtitle_name:
if v in subtitle_name.lower():
return key

View File

@@ -49,7 +49,16 @@ class TitleParser:
"jp": episode.title_jp,
}
title_raw = episode.title_en if episode.title_en else episode.title_zh
official_title = titles[language] if titles[language] else titles["zh"]
if titles[language]:
official_title = titles[language]
elif titles["zh"]:
official_title = titles["zh"]
elif titles["en"]:
official_title = titles["en"]
elif titles["jp"]:
official_title = titles["jp"]
else:
official_title = title_raw
_season = episode.season
data = BangumiData(
official_title=official_title,