From 4c979c458e5a4a21ecd0110e511007073dc9ee51 Mon Sep 17 00:00:00 2001 From: sowevo Date: Wed, 13 Aug 2025 16:54:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=8E=20TMDB=20=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=B8=AD=E8=A7=A3=E6=9E=90=E6=95=B0=E5=80=BC?= =?UTF-8?q?=20ID=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/themoviedb/tmdbapi.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/app/modules/themoviedb/tmdbapi.py b/app/modules/themoviedb/tmdbapi.py index 7e1e7218..89f33313 100644 --- a/app/modules/themoviedb/tmdbapi.py +++ b/app/modules/themoviedb/tmdbapi.py @@ -348,9 +348,13 @@ class TmdbApi: 处理网站搜索得到的链接 """ 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( mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE, - tmdbid=tmdb_links[0].split("/")[-1]) + tmdbid=tmdbid) if tmdbinfo: if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV: return {} @@ -368,9 +372,13 @@ class TmdbApi: 处理网站搜索得到的链接(异步版本) """ 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( mtype=MediaType.TV if tmdb_links[0].startswith("/tv") else MediaType.MOVIE, - tmdbid=int(tmdb_links[0].split("/")[-1])) + tmdbid=tmdbid) if tmdbinfo: if mtype == MediaType.TV and tmdbinfo.get('media_type') != MediaType.TV: return {} @@ -382,6 +390,25 @@ class TmdbApi: logger.info("%s TMDB网站未查询到媒体信息!" % name) 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 def __get_names(tmdb_info: dict) -> List[str]: """ From b0d17deda131433758ad92fe604379045dc8882a Mon Sep 17 00:00:00 2001 From: sowevo Date: Wed, 13 Aug 2025 17:11:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BB=8E=20TMDB=20=E7=9B=B8=E5=AF=B9?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=E4=B8=AD=E8=A7=A3=E6=9E=90=E6=95=B0=E5=80=BC?= =?UTF-8?q?=20ID=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/themoviedb/tmdbapi.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/modules/themoviedb/tmdbapi.py b/app/modules/themoviedb/tmdbapi.py index 89f33313..66d23011 100644 --- a/app/modules/themoviedb/tmdbapi.py +++ b/app/modules/themoviedb/tmdbapi.py @@ -404,10 +404,7 @@ class TmdbApi: 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 + return None @staticmethod def __get_names(tmdb_info: dict) -> List[str]: