-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplexMovieExport.py
More file actions
54 lines (44 loc) · 1.73 KB
/
plexMovieExport.py
File metadata and controls
54 lines (44 loc) · 1.73 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
44
45
46
47
48
49
50
51
52
53
54
import csv
import os
from plexapi.server import PlexServer
from urllib.parse import urlparse, parse_qs
# === 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 get_imdb_id(guid):
if guid and 'imdb' in guid:
parsed = urlparse(guid)
return parsed.path.replace('/title/', '').strip('/')
return ''
def get_movie_file_paths(media):
return [part.file for part in media.parts]
def main():
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
movies = plex.library.section('Movies').all()
with open(CSV_FILENAME, mode='w', newline='', encoding='utf-8') as file:
writer = csv.writer(file)
writer.writerow([
'Plex ID', 'Title', 'Year', 'Title Sort', 'Collections', 'Edition',
'IMDb ID', 'File Path(s)'
])
for movie in movies:
plex_id = movie.ratingKey
title = movie.title
year = movie.year or ''
title_sort = getattr(movie, 'titleSort', '')
collections = ', '.join([c.tag for c in movie.collections]) if movie.collections else ''
edition = getattr(movie, 'editionTitle', '')
imdb_id = get_imdb_id(movie.guid)
# Collect all file paths
file_paths = []
for media in movie.media:
file_paths.extend(get_movie_file_paths(media))
writer.writerow([
plex_id, title, year, title_sort, collections, edition,
imdb_id, ' | '.join(file_paths)
])
print(f"Exported {len(movies)} movies to {CSV_FILENAME}")
if __name__ == '__main__':
main()