Files
Plex-Scripts/plex_dubletter.py
2025-11-29 21:00:42 +00:00

47 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from plexapi.server import PlexServer
from collections import defaultdict
import csv
# ---- KONFIGURATION ----
PLEX_URL = "https://plex.ckvist.dk"
PLEX_TOKEN = "VEwP2ocF8z-bh4dFZqAJ"
LIBRARY_NAME = "Film" # æ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")