-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize4K.py
More file actions
40 lines (31 loc) · 1.33 KB
/
optimize4K.py
File metadata and controls
40 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
38
39
40
from plexapi.server import PlexServer
# Your Plex server details
PLEX_URL = 'http://192.168.1.1:32400' # Replace with your Plex server URL
PLEX_TOKEN = 'PLEX_TOKEN' # Replace with your Plex token
# Define custom optimization preset
CUSTOM_PRESET_NAME = "4K Optimized"
def create_optimized_versions():
try:
# Connect to the Plex server
plex = PlexServer(PLEX_URL, PLEX_TOKEN)
# Find the movie library
movie_library = next((lib for lib in plex.library.sections() if lib.type == "movie"), None)
if not movie_library:
print("No movie library found.")
return
# Iterate over movies and create optimized versions for 4K content
for movie in movie_library.all():
# Check if the movie has any 4K media parts
has_4k = any(
int(media.videoResolution.split('x')[0]) >= 3840
for media in movie.media
if media.videoResolution
)
if has_4k:
print(f"Creating custom optimized version for: {movie.title}")
# Use Plex built-in presets for optimization
movie.optimize(preset=CUSTOM_PRESET_NAME)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
create_optimized_versions()