Merge pull request #757 from lightolly/dev/20231008
This commit is contained in:
commit
d7f4ed069c
@ -1,3 +1,4 @@
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import List, Optional, Tuple, Union
|
||||
|
||||
@ -10,6 +11,7 @@ from app.modules import _ModuleBase
|
||||
from app.modules.douban.apiv2 import DoubanApi
|
||||
from app.modules.douban.scraper import DoubanScraper
|
||||
from app.schemas.types import MediaType
|
||||
from app.utils.common import retry
|
||||
from app.utils.system import SystemUtils
|
||||
|
||||
|
||||
@ -393,6 +395,7 @@ class DoubanModule(_ModuleBase):
|
||||
|
||||
return ret_medias
|
||||
|
||||
@retry(Exception, 5, 3, 3, logger=logger)
|
||||
def match_doubaninfo(self, name: str, mtype: str = None,
|
||||
year: str = None, season: int = None) -> dict:
|
||||
"""
|
||||
@ -402,9 +405,15 @@ class DoubanModule(_ModuleBase):
|
||||
:param year: 年份
|
||||
:param season: 季号
|
||||
"""
|
||||
result = self.doubanapi.search(f"{name} {year or ''}".strip())
|
||||
result = self.doubanapi.search(f"{name} {year or ''}".strip(),
|
||||
ts=datetime.strftime(datetime.now(), '%Y%m%d%H%M%S'))
|
||||
if not result:
|
||||
logger.warn(f"未找到 {name} 的豆瓣信息")
|
||||
return {}
|
||||
# 触发rate limit
|
||||
if "search_access_rate_limit" in result.values():
|
||||
logger.warn(f"触发豆瓣API速率限制 错误信息 {result} ...")
|
||||
raise Exception("触发豆瓣API速率限制")
|
||||
for item_obj in result.get("items"):
|
||||
type_name = item_obj.get("type_name")
|
||||
if type_name not in [MediaType.TV.value, MediaType.MOVIE.value]:
|
||||
|
@ -173,7 +173,7 @@ class DoubanApi(metaclass=Singleton):
|
||||
|
||||
ts = params.pop(
|
||||
'_ts',
|
||||
int(datetime.strftime(datetime.now(), '%Y%m%d'))
|
||||
datetime.strftime(datetime.now(), '%Y%m%d')
|
||||
)
|
||||
params.update({
|
||||
'os_rom': 'android',
|
||||
@ -185,6 +185,8 @@ class DoubanApi(metaclass=Singleton):
|
||||
ua=choice(self._user_agents),
|
||||
session=self._session
|
||||
).get_res(url=req_url, params=params)
|
||||
if resp.status_code == 400 and "rate_limit" in resp.text:
|
||||
return resp.json()
|
||||
return resp.json() if resp else {}
|
||||
|
||||
def search(self, keyword, start=0, count=20,
|
||||
|
@ -307,33 +307,8 @@ class PersonMeta(_PluginBase):
|
||||
logger.info(f"媒体库 {library.name} 的演员信息刮削完成")
|
||||
logger.info(f"服务器 {server} 的演员信息刮削完成")
|
||||
|
||||
def __update_item(self, server: str, item: MediaServerItem,
|
||||
mediainfo: MediaInfo = None, season: int = None):
|
||||
"""
|
||||
更新媒体服务器中的条目
|
||||
"""
|
||||
# 识别媒体信息
|
||||
if not mediainfo:
|
||||
if not item.tmdbid:
|
||||
logger.warn(f"{item.title} 未找到tmdbid,无法识别媒体信息")
|
||||
return
|
||||
mtype = MediaType.TV if item.item_type in ['Series', 'show'] else MediaType.MOVIE
|
||||
mediainfo = self.chain.recognize_media(mtype=mtype, tmdbid=item.tmdbid)
|
||||
if not mediainfo:
|
||||
logger.warn(f"{item.title} 未识别到媒体信息")
|
||||
return
|
||||
|
||||
# 获取豆瓣演员信息
|
||||
douban_actors = self.__get_douban_actors(mediainfo=mediainfo, season=season)
|
||||
|
||||
# 获取媒体项
|
||||
iteminfo = self.get_iteminfo(server=server, itemid=item.item_id)
|
||||
if not iteminfo:
|
||||
logger.warn(f"{item.title} 未找到媒体项")
|
||||
return
|
||||
|
||||
def __update_peoples(self, server: str, itemid: str, iteminfo: dict, douban_actors):
|
||||
# 处理媒体项中的人物信息
|
||||
if iteminfo.get("People"):
|
||||
"""
|
||||
"People": [
|
||||
{
|
||||
@ -365,7 +340,46 @@ class PersonMeta(_PluginBase):
|
||||
# 保存媒体项信息
|
||||
if peoples:
|
||||
iteminfo["People"] = peoples
|
||||
self.set_iteminfo(server=server, itemid=item.item_id, iteminfo=iteminfo)
|
||||
self.set_iteminfo(server=server, itemid=itemid, iteminfo=iteminfo)
|
||||
|
||||
def __update_item(self, server: str, item: MediaServerItem,
|
||||
mediainfo: MediaInfo = None, season: int = None):
|
||||
"""
|
||||
更新媒体服务器中的条目
|
||||
"""
|
||||
|
||||
def __need_trans_actor(_item):
|
||||
# 是否需要处理人物信息
|
||||
_peoples = [x for x in _item.get("People", []) if
|
||||
x.get("Name") and not StringUtils.is_chinese(x.get("Name"))]
|
||||
if _peoples:
|
||||
return True
|
||||
return False
|
||||
|
||||
# 识别媒体信息
|
||||
if not mediainfo:
|
||||
if not item.tmdbid:
|
||||
logger.warn(f"{item.title} 未找到tmdbid,无法识别媒体信息")
|
||||
return
|
||||
mtype = MediaType.TV if item.item_type in ['Series', 'show'] else MediaType.MOVIE
|
||||
mediainfo = self.chain.recognize_media(mtype=mtype, tmdbid=item.tmdbid)
|
||||
if not mediainfo:
|
||||
logger.warn(f"{item.title} 未识别到媒体信息")
|
||||
return
|
||||
|
||||
# 获取媒体项
|
||||
iteminfo = self.get_iteminfo(server=server, itemid=item.item_id)
|
||||
if not iteminfo:
|
||||
logger.warn(f"{item.title} 未找到媒体项")
|
||||
return
|
||||
|
||||
if __need_trans_actor(iteminfo):
|
||||
# 获取豆瓣演员信息
|
||||
logger.info(f"开始获取 {item.title} 的豆瓣演员信息 ...")
|
||||
douban_actors = self.__get_douban_actors(mediainfo=mediainfo, season=season)
|
||||
self.__update_peoples(server=server, itemid=item.item_id, iteminfo=iteminfo, douban_actors=douban_actors)
|
||||
else:
|
||||
logger.info(f"{item.title} 的人物信息已是中文,无需更新")
|
||||
|
||||
# 处理季和集人物
|
||||
if iteminfo.get("Type") and "Series" in iteminfo["Type"]:
|
||||
@ -383,31 +397,14 @@ class PersonMeta(_PluginBase):
|
||||
if not seasoninfo:
|
||||
logger.warn(f"{item.title} 未找到季媒体项:{season.get('Id')}")
|
||||
continue
|
||||
|
||||
if __need_trans_actor(seasoninfo):
|
||||
# 更新季媒体项人物
|
||||
peoples = []
|
||||
if seasoninfo.get("People"):
|
||||
logger.info(f"开始更新季 {seasoninfo.get('Id')} 的人物信息 ...")
|
||||
for people in seasoninfo["People"]:
|
||||
if not people.get("Name"):
|
||||
continue
|
||||
if StringUtils.is_chinese(people.get("Name")):
|
||||
peoples.append(people)
|
||||
continue
|
||||
if self._event.is_set():
|
||||
logger.info(f"演职人员刮削服务停止")
|
||||
return
|
||||
# 更新人物信息
|
||||
info = self.__update_people(server=server, people=people,
|
||||
self.__update_peoples(server=server, itemid=season.get("Id"), iteminfo=seasoninfo,
|
||||
douban_actors=season_actors)
|
||||
if info:
|
||||
peoples.append(info)
|
||||
elif not self._remove_nozh:
|
||||
peoples.append(people)
|
||||
# 保存季媒体项信息
|
||||
if peoples:
|
||||
seasoninfo["People"] = peoples
|
||||
self.set_iteminfo(server=server, itemid=season.get("Id"), iteminfo=seasoninfo)
|
||||
logger.info(f"季 {seasoninfo.get('Id')} 的人物信息更新完成")
|
||||
else:
|
||||
logger.info(f"季 {seasoninfo.get('Id')} 的人物信息已是中文,无需更新")
|
||||
# 获取集媒体项
|
||||
episodes = self.get_items(server=server, parentid=season.get("Id"), mtype="Episode")
|
||||
if not episodes:
|
||||
@ -420,31 +417,13 @@ class PersonMeta(_PluginBase):
|
||||
if not episodeinfo:
|
||||
logger.warn(f"{item.title} 未找到集媒体项:{episode.get('Id')}")
|
||||
continue
|
||||
if __need_trans_actor(episodeinfo):
|
||||
# 更新集媒体项人物
|
||||
if episodeinfo.get("People"):
|
||||
logger.info(f"开始更新集 {episodeinfo.get('Id')} 的人物信息 ...")
|
||||
peoples = []
|
||||
for people in episodeinfo["People"]:
|
||||
if not people.get("Name"):
|
||||
continue
|
||||
if StringUtils.is_chinese(people.get("Name")):
|
||||
peoples.append(people)
|
||||
continue
|
||||
if self._event.is_set():
|
||||
logger.info(f"演职人员刮削服务停止")
|
||||
return
|
||||
# 更新人物信息
|
||||
info = self.__update_people(server=server, people=people,
|
||||
self.__update_peoples(server=server, itemid=episode.get("Id"), iteminfo=episodeinfo,
|
||||
douban_actors=season_actors)
|
||||
if info:
|
||||
peoples.append(info)
|
||||
elif not self._remove_nozh:
|
||||
peoples.append(people)
|
||||
# 保存集媒体项信息
|
||||
if peoples:
|
||||
episodeinfo["People"] = peoples
|
||||
self.set_iteminfo(server=server, itemid=episode.get("Id"), iteminfo=episodeinfo)
|
||||
logger.info(f"集 {episodeinfo.get('Id')} 的人物信息更新完成")
|
||||
else:
|
||||
logger.info(f"集 {episodeinfo.get('Id')} 的人物信息已是中文,无需更新")
|
||||
|
||||
def __update_people(self, server: str, people: dict, douban_actors: list = None) -> Optional[dict]:
|
||||
"""
|
||||
@ -587,6 +566,8 @@ class PersonMeta(_PluginBase):
|
||||
if doubaninfo:
|
||||
doubanitem = self.chain.douban_info(doubaninfo.get("id")) or {}
|
||||
return (doubanitem.get("actors") or []) + (doubanitem.get("directors") or [])
|
||||
else:
|
||||
logger.warn(f"未找到豆瓣信息:{mediainfo.title_year}")
|
||||
return []
|
||||
|
||||
@staticmethod
|
||||
|
Loading…
x
Reference in New Issue
Block a user