-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplexUpdateMovie.py
More file actions
37 lines (31 loc) · 1.33 KB
/
plexUpdateMovie.py
File metadata and controls
37 lines (31 loc) · 1.33 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
import csv
from plexapi.server import PlexServer
# Configuration for Plex server
PLEX_URL = 'http://192.168.1.1:32400'
PLEX_TOKEN = 'PLEX_TOKEN'
# CSV file containing the movie unique identifiers to update
CSV_FILE = 'C:/Users/craig/Downloads/movie_titles.csv'
# Connect to Plex server
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
# Function to update movie titles and sort titles
def update_movie_titles(csv_file):
with open(csv_file, mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
rating_key = row['rating_key']
new_title = row['new_title']
sort_title = row['sort_title']
# Search for the movie by rating key (unique identifier)
movie = plex.fetchItem(int(rating_key))
if movie:
if new_title.strip(): # Check if new title is not blank
print(f"Updating '{movie.title}' to new title '{new_title}' and sort title '{sort_title}'")
movie.editTitle(new_title)
else:
print(f"Updating sort title for '{movie.title}' to '{sort_title}'")
movie.editSortTitle(sort_title)
movie.reload()
else:
print(f"Movie with rating key '{rating_key}' not found.")
# Run the update function
update_movie_titles(CSV_FILE)