Last active
July 17, 2024 20:16
-
-
Save JonnyWong16/fda947cfdab563b14b2c3663d61a0864 to your computer and use it in GitHub Desktop.
Audit duplicate Plex guids
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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