Add plex_dubletter.py
This commit is contained in:
46
plex_dubletter.py
Normal file
46
plex_dubletter.py
Normal file
@@ -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")
|
||||
Reference in New Issue
Block a user