This repository has been archived by the owner on May 23, 2024. It is now read-only.
forked from mfkiwl/Plex-Automatic-Pre-roll-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrerollUpdate.py
213 lines (207 loc) · 9.23 KB
/
PrerollUpdate.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import json
import PySimpleGUI as sg
import yaml
from urllib.parse import quote_plus, urlencode
import datetime
import re
import requests
from dateutil.easter import *
from plexapi.server import PlexServer
from plexapi import media, utils, settings, library
from plexapi.base import Playable, PlexPartialObject
from plexapi.exceptions import BadRequest, NotFound
from argparse import ArgumentParser
import os
import random
import shutil
import pathlib
from configparser import *
def update():
f = open(str('data.json'))
data = json.load(f)
if data['Freq'][0] == 'Monthly':
Date = datetime.date.today()
Date = Date.strftime("%b")
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
print(Date)
if data[Date] is None:
Path = data['Default']
else:
Path = data[Date]
prerolls = Path
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
if data['Freq'][0] == 'Weekly':
Date = datetime.date.today()
Date = Date.strftime("%Y-%m-%d")
if data['WeekStart'] <= Date <= data['WeekEnd']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['WeekPath']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
else:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Default']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
if data['Freq'][0] == 'Daily':
Date = datetime.date.today()
Date = Date.strftime("%a")
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
if data[Date] is None:
Path = data['Default']
else:
Path = data[Date]
prerolls = Path
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
if data['Freq'][0] == 'Holiday':
Date = datetime.date.today()
ThanksgivingDay = 22 + (10 - datetime.date(Date.year, 11, 1).weekday()) % 7
# Valentines Day
if Date.strftime("%b%d") == 'Feb14' and data['Valentines Day Enabled']:
Path = data['Valentines Day']
#April Fools
elif Date.strftime("%b%d") == 'Apr01' and data['April Fools Enabled']:
Path = data['April Fools']
# Juy 4th
elif Date.strftime("%b%d") == 'Jul04' and data['July 4th Enabled']:
Path = data['July 4th']
# Mardi Gras
elif easter(Date.year) - datetime.timedelta(days=47) == Date and data['Mardi Gras Enabled']:
Path = data['Mardi Gras']
# Easter
elif easter(Date.year) - datetime.timedelta(days=3) <= Date <= easter(Date.year) and data['Easter Enabled']:
Path = data['Easter']
# Halloween
elif Date.strftime("%b") == "Oct" and int(Date.strftime("%d")) >= 23 and data['Halloween Enabled']:
Path = data['Halloween']
# Thanksgiving
elif (datetime.date(Date.year,11,ThanksgivingDay) - datetime.timedelta(days=3) <= Date <= datetime.date(Date.year,11,ThanksgivingDay) + datetime.timedelta(days=4)) and data['Thanksgiving Enabled']:
Path = data['Thanksgiving']
# Christmas
elif Date.strftime("%b") == "Dec" and int(Date.strftime("%d")) >= 20 and data['Christmas Enabled']:
Path = data['Christmas']
else:
Path = data['Default']
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = Path
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
if data['Freq'][0] == 'Custom':
Date = datetime.date.today()
Date = Date.strftime("%Y-%m-%d")
if data['Start1'] <= Date <= data['End1']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path1']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start2'] <= Date <= data['End2']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path2']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start3'] <= Date <= data['End3']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path3']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start4'] <= Date <= data['End4']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path4']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start5'] <= Date <= data['End5']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path5']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start6'] <= Date <= data['End6']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path6']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start7'] <= Date <= data['End7']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path7']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start8'] <= Date <= data['End8']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path8']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start9'] <= Date <= data['End9']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path9']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
elif data['Start10'] <= Date <= data['End10']:
session = requests.Session()
session.verify = False
requests.packages.urllib3.disable_warnings()
plex = PlexServer(data['URL'], data['Token'], session, timeout=None)
prerolls = data['Path10']
plex.settings.get('cinemaTrailersPrerollID').set(prerolls)
plex.settings.save()
print('Pre-roll updated')
# Closing file
f.close()
if __name__ == '__main__':
update()