fix #2113
This commit is contained in:
parent
111f830664
commit
8a565bb79f
@ -378,26 +378,34 @@ class Plex:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __get_ids(guids: List[Any]) -> dict:
|
def __get_ids(guids: List[Any]) -> dict:
|
||||||
|
def parse_tmdb_id(value: str) -> (bool, int):
|
||||||
|
"""尝试将TMDB ID字符串转换为整数。如果成功,返回(True, int),失败则返回(False, None)。"""
|
||||||
|
try:
|
||||||
|
int_value = int(value)
|
||||||
|
return True, int_value
|
||||||
|
except ValueError:
|
||||||
|
return False, None
|
||||||
|
|
||||||
guid_mapping = {
|
guid_mapping = {
|
||||||
"imdb://": "imdb_id",
|
"imdb://": "imdb_id",
|
||||||
"tmdb://": "tmdb_id",
|
"tmdb://": "tmdb_id",
|
||||||
"tvdb://": "tvdb_id"
|
"tvdb://": "tvdb_id"
|
||||||
}
|
}
|
||||||
ids = {}
|
ids = {varname: None for varname in guid_mapping.values()}
|
||||||
for prefix, varname in guid_mapping.items():
|
|
||||||
ids[varname] = None
|
|
||||||
for guid in guids:
|
for guid in guids:
|
||||||
|
guid_id = guid['id'] if isinstance(guid, dict) else guid.id
|
||||||
for prefix, varname in guid_mapping.items():
|
for prefix, varname in guid_mapping.items():
|
||||||
if isinstance(guid, dict):
|
if guid_id.startswith(prefix):
|
||||||
if guid['id'].startswith(prefix):
|
clean_id = guid_id[len(prefix):]
|
||||||
# 找到匹配的ID
|
if varname == "tmdb_id":
|
||||||
ids[varname] = guid['id'][len(prefix):]
|
# tmdb_id为int,Plex可能存在脏数据,特别处理tmdb_id
|
||||||
break
|
success, parsed_id = parse_tmdb_id(clean_id)
|
||||||
|
if success:
|
||||||
|
ids[varname] = parsed_id
|
||||||
else:
|
else:
|
||||||
if guid.id.startswith(prefix):
|
ids[varname] = clean_id
|
||||||
# 找到匹配的ID
|
|
||||||
ids[varname] = guid.id[len(prefix):]
|
|
||||||
break
|
break
|
||||||
|
|
||||||
return ids
|
return ids
|
||||||
|
|
||||||
def get_items(self, parent: str) -> Generator:
|
def get_items(self, parent: str) -> Generator:
|
||||||
@ -412,6 +420,7 @@ class Plex:
|
|||||||
section = self._plex.library.sectionByID(int(parent))
|
section = self._plex.library.sectionByID(int(parent))
|
||||||
if section:
|
if section:
|
||||||
for item in section.all():
|
for item in section.all():
|
||||||
|
try:
|
||||||
if not item:
|
if not item:
|
||||||
continue
|
continue
|
||||||
ids = self.__get_ids(item.guids)
|
ids = self.__get_ids(item.guids)
|
||||||
@ -431,6 +440,9 @@ class Plex:
|
|||||||
tvdbid=ids['tvdb_id'],
|
tvdbid=ids['tvdb_id'],
|
||||||
path=path,
|
path=path,
|
||||||
)
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"处理媒体项目时出错:{str(e)}, 跳过此项目。")
|
||||||
|
continue
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error(f"获取媒体库列表出错:{str(err)}")
|
logger.error(f"获取媒体库列表出错:{str(err)}")
|
||||||
yield None
|
yield None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user