-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.py
executable file
·352 lines (339 loc) · 11.5 KB
/
main.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
from app import app
def sys_info():
import platform
uname = platform.uname()
log.info({"System: "+uname.system,
"Node Name: "+uname.node,
"Release: "+uname.release,
"Version: "+uname.version,
"Machine: "+uname.machine})
from app.setup import setup_helper
setup_helper()
plexpath = ''
import sqlite3
import shutil
from app import log
def continue_setup():
def add_new_columns():
#log.debug('Adding new Columns')
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
config = c.fetchall()
query1 = """ALTER TABLE plex_utills
ADD COLUMN autocollections INT
"""
query2 = """ALTER TABLE plex_utills
ADD COLUMN default_poster INT
"""
query3 = """ALTER TABLE plex_utills
ADD COLUMN tr_r_p_collection INT
"""
query4 = """ALTER TABLE plex_utills
ADD COLUMN tautulli_server TEXT
"""
query5 = """ALTER TABLE plex_utills
ADD COLUMN tautulli_api TEXT
"""
query6 = """ALTER TABLE plex_utills
ADD COLUMN mcu_collection INT
"""
query7 = """ALTER TABLE plex_utills
ADD COLUMN audio_posters INT
"""
query8 = """ALTER TABLE plex_utills
ADD COLUMN loglevel INT
"""
query9 = """ALTER TABLE plex_utills
ADD COLUMN manualplexpath INT
"""
query10 = """ALTER TABLE plex_utills
ADD COLUMN manualplexpathfield TEXT
"""
query11 = """ALTER TABLE plex_utills
ADD COLUMN skip_media_info INT
"""
query12 = """ALTER TABLE plex_utills
ADD COLUMN spoilers INT
"""
query13 = """ALTER TABLE episodes
ADD COLUMN show_season INT
"""
query14 = """ALTER TABLE seasons
ADD COLUMN checked INT
"""
query15 = """ALTER TABLE films
ADD COLUMN url TEXT
"""
query16 = """ALTER TABLE plex_utills
ADD COLUMN migrated INT
"""
try:
c.execute(query1)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query2)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query3)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query4)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query5)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query6)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query7)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query8)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query9)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query10)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query11)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query12)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query13)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query14)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query15)
except sqlite3.OperationalError as e:
pass
try:
c.execute(query16)
except sqlite3.OperationalError as e:
pass
try:
api = config[0][32]
loglevel = config[0][36]
manpp = config[0][37]
mediainfo = config[0][39]
newhdr = config[0][28]
migrated = config[0][41]
if not api:
c.execute("UPDATE plex_utills SET tautulli_server = 'http://127.0.0.1:8181' where ID = 1")
if not loglevel or loglevel == '0':
c.execute("UPDATE plex_utills SET loglevel = '1' WHERE ID = 1")
if not manpp:
c.execute("UPDATE plex_utills SET manualplexpath = '0' WHERE ID = 1")
c.execute("UPDATE plex_utills SET manualplexpathfield = 'None' WHERE ID = 1")
if not mediainfo or mediainfo == 'None':
c.execute("UPDATE plex_utills SET skip_media_info = '0' WHERE ID = 1")
if not newhdr or newhdr == 'None':
c.execute("UPDATE plex_utills SET new_hdr = '1' WHERE ID = 1")
if not migrated:
c.execute("UPDATE plex_utills SET migrated = '0' WHERE ID = 1")
conn.commit()
except (sqlite3.OperationalError, IndexError) as e:
pass
#log.debug(repr(e))
c.close()
add_new_columns()
#try:
# update_plex_path()
#except:
# raise Exception('looks like this is a first run')
add_new_table()
def create_table():
shutil.copy('app/static/default_db/default_app.db', '/config/app.db')
#log.debug('Copying table')
continue_setup()
def add_new_table():
#log.debug('Adding new table')
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
table = """CREATE TABLE "films" (
"ID" INTEGER NOT NULL UNIQUE,
"Title" TEXT NOT NULL,
"GUID" TEXT NOT NULL,
"GUIDS" TEXT NOT NULL,
"size" TEXT,
"res" TEXT,
"hdr" TEXT,
"audio" TEXT,
"poster" TEXT NOT NULL,
"checked" INTEGER,
PRIMARY KEY("ID" AUTOINCREMENT)
); """
c.execute(table)
conn.commit()
except Exception as e:
pass #log.debug(repr(e))
def add_ep_table():
#log.debug('Adding new table')
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
table = """CREATE TABLE "episodes" (
"ID" INTEGER NOT NULL UNIQUE,
"Show_season" TEXT,
"Title" TEXT NOT NULL,
"GUID" TEXT NOT NULL,
"GUIDS" TEXT NOT NULL,
"size" TEXT,
"res" TEXT,
"hdr" TEXT,
"audio" TEXT,
"poster" TEXT NOT NULL,
"bannered_poster" TEXT,
"checked" INTEGER,
"blurred" INTEGER,
PRIMARY KEY("ID" AUTOINCREMENT)
); """
c.execute(table)
conn.commit()
except Exception as e:
pass #log.debug(repr(e))
def add_season_table():
#log.debug('Adding new table')
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
table = """CREATE TABLE "seasons" (
"ID" INTEGER NOT NULL UNIQUE,
"Title" TEXT NOT NULL,
"GUID" TEXT NOT NULL,
"poster" TEXT,
"bannered_poster" TEXT,
"checked" INTEGER,
PRIMARY KEY("ID" AUTOINCREMENT)
); """
c.execute(table)
conn.commit()
except Exception as e:
pass #log.debug(repr(e))
def table_check():
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
c.close()
continue_setup()
except sqlite3.OperationalError as e:
#log.debug(repr(e))
create_table()
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM films")
c.close()
continue_setup()
except sqlite3.OperationalError as e:
#log.debug(repr(e))
add_new_table()
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM episodes")
try:
q1 = """ALTER TABLE episodes
ADD COLUMN blurred INT
"""
c.execute(q1)
except sqlite3.OperationalError as e:
pass # log.debug(repr(e))
try:
q3 = """ALTER TABLE episodes
ADD COLUMN bannered_poster TEXT
"""
c.execute(q3)
except sqlite3.OperationalError as e:
pass #log.debug(repr(e))
try:
q2 = """ALTER TABLE films
ADD COLUMN bannered_poster TEXT
"""
c.execute(q2)
except sqlite3.OperationalError as e:
pass #log.debug(repr(e))
c.close()
continue_setup()
except sqlite3.OperationalError as e:
#log.debug(repr(e))
add_ep_table()
try:
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM seasons")
c.close()
continue_setup()
except sqlite3.OperationalError as e:
pass #log.debug(repr(e))
add_season_table()
log.debug('Running setup Helper')
table_check()
from app import log
import os
b_dir = '/config/backup/'
try:
log.info('creating backup directory now')
if os.path.exists(b_dir):
pass
else:
os.makedirs(b_dir)
if os.path.exists(b_dir+'/films'):
pass
else:
os.makedirs(b_dir+'/films')
if os.path.exists(b_dir+'/tv/episodes'):
pass
else:
os.makedirs(b_dir+'/tv/episodes')
if os.path.exists(b_dir+'/tv/bannered_episodes'):
pass
else:
os.makedirs(b_dir+'/tv/bannered_episodes')
if os.path.exists(b_dir+'bannered_films'):
pass
else:
os.makedirs(b_dir+'bannered_films')
if os.path.exists(b_dir+'/tv/bannered_seasons'):
pass
else:
os.makedirs(b_dir+'/tv/bannered_seasons')
if os.path.exists(b_dir+'/tv/seasons'):
pass
else:
os.makedirs(b_dir+'/tv/seasons')
except: pass
try:
for root,dirs,files in os.walk('/config'):
os.chmod(root, 0o777)
for f in files :
os.chmod(os.path.join(root,f) , 0o777)
for d in dirs :
os.chmod(os.path.join(root,d) , 0o777)
except Exception as e:
log.error(repr(e))
if __name__ == '__main__':
app.run()