Skip to content

Commit 19608fa

Browse files
authored
Merge pull request jxxghp#4756 from Sowevo/v2
2 parents c5e9316 + b0d17de commit 19608fa

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

app/modules/themoviedb/tmdbapi.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,13 @@ def _process_web_search_links(self, name: str, mtype: MediaType,
348348
处理网站搜索得到的链接
349349
"""
350350
if len(tmdb_links) == 1:
351+
tmdbid = self._parse_tmdb_id_from_link(tmdb_links[0])
352+
if not tmdbid:
353+
logger.warn(f"无法从链接解析TMDBID:{tmdb_links[0]}")
354+
return {}
351355
tmdbinfo = get_info_func(
352356
mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE,
353-
tmdbid=tmdb_links[0].split("/")[-1])
357+
tmdbid=tmdbid)
354358
if tmdbinfo:
355359
if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV:
356360
return {}
@@ -368,9 +372,13 @@ async def _async_process_web_search_links(self, name: str,
368372
处理网站搜索得到的链接(异步版本)
369373
"""
370374
if len(tmdb_links) == 1:
375+
tmdbid = self._parse_tmdb_id_from_link(tmdb_links[0])
376+
if not tmdbid:
377+
logger.warn(f"无法从链接解析TMDBID:{tmdb_links[0]}")
378+
return {}
371379
tmdbinfo = await self.async_get_info(
372380
mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE,
373-
tmdbid=int(tmdb_links[0].split("/")[-1]))
381+
tmdbid=tmdbid)
374382
if tmdbinfo:
375383
if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV:
376384
return {}
@@ -382,6 +390,22 @@ async def _async_process_web_search_links(self, name: str,
382390
logger.info("%s TMDB网站未查询到媒体信息!" % name)
383391
return {}
384392

393+
@staticmethod
394+
def _parse_tmdb_id_from_link(link: str) -> Optional[int]:
395+
"""
396+
从 TMDB 相对链接中解析数值 ID。
397+
兼容格式:/movie/1195631-william-tell、/tv/65942-re、/tv/79744-the-rookie
398+
"""
399+
if not link:
400+
return None
401+
match = re.match(r"^/[^/]+/(\d+)", link)
402+
if match:
403+
try:
404+
return int(match.group(1))
405+
except Exception:
406+
return None
407+
return None
408+
385409
@staticmethod
386410
def __get_names(tmdb_info: dict) -> List[str]:
387411
"""

0 commit comments

Comments
 (0)