mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-05 15:38:19 +08:00
从 TMDB 相对链接中解析数值 ID。
This commit is contained in:
@@ -348,9 +348,13 @@ class TmdbApi:
|
|||||||
处理网站搜索得到的链接
|
处理网站搜索得到的链接
|
||||||
"""
|
"""
|
||||||
if len(tmdb_links) == 1:
|
if len(tmdb_links) == 1:
|
||||||
|
tmdbid = self._parse_tmdb_id_from_link(tmdb_links[0])
|
||||||
|
if not tmdbid:
|
||||||
|
logger.warn(f"无法从链接解析TMDBID:{tmdb_links[0]}")
|
||||||
|
return {}
|
||||||
tmdbinfo = get_info_func(
|
tmdbinfo = get_info_func(
|
||||||
mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE,
|
mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE,
|
||||||
tmdbid=tmdb_links[0].split("/")[-1])
|
tmdbid=tmdbid)
|
||||||
if tmdbinfo:
|
if tmdbinfo:
|
||||||
if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV:
|
if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV:
|
||||||
return {}
|
return {}
|
||||||
@@ -368,9 +372,13 @@ class TmdbApi:
|
|||||||
处理网站搜索得到的链接(异步版本)
|
处理网站搜索得到的链接(异步版本)
|
||||||
"""
|
"""
|
||||||
if len(tmdb_links) == 1:
|
if len(tmdb_links) == 1:
|
||||||
|
tmdbid = self._parse_tmdb_id_from_link(tmdb_links[0])
|
||||||
|
if not tmdbid:
|
||||||
|
logger.warn(f"无法从链接解析TMDBID:{tmdb_links[0]}")
|
||||||
|
return {}
|
||||||
tmdbinfo = await self.async_get_info(
|
tmdbinfo = await self.async_get_info(
|
||||||
mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE,
|
mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE,
|
||||||
tmdbid=int(tmdb_links[0].split("/")[-1]))
|
tmdbid=tmdbid)
|
||||||
if tmdbinfo:
|
if tmdbinfo:
|
||||||
if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV:
|
if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV:
|
||||||
return {}
|
return {}
|
||||||
@@ -382,6 +390,25 @@ class TmdbApi:
|
|||||||
logger.info("%s TMDB网站未查询到媒体信息!" % name)
|
logger.info("%s TMDB网站未查询到媒体信息!" % name)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse_tmdb_id_from_link(link: str) -> Optional[int]:
|
||||||
|
"""
|
||||||
|
从 TMDB 相对链接中解析数值 ID。
|
||||||
|
兼容格式:/movie/1195631-william-tell、/tv/65942-re、/tv/79744-the-rookie
|
||||||
|
"""
|
||||||
|
if not link:
|
||||||
|
return None
|
||||||
|
match = re.match(r"^/[^/]+/(\d+)", link)
|
||||||
|
if match:
|
||||||
|
try:
|
||||||
|
return int(match.group(1))
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
|
# 兜底:取最后段再取数字前缀
|
||||||
|
last = link.rsplit("/", 1)[-1]
|
||||||
|
num_match = re.match(r"^(\d+)", last)
|
||||||
|
return int(num_match.group(1)) if num_match else None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_names(tmdb_info: dict) -> List[str]:
|
def __get_names(tmdb_info: dict) -> List[str]:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user