Skip to content

Instantly share code, notes, and snippets.

@JonnyWong16
Last active July 17, 2024 20:16
Show Gist options
  • Save JonnyWong16/fda947cfdab563b14b2c3663d61a0864 to your computer and use it in GitHub Desktop.
Save JonnyWong16/fda947cfdab563b14b2c3663d61a0864 to your computer and use it in GitHub Desktop.
Audit duplicate Plex guids
from plexapi.server import PlexServer
def duplicate_guids(library, libtype=None):
for item in library.all(libtype):
guid_map = {
'imdb': [],
'tmdb': [],
'tvdb': [],
}
for guid in item.guids:
guid_map[guid.id[:4]].append(guid.id)
if any(len(guids) > 1 for guids in guid_map.values()):
if item.type in ('movie', 'show'):
print(f'{item.title} ({item.year})')
elif item.type == 'season':
print(f'{item.parentTitle} ({item.parentYear}) - {item.title}')
elif item.type == 'episode':
print(f'{item.grandparentTitle} ({item.year}) - {item.seasonEpisode} - {item.title}')
print(f' {item.guid}')
for guids in guid_map.values():
for guid in guids:
print(f' {guid}')
if __name__ == '__main__':
plex = PlexServer('http://localhost:32400', token='XXXXXXXXXXXXXXXXXXXX')
for library in plex.library.sections():
if library.type == 'movie':
duplicate_guids(library)
elif library.type == 'show':
duplicate_guids(library)
duplicate_guids(library, 'season')
duplicate_guids(library, 'episode')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment