forked from jkirkcaldy/plex-utills
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all.py
123 lines (103 loc) · 4.13 KB
/
run_all.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/local/bin/python3
import os
from subprocess import Popen, PIPE, STDOUT
from configparser import ConfigParser
import schedule
import time
from datetime import datetime
from colorama import Fore, Back, Style
from plexapi.server import PlexServer
import requests
from colorama import Fore, Back, Style
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
def check_config():
p = Popen('python3 -u ./config_check.py', shell=True, stderr=STDOUT, stdout=PIPE)
output = p.communicate()[0]
if 'Pass' in str(output):
print(Fore.LIGHTGREEN_EX,'Config check passed',Fore.RESET)
else:
exit()
check_config()
config_object = ConfigParser()
config_object.read("config/config.ini")
server = config_object["PLEXSERVER"]
schedules = config_object["SCHEDULES"]
options = config_object["OPTIONS"]
baseurl = (server["PLEX_URL"])
token = (server["TOKEN"])
films = (server["FILMSLIBRARY"])
plex = PlexServer(baseurl, token)
films = plex.library.section(films)
mpath = (server["MOUNTEDPATH"])
hdr_4k_posters = str.lower((options["4k_hdr_posters"]))
posters_3d_banner_add = str.lower((options["3d_posters"]))
Disney = str.lower((options["Disney"]))
Pixar = (str.lower(options["Pixar"]))
hide_4k = str.lower((options["hide_4k"]))
t1 = (schedules["4k_poster_schedule"])
t2 = (schedules["disney_schedule"])
t3 = (schedules["pixar_schedule"])
t4 = (schedules["hide_poster_schedule"])
t5 = (schedules["3d_poster_schedule"])
def posters_4k():
if hdr_4k_posters == "true":
p = Popen('python -u ./4k_hdr_poster.py', shell=True)
output = p.communicate()
print(output[0])
def posters_3d():
if posters_3d_banner_add == "true":
p = Popen('python -u ./4k_hdr_poster.py', shell=True)
output = p.communicate()
print(output[0])
def disney():
if Disney == "true":
p = Popen('python -u ./disney_collection.py', shell=True)
output = p.communicate()
print(output[0])
def pixar():
if Pixar == "true":
p = Popen('python -u ./Pixar_collection.py', shell=True)
output = p.communicate()
print(output[0])
def hide_4k_films():
if hide_4k == "true":
p = Popen('python -u ./hide-4k.py', shell=True)
output = p.communicate()
print(output[0])
def plex_file_path():
media_location = films.search()
filepath = os.path.dirname(os.path.dirname(media_location[0].media[0].parts[0].file))
print(Fore.GREEN, 'Plex mount path is:')
print('/'+filepath.split('/')[1], Fore.RESET)
print(Fore.LIGHTGREEN_EX, '# You should use the mount path of all your media not just your movies folder.', Fore.RESET)
print(Fore.YELLOW, 'checking poster download permissions...')
i = films.search(resolution='4k')
imgurl = i[0].posterUrl
img = requests.get(imgurl, stream=True)
if img.status_code == 200:
print(Fore.GREEN, "You're good to go", Fore.RESET)
elif img.status_code == 401:
print(Fore.RED, "Unable to download the image", Fore.RESET)
def check_mpath():
try:
test_dir = os.listdir(mpath)
print("if you see your media directories bellow then all should be good. If you don't see anything, or your don't see the expected directories make sure your plex media is mounted and mapped correctly in the config file.")
print(Fore.LIGHTBLUE_EX, test_dir, Fore.RESET)
except FileNotFoundError:
print('Oops, it looks like', Fore.YELLOW,'"',mpath,'"', Fore.RESET, "isn't correct or doesn't have the right permissions")
def working():
print(current_time, ": This script is still working, check back later for more info")
print(current_time, ": This script is now running, check back later for more info")
plex_file_path()
check_mpath()
print('waiting for next script...')
schedule.every(60).minutes.do(working)
schedule.every().day.at(t1).do(posters_4k)
schedule.every().day.at(t5).do(posters_3d)
schedule.every().day.at(t2).do(disney)
schedule.every().day.at(t3).do(pixar)
schedule.every().day.at(t4).do(hide_4k_films)
while True:
schedule.run_pending()
time.sleep(1)