mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
Merge pull request #3824 from cddjr/feat_tmdb_content_rating
This commit is contained in:
@@ -262,6 +262,8 @@ class MediaInfo:
|
|||||||
runtime: int = None
|
runtime: int = None
|
||||||
# 下一集
|
# 下一集
|
||||||
next_episode_to_air: dict = field(default_factory=dict)
|
next_episode_to_air: dict = field(default_factory=dict)
|
||||||
|
# 内容分级
|
||||||
|
content_rating: str = None
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
# 设置媒体信息
|
# 设置媒体信息
|
||||||
|
|||||||
@@ -170,6 +170,9 @@ class TmdbScraper:
|
|||||||
DomUtils.add_node(doc, root, "genre", genre.get("name") or "")
|
DomUtils.add_node(doc, root, "genre", genre.get("name") or "")
|
||||||
# 评分
|
# 评分
|
||||||
DomUtils.add_node(doc, root, "rating", mediainfo.vote_average or "0")
|
DomUtils.add_node(doc, root, "rating", mediainfo.vote_average or "0")
|
||||||
|
# 内容分级
|
||||||
|
if content_rating := mediainfo.content_rating:
|
||||||
|
DomUtils.add_node(doc, root, "mpaa", content_rating)
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|||||||
@@ -601,6 +601,8 @@ class TmdbApi:
|
|||||||
tmdb_info['genre_ids'] = __get_genre_ids(tmdb_info.get('genres'))
|
tmdb_info['genre_ids'] = __get_genre_ids(tmdb_info.get('genres'))
|
||||||
# 别名和译名
|
# 别名和译名
|
||||||
tmdb_info['names'] = self.__get_names(tmdb_info)
|
tmdb_info['names'] = self.__get_names(tmdb_info)
|
||||||
|
# 内容分级
|
||||||
|
tmdb_info['content_rating'] = self.__get_content_rating(tmdb_info)
|
||||||
# 转换多语种标题
|
# 转换多语种标题
|
||||||
self.__update_tmdbinfo_extra_title(tmdb_info)
|
self.__update_tmdbinfo_extra_title(tmdb_info)
|
||||||
# 转换中文标题
|
# 转换中文标题
|
||||||
@@ -608,6 +610,68 @@ class TmdbApi:
|
|||||||
|
|
||||||
return tmdb_info
|
return tmdb_info
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __get_content_rating(tmdb_info: dict) -> Optional[str]:
|
||||||
|
"""
|
||||||
|
获得tmdb中的内容评级
|
||||||
|
:param tmdb_info: TMDB信息
|
||||||
|
:return: 内容评级
|
||||||
|
"""
|
||||||
|
if not tmdb_info:
|
||||||
|
return None
|
||||||
|
# dict[地区:分级]
|
||||||
|
ratings = {}
|
||||||
|
if results := (tmdb_info.get("release_dates") or {}).get("results"):
|
||||||
|
"""
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"iso_3166_1": "AR",
|
||||||
|
"release_dates": [
|
||||||
|
{
|
||||||
|
"certification": "+13",
|
||||||
|
"descriptors": [],
|
||||||
|
"iso_639_1": "",
|
||||||
|
"note": "",
|
||||||
|
"release_date": "2025-01-23T00:00:00.000Z",
|
||||||
|
"type": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
for item in results:
|
||||||
|
iso_3166_1 = item.get("iso_3166_1")
|
||||||
|
if not iso_3166_1:
|
||||||
|
continue
|
||||||
|
dates = item.get("release_dates")
|
||||||
|
if not dates:
|
||||||
|
continue
|
||||||
|
certification = dates[0].get("certification")
|
||||||
|
if not certification:
|
||||||
|
continue
|
||||||
|
ratings[iso_3166_1] = certification
|
||||||
|
elif results := (tmdb_info.get("content_ratings") or {}).get("results"):
|
||||||
|
"""
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"descriptors": [],
|
||||||
|
"iso_3166_1": "US",
|
||||||
|
"rating": "TV-MA"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
"""
|
||||||
|
for item in results:
|
||||||
|
iso_3166_1 = item.get("iso_3166_1")
|
||||||
|
if not iso_3166_1:
|
||||||
|
continue
|
||||||
|
rating = item.get("rating")
|
||||||
|
if not rating:
|
||||||
|
continue
|
||||||
|
ratings[iso_3166_1] = rating
|
||||||
|
if not ratings:
|
||||||
|
return None
|
||||||
|
return ratings.get("CN") or ratings.get("US")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __update_tmdbinfo_cn_title(tmdb_info: dict):
|
def __update_tmdbinfo_cn_title(tmdb_info: dict):
|
||||||
"""
|
"""
|
||||||
@@ -700,6 +764,7 @@ class TmdbApi:
|
|||||||
"credits,"
|
"credits,"
|
||||||
"alternative_titles,"
|
"alternative_titles,"
|
||||||
"translations,"
|
"translations,"
|
||||||
|
"release_dates,"
|
||||||
"external_ids") -> Optional[dict]:
|
"external_ids") -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
获取电影的详情
|
获取电影的详情
|
||||||
@@ -812,6 +877,7 @@ class TmdbApi:
|
|||||||
"credits,"
|
"credits,"
|
||||||
"alternative_titles,"
|
"alternative_titles,"
|
||||||
"translations,"
|
"translations,"
|
||||||
|
"content_ratings,"
|
||||||
"external_ids") -> Optional[dict]:
|
"external_ids") -> Optional[dict]:
|
||||||
"""
|
"""
|
||||||
获取电视剧的详情
|
获取电视剧的详情
|
||||||
|
|||||||
Reference in New Issue
Block a user