From 9528f7480bb0395e97841210358a46a717399fcb Mon Sep 17 00:00:00 2001 From: carsten Date: Sat, 29 Nov 2025 20:58:35 +0000 Subject: [PATCH] Add plex_dubletter.py --- plex_dubletter.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 plex_dubletter.py diff --git a/plex_dubletter.py b/plex_dubletter.py new file mode 100644 index 0000000..0cd6c69 --- /dev/null +++ b/plex_dubletter.py @@ -0,0 +1,46 @@ +from plexapi.server import PlexServer +from collections import defaultdict +import csv + +# ---- KONFIGURATION ---- +PLEX_URL = "http://IP_TIL_PLEX_SERVER:32400" +PLEX_TOKEN = "DIN_PLEX_TOKEN" +LIBRARY_NAME = "Movies" # ændr hvis din samling hedder noget andet + +# ---- FORBINDELSE ---- +plex = PlexServer(PLEX_URL, PLEX_TOKEN) +library = plex.library.section(LIBRARY_NAME) + +print("Henter film...") + +# Struktur: {"Titel (År)": [film1, film2, ...]} +movies_by_key = defaultdict(list) + +for movie in library.all(): + key = f"{movie.title} ({movie.year})" + movies_by_key[key].append(movie) + +# ---- FIND DUBLETTER ---- +duplicates = {k: v for k, v in movies_by_key.items() if len(v) > 1} + +print(f"\nFundet {len(duplicates)} film med dubletter.\n") + +# ---- UDPRINT OG GEM ---- +output = [] + +for title_key, items in duplicates.items(): + print(f"\n### {title_key} – {len(items)} versioner ###") + for movie in items: + for media in movie.media: + for part in media.parts: + filepath = part.file + print(f" - {filepath}") + output.append([title_key, filepath]) + +# ---- GEM SOM CSV ---- +with open("plex_duplicates.csv", "w", newline="", encoding="utf-8") as f: + writer = csv.writer(f) + writer.writerow(["Film", "Filplacering"]) + writer.writerows(output) + +print("\nCSV genereret: plex_duplicates.csv")