From a8f8bf5872af6aceb5025631e9ba4a106171fa64 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 18 May 2025 13:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=BC=BAMetaBase=E7=B1=BB=E4=BB=A5?= =?UTF-8?q?=E6=94=AF=E6=8C=81tmdbid=E5=92=8Cdoubanid=E7=9A=84=E8=B5=8B?= =?UTF-8?q?=E5=80=BC=EF=BC=8C=E5=B9=B6=E4=B8=BAEmby=E6=A0=BC=E5=BC=8FID?= =?UTF-8?q?=E8=AF=86=E5=88=AB=E6=B7=BB=E5=8A=A0=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/meta/metabase.py | 6 +++ tests/cases/meta.py | 80 +++++++++++++++++++++++++++++++++++++++ tests/test_metainfo.py | 28 ++++++++++++++ 3 files changed, 114 insertions(+) diff --git a/app/core/meta/metabase.py b/app/core/meta/metabase.py index 543adf2eb..04f051517 100644 --- a/app/core/meta/metabase.py +++ b/app/core/meta/metabase.py @@ -582,6 +582,12 @@ class MetaBase(object): # Part if not self.part: self.part = meta.part + # tmdbid + if not self.tmdbid and meta.tmdbid: + self.tmdbid = meta.tmdbid + # doubanid + if not self.doubanid and meta.doubanid: + self.doubanid = meta.doubanid def to_dict(self): """ diff --git a/tests/cases/meta.py b/tests/cases/meta.py index 63d815dd7..6df283c43 100644 --- a/tests/cases/meta.py +++ b/tests/cases/meta.py @@ -1037,4 +1037,84 @@ meta_cases = [{ "video_codec": "", "audio_codec": "" } +}, { + "path": "/movies/The Vampire Diaries (2009) [tmdbid=18165]/The.Vampire.Diaries.S01E01.1080p.mkv", + "target": { + "type": "电视剧", + "cn_name": "", + "en_name": "The Vampire Diaries", + "year": "2009", + "part": "", + "season": "S01", + "episode": "E01", + "restype": "", + "pix": "1080p", + "video_codec": "", + "audio_codec": "", + "tmdbid": 18165 + } +}, { + "path": "/movies/Inception (2010) [tmdbid-27205]/Inception.2010.1080p.mkv", + "target": { + "type": "未知", + "cn_name": "", + "en_name": "Inception", + "year": "2010", + "part": "", + "season": "", + "episode": "", + "restype": "", + "pix": "1080p", + "video_codec": "", + "audio_codec": "", + "tmdbid": 27205 + } +}, { + "path": "/movies/Breaking Bad (2008) [tmdb=1396]/Season 1/Breaking.Bad.S01E01.1080p.mkv", + "target": { + "type": "电视剧", + "cn_name": "", + "en_name": "Breaking Bad", + "year": "2008", + "part": "", + "season": "S01", + "episode": "E01", + "restype": "", + "pix": "1080p", + "video_codec": "", + "audio_codec": "", + "tmdbid": 1396 + } +}, { + "path": "/tv/Game of Thrones (2011) {tmdb=1399}/Season 1/Game.of.Thrones.S01E01.1080p.mkv", + "target": { + "type": "电视剧", + "cn_name": "", + "en_name": "Game Of Thrones", + "year": "2011", + "part": "", + "season": "S01", + "episode": "E01", + "restype": "", + "pix": "1080p", + "video_codec": "", + "audio_codec": "", + "tmdbid": 1399 + } +}, { + "path": "/movies/Avatar (2009) {tmdb-19995}/Avatar.2009.1080p.mkv", + "target": { + "type": "未知", + "cn_name": "", + "en_name": "Avatar", + "year": "2009", + "part": "", + "season": "", + "episode": "", + "restype": "", + "pix": "1080p", + "video_codec": "", + "audio_codec": "", + "tmdbid": 19995 + } }] diff --git a/tests/test_metainfo.py b/tests/test_metainfo.py index 689f021f3..ac4645948 100644 --- a/tests/test_metainfo.py +++ b/tests/test_metainfo.py @@ -32,4 +32,32 @@ class MetaInfoTest(TestCase): "video_codec": meta_info.video_encode or "", "audio_codec": meta_info.audio_encode or "" } + + # 检查tmdbid + if info.get("target").get("tmdbid"): + target["tmdbid"] = meta_info.tmdbid + self.assertEqual(target, info.get("target")) + + def test_emby_format_ids(self): + """ + 测试Emby格式ID识别 + """ + # 测试文件路径 + test_paths = [ + # 文件名中包含tmdbid + ("/movies/The Vampire Diaries (2009) [tmdbid=18165]/The.Vampire.Diaries.S01E01.1080p.mkv", 18165), + # 目录名中包含tmdbid + ("/movies/Inception (2010) [tmdbid-27205]/Inception.2010.1080p.mkv", 27205), + # 父目录名中包含tmdbid + ("/movies/Breaking Bad (2008) [tmdb=1396]/Season 1/Breaking.Bad.S01E01.1080p.mkv", 1396), + # 祖父目录名中包含tmdbid + ("/tv/Game of Thrones (2011) {tmdb=1399}/Season 1/Game.of.Thrones.S01E01.1080p.mkv", 1399), + # 测试{tmdb-xxx}格式 + ("/movies/Avatar (2009) {tmdb-19995}/Avatar.2009.1080p.mkv", 19995), + ] + + for path_str, expected_tmdbid in test_paths: + meta = MetaInfoPath(Path(path_str)) + self.assertEqual(meta.tmdbid, expected_tmdbid, + f"路径 {path_str} 期望的tmdbid为 {expected_tmdbid},实际识别为 {meta.tmdbid}")