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 pathlib import Path
|
||||||
from typing import List, Optional, Tuple, Union
|
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.apiv2 import DoubanApi
|
||||||
from app.modules.douban.scraper import DoubanScraper
|
from app.modules.douban.scraper import DoubanScraper
|
||||||
from app.schemas.types import MediaType
|
from app.schemas.types import MediaType
|
||||||
|
from app.utils.common import retry
|
||||||
from app.utils.system import SystemUtils
|
from app.utils.system import SystemUtils
|
||||||
|
|
||||||
|
|
||||||
@ -393,6 +395,7 @@ class DoubanModule(_ModuleBase):
|
|||||||
|
|
||||||
return ret_medias
|
return ret_medias
|
||||||
|
|
||||||
|
@retry(Exception, 5, 3, 3, logger=logger)
|
||||||
def match_doubaninfo(self, name: str, mtype: str = None,
|
def match_doubaninfo(self, name: str, mtype: str = None,
|
||||||
year: str = None, season: int = None) -> dict:
|
year: str = None, season: int = None) -> dict:
|
||||||
"""
|
"""
|
||||||
@ -402,9 +405,15 @@ class DoubanModule(_ModuleBase):
|
|||||||
:param year: 年份
|
:param year: 年份
|
||||||
:param season: 季号
|
: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:
|
if not result:
|
||||||
|
logger.warn(f"未找到 {name} 的豆瓣信息")
|
||||||
return {}
|
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"):
|
for item_obj in result.get("items"):
|
||||||
type_name = item_obj.get("type_name")
|
type_name = item_obj.get("type_name")
|
||||||
if type_name not in [MediaType.TV.value, MediaType.MOVIE.value]:
|
if type_name not in [MediaType.TV.value, MediaType.MOVIE.value]:
|
||||||
|
@ -173,7 +173,7 @@ class DoubanApi(metaclass=Singleton):
|
|||||||
|
|
||||||
ts = params.pop(
|
ts = params.pop(
|
||||||
'_ts',
|
'_ts',
|
||||||
int(datetime.strftime(datetime.now(), '%Y%m%d'))
|
datetime.strftime(datetime.now(), '%Y%m%d')
|
||||||
)
|
)
|
||||||
params.update({
|
params.update({
|
||||||
'os_rom': 'android',
|
'os_rom': 'android',
|
||||||
@ -185,6 +185,8 @@ class DoubanApi(metaclass=Singleton):
|
|||||||
ua=choice(self._user_agents),
|
ua=choice(self._user_agents),
|
||||||
session=self._session
|
session=self._session
|
||||||
).get_res(url=req_url, params=params)
|
).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 {}
|
return resp.json() if resp else {}
|
||||||
|
|
||||||
def search(self, keyword, start=0, count=20,
|
def search(self, keyword, start=0, count=20,
|
||||||
|
@ -307,11 +307,55 @@ class PersonMeta(_PluginBase):
|
|||||||
logger.info(f"媒体库 {library.name} 的演员信息刮削完成")
|
logger.info(f"媒体库 {library.name} 的演员信息刮削完成")
|
||||||
logger.info(f"服务器 {server} 的演员信息刮削完成")
|
logger.info(f"服务器 {server} 的演员信息刮削完成")
|
||||||
|
|
||||||
|
def __update_peoples(self, server: str, itemid: str, iteminfo: dict, douban_actors):
|
||||||
|
# 处理媒体项中的人物信息
|
||||||
|
"""
|
||||||
|
"People": [
|
||||||
|
{
|
||||||
|
"Name": "丹尼尔·克雷格",
|
||||||
|
"Id": "33625",
|
||||||
|
"Role": "James Bond",
|
||||||
|
"Type": "Actor",
|
||||||
|
"PrimaryImageTag": "bef4f764540f10577f804201d8d27918"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
peoples = []
|
||||||
|
# 更新当前媒体项人物
|
||||||
|
for people in iteminfo["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,
|
||||||
|
douban_actors=douban_actors)
|
||||||
|
if info:
|
||||||
|
peoples.append(info)
|
||||||
|
elif not self._remove_nozh:
|
||||||
|
peoples.append(people)
|
||||||
|
# 保存媒体项信息
|
||||||
|
if peoples:
|
||||||
|
iteminfo["People"] = peoples
|
||||||
|
self.set_iteminfo(server=server, itemid=itemid, iteminfo=iteminfo)
|
||||||
|
|
||||||
def __update_item(self, server: str, item: MediaServerItem,
|
def __update_item(self, server: str, item: MediaServerItem,
|
||||||
mediainfo: MediaInfo = None, season: int = None):
|
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 mediainfo:
|
||||||
if not item.tmdbid:
|
if not item.tmdbid:
|
||||||
@ -323,49 +367,19 @@ class PersonMeta(_PluginBase):
|
|||||||
logger.warn(f"{item.title} 未识别到媒体信息")
|
logger.warn(f"{item.title} 未识别到媒体信息")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 获取豆瓣演员信息
|
|
||||||
douban_actors = self.__get_douban_actors(mediainfo=mediainfo, season=season)
|
|
||||||
|
|
||||||
# 获取媒体项
|
# 获取媒体项
|
||||||
iteminfo = self.get_iteminfo(server=server, itemid=item.item_id)
|
iteminfo = self.get_iteminfo(server=server, itemid=item.item_id)
|
||||||
if not iteminfo:
|
if not iteminfo:
|
||||||
logger.warn(f"{item.title} 未找到媒体项")
|
logger.warn(f"{item.title} 未找到媒体项")
|
||||||
return
|
return
|
||||||
|
|
||||||
# 处理媒体项中的人物信息
|
if __need_trans_actor(iteminfo):
|
||||||
if iteminfo.get("People"):
|
# 获取豆瓣演员信息
|
||||||
"""
|
logger.info(f"开始获取 {item.title} 的豆瓣演员信息 ...")
|
||||||
"People": [
|
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)
|
||||||
"Name": "丹尼尔·克雷格",
|
else:
|
||||||
"Id": "33625",
|
logger.info(f"{item.title} 的人物信息已是中文,无需更新")
|
||||||
"Role": "James Bond",
|
|
||||||
"Type": "Actor",
|
|
||||||
"PrimaryImageTag": "bef4f764540f10577f804201d8d27918"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
"""
|
|
||||||
peoples = []
|
|
||||||
# 更新当前媒体项人物
|
|
||||||
for people in iteminfo["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,
|
|
||||||
douban_actors=douban_actors)
|
|
||||||
if info:
|
|
||||||
peoples.append(info)
|
|
||||||
elif not self._remove_nozh:
|
|
||||||
peoples.append(people)
|
|
||||||
# 保存媒体项信息
|
|
||||||
if peoples:
|
|
||||||
iteminfo["People"] = peoples
|
|
||||||
self.set_iteminfo(server=server, itemid=item.item_id, iteminfo=iteminfo)
|
|
||||||
|
|
||||||
# 处理季和集人物
|
# 处理季和集人物
|
||||||
if iteminfo.get("Type") and "Series" in iteminfo["Type"]:
|
if iteminfo.get("Type") and "Series" in iteminfo["Type"]:
|
||||||
@ -383,31 +397,14 @@ class PersonMeta(_PluginBase):
|
|||||||
if not seasoninfo:
|
if not seasoninfo:
|
||||||
logger.warn(f"{item.title} 未找到季媒体项:{season.get('Id')}")
|
logger.warn(f"{item.title} 未找到季媒体项:{season.get('Id')}")
|
||||||
continue
|
continue
|
||||||
# 更新季媒体项人物
|
|
||||||
peoples = []
|
if __need_trans_actor(seasoninfo):
|
||||||
if seasoninfo.get("People"):
|
# 更新季媒体项人物
|
||||||
logger.info(f"开始更新季 {seasoninfo.get('Id')} 的人物信息 ...")
|
self.__update_peoples(server=server, itemid=season.get("Id"), iteminfo=seasoninfo,
|
||||||
for people in seasoninfo["People"]:
|
douban_actors=season_actors)
|
||||||
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,
|
|
||||||
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')} 的人物信息更新完成")
|
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")
|
episodes = self.get_items(server=server, parentid=season.get("Id"), mtype="Episode")
|
||||||
if not episodes:
|
if not episodes:
|
||||||
@ -420,31 +417,13 @@ class PersonMeta(_PluginBase):
|
|||||||
if not episodeinfo:
|
if not episodeinfo:
|
||||||
logger.warn(f"{item.title} 未找到集媒体项:{episode.get('Id')}")
|
logger.warn(f"{item.title} 未找到集媒体项:{episode.get('Id')}")
|
||||||
continue
|
continue
|
||||||
# 更新集媒体项人物
|
if __need_trans_actor(episodeinfo):
|
||||||
if episodeinfo.get("People"):
|
# 更新集媒体项人物
|
||||||
logger.info(f"开始更新集 {episodeinfo.get('Id')} 的人物信息 ...")
|
self.__update_peoples(server=server, itemid=episode.get("Id"), iteminfo=episodeinfo,
|
||||||
peoples = []
|
douban_actors=season_actors)
|
||||||
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,
|
|
||||||
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')} 的人物信息更新完成")
|
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]:
|
def __update_people(self, server: str, people: dict, douban_actors: list = None) -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
@ -587,6 +566,8 @@ class PersonMeta(_PluginBase):
|
|||||||
if doubaninfo:
|
if doubaninfo:
|
||||||
doubanitem = self.chain.douban_info(doubaninfo.get("id")) or {}
|
doubanitem = self.chain.douban_info(doubaninfo.get("id")) or {}
|
||||||
return (doubanitem.get("actors") or []) + (doubanitem.get("directors") or [])
|
return (doubanitem.get("actors") or []) + (doubanitem.get("directors") or [])
|
||||||
|
else:
|
||||||
|
logger.warn(f"未找到豆瓣信息:{mediainfo.title_year}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
Loading…
x
Reference in New Issue
Block a user