forked from jkirkcaldy/plex-utills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhide-4k.py
38 lines (35 loc) · 1.44 KB
/
hide-4k.py
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
#!/usr/local/bin/python
from collections import defaultdict
from plexapi.server import PlexServer
from datetime import datetime
from configparser import ConfigParser
import socket
#Read config.ini file
config_object = ConfigParser()
config_object.read("config/config.ini")
server = config_object["PLEXSERVER"]
options = config_object["OPTIONS"]
optimise = str.lower((options["transcode"]))
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
print(current_time, ": Hide 4k films script starting now")
baseurl = (server["PLEX_URL"])
token = (server["TOKEN"])
films = (server["FILMSLIBRARY"])
plex = PlexServer(baseurl, token)
movies_section = plex.library.section(films)
added = movies_section.search(resolution='4k', sort='addedAt')
b = movies_section.search(label='untranscodable', sort='addedAt')
for movie in added:
resolutions = {m.videoResolution for m in movie.media}
if len(resolutions) < 2 and '4k' in resolutions:
if optimise == 'False':
movie.addLabel('Untranscodable')
print(movie.title+' has only 4k avaialble, setting untranscodable' )
elif optimise == 'true':
print('Sending', movie.title, 'to be transcoded')
movie.optimize(deviceProfile="Android", videoQuality=10)
for movie in b:
resolutions = {m.videoResolution for m in movie.media}
if len(resolutions) > 1 and '4k' in resolutions:
movie.removeLabel('Untranscodable')