mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-26 13:13:40 +00:00
added exception handling to database update
Error handling now exists to prevent a corrupted database from being copied across the channel directories in case of an update failure. Script will now exit without copying files if the database update does not complete.
This commit is contained in:
@@ -42,7 +42,7 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
update_call = "python3 PseudoChannel.py %s" % update_flags
|
update_call = "python3 PseudoChannel.py %s" % update_flags
|
||||||
|
halt = True
|
||||||
|
|
||||||
# Step ONE: Global database update
|
# Step ONE: Global database update
|
||||||
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
||||||
@@ -53,139 +53,142 @@ except OSError:
|
|||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
os.system(update_call)
|
os.system(update_call)
|
||||||
|
halt = False
|
||||||
except:
|
except:
|
||||||
print("ERROR: Global Update Failed!")
|
print("ERROR: Global Update Failed!")
|
||||||
os.remove("pseudo-channel.db")
|
print(e)
|
||||||
os.rename("pseudo-channel.bak", "pseudo-channel.db")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
base_dirA = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
locations = "pseudo-channel"+channel_dir_increment_symbol
|
|
||||||
channel_dirs = [ item for item in os.listdir('.') if os.path.isdir(os.path.join('.', item)) ]
|
|
||||||
channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs))
|
|
||||||
|
|
||||||
for channel_dir in channel_dirs:
|
|
||||||
# Step TWO: Go to each folder, export the following information
|
|
||||||
# - Show title, lastEpisodeTitle
|
|
||||||
# - Movie title, lastPlayedDate
|
|
||||||
# - Current channel schedule that the daily schedule is sourced from
|
|
||||||
# - Daily schedule currently being executed
|
|
||||||
os.chdir(channel_dir)
|
|
||||||
|
|
||||||
channel_dirA = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
print(channel_dirA.split('/')[-1])
|
|
||||||
if channel_dirA.split('/')[-1] == "channels":
|
|
||||||
os.chdir(os.path.join(channel_dirA, channel_dir))
|
|
||||||
channel_dirA = os.getcwd()
|
|
||||||
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
|
||||||
print("ACTION: Importing from " + db_path)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
os.remove("pseudo-channel.db")
|
||||||
|
halt = True
|
||||||
|
except:
|
||||||
|
print("DATABASE FILE NOT FOUND, RESTORING BACKUP")
|
||||||
|
os.rename("pseudo-channel.bak", "pseudo-channel.db")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
|
if halt != True:
|
||||||
|
base_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
locations = "pseudo-channel"+channel_dir_increment_symbol
|
||||||
|
channel_dirs = [ item for item in os.listdir('.') if os.path.isdir(os.path.join('.', item)) ]
|
||||||
|
channel_dirs = list(filter(lambda x: x.startswith(locations),channel_dirs))
|
||||||
|
|
||||||
|
for channel_dir in channel_dirs:
|
||||||
|
# Step TWO: Go to each folder, export the following information
|
||||||
|
# - Show title, lastEpisodeTitle
|
||||||
|
# - Movie title, lastPlayedDate
|
||||||
|
# - Current channel schedule that the daily schedule is sourced from
|
||||||
|
# - Daily schedule currently being executed
|
||||||
|
os.chdir(channel_dir)
|
||||||
|
|
||||||
|
channel_dirA = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
print(channel_dirA.split('/')[-1])
|
||||||
|
if channel_dirA.split('/')[-1] == "channels":
|
||||||
|
os.chdir(os.path.join(channel_dirA, channel_dir))
|
||||||
|
channel_dirA = os.getcwd()
|
||||||
|
db_path = os.path.join(channel_dirA, "pseudo-channel.db")
|
||||||
|
print("ACTION: Importing from " + db_path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
table = conn.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall()
|
||||||
|
lastEpisode_export = list(lastEpisode_export)
|
||||||
|
lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall()
|
||||||
|
lastMovie_export = list(lastMovie_export)
|
||||||
|
schedule = table.execute('SELECT * FROM schedule').fetchall()
|
||||||
|
daily_schedule = table.execute('SELECT * FROM daily_schedule').fetchall()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
except:
|
||||||
|
print("NOTICE: Database experiencing errors or hasn't been formed yet; creating fresh one")
|
||||||
|
lastEpisode_export = []
|
||||||
|
lastMovie_export = []
|
||||||
|
schedule = []
|
||||||
|
daily_schedule = []
|
||||||
|
|
||||||
|
|
||||||
|
# Step THREE: Delete the previous database, replace with the recently created global one
|
||||||
|
print("ACTION: Copying global update to " + db_path)
|
||||||
|
copy2('../pseudo-channel.db','.')
|
||||||
|
|
||||||
|
|
||||||
|
# Step FOUR: Import the previous information we exported previously
|
||||||
|
print("ACTION: Exporting to " + db_path)
|
||||||
conn = sqlite3.connect(db_path)
|
conn = sqlite3.connect(db_path)
|
||||||
table = conn.cursor()
|
table = conn.cursor()
|
||||||
|
|
||||||
|
for i in range(0,len(lastEpisode_export)):
|
||||||
|
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
|
||||||
|
table.execute(sql,lastEpisode_export[i])
|
||||||
|
|
||||||
lastEpisode_export = table.execute('SELECT lastEpisodeTitle,title FROM shows').fetchall()
|
for i in range(0,len(lastMovie_export)):
|
||||||
lastEpisode_export = list(lastEpisode_export)
|
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
||||||
lastMovie_export = table.execute('SELECT lastPlayedDate,title FROM movies').fetchall()
|
table.execute(sql,lastMovie_export[i])
|
||||||
lastMovie_export = list(lastMovie_export)
|
if len(schedule) == 0:
|
||||||
schedule = table.execute('SELECT * FROM schedule').fetchall()
|
#db = PseudoChannelDatabase("./pseudo-channel.db")
|
||||||
daily_schedule = table.execute('SELECT * FROM daily_schedule').fetchall()
|
print("NOTICE: Schedule Not Found, Creating Default Schedule")
|
||||||
|
entryList = {}
|
||||||
|
entryList['id'] = "1"
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
except:
|
|
||||||
print("NOTICE: Database experiencing errors or hasn't been formed yet; creating fresh one")
|
|
||||||
lastEpisode_export = []
|
|
||||||
lastMovie_export = []
|
|
||||||
schedule = []
|
|
||||||
daily_schedule = []
|
|
||||||
|
|
||||||
|
|
||||||
# Step THREE: Delete the previous database, replace with the recently created global one
|
|
||||||
print("ACTION: Copying global update to " + db_path)
|
|
||||||
copy2('../pseudo-channel.db','.')
|
|
||||||
|
|
||||||
|
|
||||||
# Step FOUR: Import the previous information we exported previously
|
|
||||||
print("ACTION: Exporting to " + db_path)
|
|
||||||
conn = sqlite3.connect(db_path)
|
|
||||||
table = conn.cursor()
|
|
||||||
|
|
||||||
for i in range(0,len(lastEpisode_export)):
|
|
||||||
sql = "UPDATE shows SET lastEpisodeTitle=? WHERE title=?"
|
|
||||||
table.execute(sql,lastEpisode_export[i])
|
|
||||||
|
|
||||||
for i in range(0,len(lastMovie_export)):
|
|
||||||
sql = "UPDATE movies SET lastPlayedDate=? WHERE title=?"
|
|
||||||
table.execute(sql,lastMovie_export[i])
|
|
||||||
if len(schedule) == 0:
|
|
||||||
#db = PseudoChannelDatabase("./pseudo-channel.db")
|
|
||||||
print("NOTICE: Schedule Not Found, Creating Default Schedule")
|
|
||||||
entryList = {}
|
|
||||||
entryList['id'] = "1"
|
|
||||||
entryList['unix'] = str(time.time())
|
|
||||||
entryList['mediaID'] = "23"
|
|
||||||
rndsql = "SELECT * FROM shows WHERE (customSectionName NOT LIKE 'playlist' AND duration BETWEEN 6000 and 999000000) ORDER BY RANDOM() LIMIT 1"
|
|
||||||
table.execute(rndsql)
|
|
||||||
the_show = table.fetchone()
|
|
||||||
entryList['duration'] = str("1,"+str(int(the_show[4] / 60000)))
|
|
||||||
entryList['title'] = the_show[3]
|
|
||||||
entryList['startTime'] = "00:00:00"
|
|
||||||
entryList['dayOfWeek'] = "everyday"
|
|
||||||
entryList['startTimeUnix'] = time.mktime(time.strptime("2000/01/01 00:00:00", "%Y/%m/%d %H:%M:%S"))
|
|
||||||
entryList['section'] = "TV Shows"
|
|
||||||
if entryList['startTime'] == "00:00:00":
|
|
||||||
entryList['strictTime'] = "true"
|
|
||||||
else:
|
|
||||||
entryList['strictTime'] = "secondary"
|
|
||||||
entryList['endTime'] = datetime.datetime.fromtimestamp(float(entryList['startTimeUnix']) + the_show[4]/1000).strftime("%H:%M:%S")
|
|
||||||
entryList['timeShift'] = 15
|
|
||||||
entryList['overlapMax'] = 15
|
|
||||||
entryList['xtra'] = None
|
|
||||||
entryList['rerun'] = 0
|
|
||||||
entryList['year'] = None
|
|
||||||
entryList['genres'] = None
|
|
||||||
entryList['actors'] = None
|
|
||||||
entryList['collections'] = None
|
|
||||||
entryList['rating'] = None
|
|
||||||
entryList['studio'] = None
|
|
||||||
entryList['seasonEpisode'] = None
|
|
||||||
print("INFO: Adding "+entryList['startTime']+" - "+entryList['title']+"\033[K",end='\n')
|
|
||||||
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra,rerun,year,genres,actors,collections,rating,studio,seasonEpisode) \
|
|
||||||
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra,:rerun,:year,:genres,:actors,:collections,:rating,:studio,:seasonEpisode)"
|
|
||||||
table.execute(sql,entryList)
|
|
||||||
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
|
||||||
print("INFO: "+str(timediff.seconds)+" to midnight\033[K",end='\n')
|
|
||||||
endloop = 0
|
|
||||||
while timediff.seconds > 900 and endloop == 0:
|
|
||||||
entryList['id'] = str(int(entryList['id']) + 1)
|
|
||||||
entryList['unix'] = str(time.time())
|
entryList['unix'] = str(time.time())
|
||||||
try:
|
entryList['mediaID'] = "0"
|
||||||
prevEndTimeUnix = float(entryList['startTimeUnix']) + the_show[4]/1000
|
rndsql = "SELECT * FROM shows WHERE (customSectionName NOT LIKE 'playlist' AND duration BETWEEN 6000 and 999000) ORDER BY RANDOM() LIMIT 1"
|
||||||
except:
|
table.execute(rndsql)
|
||||||
prevEndTimeUnix = float(entryList['startTimeUnix'])
|
the_show = table.fetchone()
|
||||||
prevEndTime = datetime.datetime.fromtimestamp(prevEndTimeUnix)
|
entryList['duration'] = str("1,"+str(int(the_show[4] / 60000)))
|
||||||
entryList['startTime'] = prevEndTime + (datetime.datetime.min - prevEndTime) % datetime.timedelta(minutes=entryList['timeShift'])
|
entryList['title'] = the_show[3]
|
||||||
entryList['startTime'] = entryList['startTime'].strftime("%H:%M:%S")
|
entryList['startTime'] = "00:00:00"
|
||||||
entryList['startTimeUnix'] = time.mktime(time.strptime("2000/01/01 "+entryList['startTime'], "%Y/%m/%d %H:%M:%S"))
|
entryList['dayOfWeek'] = "everyday"
|
||||||
print("INFO: "+str(entryList['startTimeUnix'])+" - New Unix Time Start\033[K",end='\n')
|
entryList['startTimeUnix'] = time.mktime(time.strptime("2000/01/01 00:00:00", "%Y/%m/%d %H:%M:%S"))
|
||||||
print("INFO: "+str(entryList['startTime'])+" - New Start Time\033[K",end='\n')
|
entryList['section'] = "TV Shows"
|
||||||
if entryList['startTime'] == "00:00:00":
|
if entryList['startTime'] == "00:00:00":
|
||||||
entryList['strictTime'] = "true"
|
entryList['strictTime'] = "true"
|
||||||
else:
|
else:
|
||||||
entryList['strictTime'] = "secondary"
|
entryList['strictTime'] = "secondary"
|
||||||
|
entryList['endTime'] = datetime.datetime.fromtimestamp(float(entryList['startTimeUnix']) + the_show[4]/1000).strftime("%H:%M:%S")
|
||||||
|
entryList['timeShift'] = 15
|
||||||
|
entryList['overlapMax'] = 15
|
||||||
|
entryList['xtra'] = None
|
||||||
|
entryList['rerun'] = 0
|
||||||
|
entryList['year'] = None
|
||||||
|
entryList['genres'] = None
|
||||||
|
entryList['actors'] = None
|
||||||
|
entryList['collections'] = None
|
||||||
|
entryList['rating'] = None
|
||||||
|
entryList['studio'] = None
|
||||||
|
entryList['seasonEpisode'] = None
|
||||||
|
print("INFO: Adding "+entryList['startTime']+" - "+entryList['title']+"\033[K",end='\n')
|
||||||
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra,rerun,year,genres,actors,collections,rating,studio,seasonEpisode) \
|
||||||
|
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra,:rerun,:year,:genres,:actors,:collections,:rating,:studio,:seasonEpisode)"
|
||||||
|
table.execute(sql,entryList)
|
||||||
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
||||||
maxMS = timediff.seconds * 1000
|
print("INFO: "+str(timediff.seconds)+" to midnight\033[K",end='\n')
|
||||||
if 0 < int(entryList['endTime'].split(':')[1]) <= 15 or 30 < int(entryList['endTime'].split(':')[1]) <= 45:
|
endloop = 0
|
||||||
maxMS = 15*60*1000
|
while timediff.seconds > 900 and endloop == 0:
|
||||||
rndsql = "SELECT * FROM shows WHERE (customSectionName NOT LIKE 'playlist' AND duration BETWEEN ? and ?) ORDER BY RANDOM() LIMIT 1"
|
entryList['id'] = str(int(entryList['id']) + 1)
|
||||||
table.execute(rndsql, ("60000", str(maxMS)))
|
entryList['unix'] = str(time.time())
|
||||||
the_show = table.fetchone()
|
prevEndTimeUnix = float(entryList['startTimeUnix']) + the_show[4]/1000
|
||||||
try:
|
prevEndTime = datetime.datetime.fromtimestamp(prevEndTimeUnix)
|
||||||
|
entryList['startTime'] = prevEndTime + (datetime.datetime.min - prevEndTime) % datetime.timedelta(minutes=entryList['timeShift'])
|
||||||
|
entryList['startTime'] = entryList['startTime'].strftime("%H:%M:%S")
|
||||||
|
entryList['startTimeUnix'] = time.mktime(time.strptime("2000/01/01 "+entryList['startTime'], "%Y/%m/%d %H:%M:%S"))
|
||||||
|
print("INFO: "+str(entryList['startTimeUnix'])+" - New Unix Time Start\033[K",end='\n')
|
||||||
|
print("INFO: "+str(entryList['startTime'])+" - New Start Time\033[K",end='\n')
|
||||||
|
if entryList['startTime'] == "00:00:00":
|
||||||
|
entryList['strictTime'] = "true"
|
||||||
|
else:
|
||||||
|
entryList['strictTime'] = "secondary"
|
||||||
|
timediff = datetime.datetime.strptime("23:59:59", "%H:%M:%S") - datetime.datetime.strptime(entryList['startTime'], "%H:%M:%S")
|
||||||
|
maxMS = timediff.seconds * 1000
|
||||||
|
if 0 < int(entryList['endTime'].split(':')[1]) <= 15 or 30 < int(entryList['endTime'].split(':')[1]) <= 45:
|
||||||
|
maxMS = 15*60*1000
|
||||||
|
rndsql = "SELECT * FROM shows WHERE (customSectionName NOT LIKE 'playlist' AND duration BETWEEN ? and ?) ORDER BY RANDOM() LIMIT 1"
|
||||||
|
table.execute(rndsql, ("60000", str(maxMS)))
|
||||||
|
the_show = table.fetchone()
|
||||||
entryList['duration'] = str("1,"+str(int(the_show[4] / 60000)))
|
entryList['duration'] = str("1,"+str(int(the_show[4] / 60000)))
|
||||||
entryList['endTime'] = datetime.datetime.fromtimestamp(float(entryList['startTimeUnix']) + the_show[4]/1000).strftime("%H:%M:%S")
|
entryList['endTime'] = datetime.datetime.fromtimestamp(float(entryList['startTimeUnix']) + the_show[4]/1000).strftime("%H:%M:%S")
|
||||||
entryList['title'] = the_show[3]
|
entryList['title'] = the_show[3]
|
||||||
@@ -193,73 +196,70 @@ for channel_dir in channel_dirs:
|
|||||||
print("INFO: Adding "+entryList['startTime']+" - "+entryList['title']+"\033[K",end='\n')
|
print("INFO: Adding "+entryList['startTime']+" - "+entryList['title']+"\033[K",end='\n')
|
||||||
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra,rerun,year,genres,actors,collections,rating,studio,seasonEpisode) \
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra,rerun,year,genres,actors,collections,rating,studio,seasonEpisode) \
|
||||||
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra,:rerun,:year,:genres,:actors,:collections,:rating,:studio,:seasonEpisode)"
|
VALUES(:id,:unix,:mediaID,:title,:duration,:startTime,:endTime,:dayOfWeek,:startTimeUnix,:section,:strictTime,:timeShift,:overlapMax,:xtra,:rerun,:year,:genres,:actors,:collections,:rating,:studio,:seasonEpisode)"
|
||||||
except:
|
if entryList['startTime'] != "00:00:00":
|
||||||
timediff = timediff + datetime.timedelta(0,900)
|
table.execute(sql,entryList)
|
||||||
if entryList['startTime'] != "00:00:00":
|
print("INFO: "+str(timediff.seconds)+" to midnight\033[K",end='\n')
|
||||||
table.execute(sql,entryList)
|
else:
|
||||||
print("INFO: "+str(timediff.seconds)+" to midnight\033[K",end='\n')
|
endloop = 1
|
||||||
else:
|
else:
|
||||||
endloop = 1
|
for i in range(0,len(schedule)):
|
||||||
else:
|
try:
|
||||||
for i in range(0,len(schedule)):
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra,rerun,year,genres,actors,collections,rating,studio,seasonEpisode) \
|
||||||
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||||
|
table.execute(sql,schedule[i])
|
||||||
|
except Exception as e:
|
||||||
|
print("ERROR: "+str(e))
|
||||||
|
print("INFO: Importing Legacy Database")
|
||||||
|
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
||||||
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||||
|
table.execute(sql,schedule[i])
|
||||||
|
for i in range(0,len(daily_schedule)):
|
||||||
try:
|
try:
|
||||||
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra,rerun,year,genres,actors,collections,rating,studio,seasonEpisode) \
|
sql = "INSERT INTO daily_schedule(id,unix,mediaID,title,episodeNumber,seasonNumber,showTitle,duration,startTime,endTime,dayOfWeek,sectionType,plexMediaID,customSectionName,notes) \
|
||||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||||
table.execute(sql,schedule[i])
|
table.execute(sql,daily_schedule[i])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("ERROR: "+str(e))
|
print("ERROR: "+str(e))
|
||||||
print("INFO: Importing Legacy Database")
|
print("INFO: Importing Legacy Database")
|
||||||
sql = "INSERT INTO schedule(id,unix,mediaID,title,duration,startTime,endTime,dayOfWeek,startTimeUnix,section,strictTime,timeShift,overlapMax,xtra) \
|
sql = "INSERT INTO daily_schedule(id,unix,mediaID,title,episodeNumber,seasonNumber,showTitle,duration,startTime,endTime,dayOfWeek,sectionType,plexMediaID,customSectionName) \
|
||||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||||
table.execute(sql,schedule[i])
|
table.execute(sql,daily_schedule[i])
|
||||||
for i in range(0,len(daily_schedule)):
|
|
||||||
try:
|
# Step FIVE: Remove any media not in the directories set of commerical archives
|
||||||
sql = "INSERT INTO daily_schedule(id,unix,mediaID,title,episodeNumber,seasonNumber,showTitle,duration,startTime,endTime,dayOfWeek,sectionType,plexMediaID,customSectionName,notes) \
|
print("NOTICE: Trimming database at " + db_path)
|
||||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
os.system('python report_MediaFolders.py')
|
||||||
table.execute(sql,daily_schedule[i])
|
|
||||||
except Exception as e:
|
|
||||||
print("ERROR: "+str(e))
|
|
||||||
print("INFO: Importing Legacy Database")
|
|
||||||
sql = "INSERT INTO daily_schedule(id,unix,mediaID,title,episodeNumber,seasonNumber,showTitle,duration,startTime,endTime,dayOfWeek,sectionType,plexMediaID,customSectionName) \
|
|
||||||
VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
|
||||||
table.execute(sql,daily_schedule[i])
|
|
||||||
|
|
||||||
# Step FIVE: Remove any media not in the directories set of commerical archives
|
|
||||||
print("NOTICE: Trimming database at " + db_path)
|
|
||||||
os.system('python report_MediaFolders.py')
|
|
||||||
try:
|
|
||||||
local_commercials = open('Commercial_Libraries.txt').read().splitlines()
|
local_commercials = open('Commercial_Libraries.txt').read().splitlines()
|
||||||
|
local_movies = open('Movie_Libraries.txt').read().splitlines()
|
||||||
|
local_tvs = open('TV_Libraries.txt').read().splitlines()
|
||||||
|
|
||||||
commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials]
|
commercial_removal = [x for x in global_commercials["Commercials"] if x not in local_commercials]
|
||||||
except:
|
movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies]
|
||||||
print("ERROR: Commercials Not Found")
|
tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs]
|
||||||
local_movies = open('Movie_Libraries.txt').read().splitlines()
|
|
||||||
local_tvs = open('TV_Libraries.txt').read().splitlines()
|
# print(db_path)
|
||||||
|
# print(local_commercials)
|
||||||
movie_removal = [x for x in global_commercials["Movies"] if x not in local_movies]
|
# print(global_commercials["Commercials"])
|
||||||
tv_removal = [x for x in global_commercials["TV Shows"] if x not in local_tvs]
|
# print(commercial_removal)
|
||||||
|
|
||||||
# print(db_path)
|
for commercial in commercial_removal:
|
||||||
# print(local_commercials)
|
sql = "DELETE FROM commercials WHERE customSectionName=?"
|
||||||
# print(global_commercials["Commercials"])
|
table.execute(sql,(commercial,))
|
||||||
# print(commercial_removal)
|
for movie in movie_removal:
|
||||||
|
sql = "DELETE FROM movies WHERE customSectionName=?"
|
||||||
for commercial in commercial_removal:
|
table.execute(sql,(movie,))
|
||||||
sql = "DELETE FROM commercials WHERE customSectionName=?"
|
for tv in tv_removal:
|
||||||
table.execute(sql,(commercial,))
|
sql = "DELETE FROM shows WHERE customSectionName=?"
|
||||||
for movie in movie_removal:
|
table.execute(sql,(tv,))
|
||||||
sql = "DELETE FROM movies WHERE customSectionName=?"
|
sql = "DELETE FROM episodes WHERE customSectionName=?"
|
||||||
table.execute(sql,(movie,))
|
table.execute(sql,(tv,))
|
||||||
for tv in tv_removal:
|
|
||||||
sql = "DELETE FROM shows WHERE customSectionName=?"
|
conn.commit()
|
||||||
table.execute(sql,(tv,))
|
conn.close()
|
||||||
sql = "DELETE FROM episodes WHERE customSectionName=?"
|
|
||||||
table.execute(sql,(tv,))
|
|
||||||
|
|
||||||
conn.commit()
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
os.chdir('..')
|
os.chdir('..')
|
||||||
|
|
||||||
print("NOTICE: " + db_path + " complete! Going to next file")
|
print("NOTICE: " + db_path + " complete! Going to next file")
|
||||||
|
|
||||||
print("NOTICE: Global update COMPLETE")
|
print("NOTICE: Global update COMPLETE")
|
||||||
|
else:
|
||||||
|
print("ERROR: Global update FAILED!")
|
||||||
Reference in New Issue
Block a user