Finished new version of rss parser.

This commit is contained in:
EstrellaXD
2023-05-09 15:34:58 +08:00
parent 3ac4381e31
commit f4469bf892
9 changed files with 154 additions and 270 deletions

View File

@@ -1,15 +1,16 @@
import logging
from .analyser import raw_parser, torrent_parser, TMDBMatcher
from .analyser import raw_parser, torrent_parser, tmdb_parser
from module.models import BangumiData, Config
from module.models import BangumiData
from module.conf import settings
logger = logging.getLogger(__name__)
class TitleParser:
def __init__(self):
self._tmdb_parser = TMDBMatcher()
pass
@staticmethod
def torrent_parser(
@@ -18,25 +19,22 @@ class TitleParser:
):
return torrent_parser(torrent_path, season)
def tmdb_parser(self, title: str, season: int, language: str):
official_title, tmdb_season = None, None
try:
tmdb_info = self._tmdb_parser.tmdb_search(title)
logger.debug(f"TMDB Matched, official title is {tmdb_info.title_zh}")
except Exception as e:
logger.debug(e)
logger.warning(f"{title} can not Matched with TMDB")
logger.info("Please change the bangumi info in webui")
return title, season
if language == "zh":
official_title = f"{tmdb_info.title_zh} ({tmdb_info.year_number})"
elif language == "jp":
official_title = f"{tmdb_info.title_jp} ({tmdb_info.year_number})"
tmdb_season = tmdb_info.last_season if tmdb_info.last_season else season
official_title = official_title if official_title else title
return official_title, tmdb_season
@staticmethod
def tmdb_parser(title: str, season: int, language: str):
official_title, tmdb_season, year = title, season, None
tmdb_info = tmdb_parser(title, language)
if tmdb_info:
logger.debug(f"TMDB Matched, official title is {tmdb_info.title}")
tmdb_season = tmdb_info.last_season if tmdb_info.last_season else season
official_title = tmdb_info.title
year = tmdb_info.year
else:
logger.warning(f"Cannot match {title} in TMDB. Use raw title instead.")
logger.warning("Please change bangumi info manually.")
return official_title, tmdb_season, year
def raw_parser(self, raw: str, rss_link: str, settings: Config, _id: int = 0) -> BangumiData:
@staticmethod
def raw_parser(raw: str, rss_link: str, _id: int = 0) -> BangumiData:
language = settings.rss_parser.language
try:
episode = raw_parser(raw)
@@ -45,7 +43,6 @@ class TitleParser:
"en": episode.title_en,
"jp": episode.title_jp,
}
title_search = episode.title_zh if episode.title_zh else episode.title_en
title_raw = episode.title_en if episode.title_en else episode.title_zh
official_title = titles[language] if titles[language] else titles["zh"]
_season = episode.season
@@ -59,13 +56,13 @@ class TitleParser:
dpi=episode.resolution,
source=episode.source,
subtitle=episode.sub,
eps_collect=True if episode.episode > 1 else False,
eps_collect=False if episode.episode > 1 else True,
offset=0,
filter=settings.rss_parser.filter,
rss_link=[rss_link],
)
logger.debug(f"RAW:{raw} >> {episode.title_en}")
logger.debug(f"RAW:{raw} >> {title_raw}")
return data
except Exception as e:
logger.debug(e)
print(e)
logger.warning(f"Cannot parse {raw}.")