-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateMovieSort.py
More file actions
43 lines (35 loc) · 1.42 KB
/
UpdateMovieSort.py
File metadata and controls
43 lines (35 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import csv
from plexapi.server import PlexServer
# === CONFIGURATION ===
PLEX_URL = 'http://192.168.1.1:32400' # Change to your Plex server URL
PLEX_TOKEN = 'PLEX_TOKEN' # Replace with your actual token
CSV_FILENAME = 'plex_movies_export.csv'
# =====================
def main():
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
# Load sort titles from CSV
sort_title_map = {}
with open(CSV_FILENAME, mode='r', encoding='utf-8') as file:
reader = csv.DictReader(file)
for row in reader:
plex_id = row['Plex ID']
sort_title = row['Title Sort']
if plex_id and sort_title:
sort_title_map[plex_id] = sort_title
print(f"Loaded {len(sort_title_map)} movie sort titles from CSV.")
# Process and update movies
movie_section = plex.library.section('Movies')
updated_count = 0
for movie in movie_section.all():
movie_id = str(movie.ratingKey)
if movie_id in sort_title_map:
new_sort_title = sort_title_map[movie_id]
current_sort_title = getattr(movie, 'titleSort', '')
if current_sort_title != new_sort_title:
print(f"Updating: {movie.title} (ID: {movie_id}) → '{new_sort_title}'")
movie.editSortTitle(new_sort_title)
movie.reload()
updated_count += 1
print(f"Updated {updated_count} movie sort titles.")
if __name__ == '__main__':
main()