From f8cc274fc68372df94733d23830ce0c0a37d5f4e Mon Sep 17 00:00:00 2001 From: Moe Fwacky Date: Wed, 28 Jul 2021 23:28:07 -0700 Subject: [PATCH] bug fixes Fixed bug causing infinite loop in daily schedule generation --- both-dir/PseudoChannel.py | 12 +++++++++--- both-dir/src/PseudoChannelDatabase.py | 19 ++++++++++--------- main-dir/Global_DailySchedule.py | 2 +- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/both-dir/PseudoChannel.py b/both-dir/PseudoChannel.py index 1222f91..467886f 100644 --- a/both-dir/PseudoChannel.py +++ b/both-dir/PseudoChannel.py @@ -757,7 +757,10 @@ class PseudoChannel(): max = int(minmax) max = max * 60000 if str(entry[3]).lower() == "random": - media_id = 999 + if entry[14] == 0: + media_id = 998 + else: + media_id = 999 advance_episode = "no" sections = self.PLEX.library.sections() shows_list = [] @@ -771,6 +774,7 @@ class PseudoChannel(): shows = self.PLEX.library.section(theSection.title) print("NOTICE: Getting Show That Matches Data Filters") the_show = self.db.get_random_show_data("TV Shows",int(min),int(max),entry[15],entry[16],entry[17],entry[18],entry[19],entry[20]) + print("INFO: " + the_show[3]) if (the_show == None): print("NOTICE: Failed to get shows with data filters, trying with less") the_show = self.db.get_random_show_data("TV Shows",int(min),int(max),entry[15],None,None,None,entry[19],None) @@ -796,14 +800,16 @@ class PseudoChannel(): episode_duration = int(next_episode[4]) print("INFO: Random Selection: "+next_episode[7]+" - S"+str(next_episode[6])+"E"+str(next_episode[5])+" - "+next_episode[3]) else: - if entry[2] == 999: + print("INFO: entry[2] = " + str(entry[2])) + print("INFO: media_id = " + str(media_id)) + if entry[2] == 999 or media_id == 999: media_id = 999 print("ACTION: Choosing random episode of "+the_show[3].upper()) try: next_episode = self.db.get_random_episode_of_show_by_data(the_show[2],int(min),int(max),entry[15],entry[21].split(',')[0],entry[21].split(',')[1]) except: next_episode = self.db.get_random_episode_of_show_by_data(the_show[2],int(min),int(max),entry[15]) - elif entry[2] == 998: + elif entry[2] == 998 or media_id == 998: media_id = 998 if entry[14] == 1: print("ACTION: Choosing last episode of " +the_show[3].upper()) diff --git a/both-dir/src/PseudoChannelDatabase.py b/both-dir/src/PseudoChannelDatabase.py index 4055c52..321b198 100644 --- a/both-dir/src/PseudoChannelDatabase.py +++ b/both-dir/src/PseudoChannelDatabase.py @@ -9,7 +9,7 @@ class PseudoChannelDatabase(): def __init__(self, db): - self.db = db + self = db self.conn = sqlite3.connect(self.db, check_same_thread=False) self.cursor = self.conn.cursor() @@ -457,6 +457,7 @@ class PseudoChannelDatabase(): """Database functions. Updaters, etc. """ + def update_shows_table_with_last_episode(self, showTitle, lastEpisodeTitle): sql1 = "UPDATE shows SET lastEpisodeTitle = ? WHERE title LIKE ? COLLATE NOCASE" self.cursor.execute(sql1, (lastEpisodeTitle, showTitle, )) @@ -817,18 +818,18 @@ class PseudoChannelDatabase(): return media_item def get_first_episode(self, tvshow): - sql = ("SELECT * FROM episodes WHERE ( showTitle LIKE ? AND " - "episodeNumber LIKE (SELECT MIN(episodeNumber) FROM episodes WHERE (showTitle LIKE ?)) AND " - "seasonNumber LIKE (SELECT MIN(seasonNumber) FROM episodes WHERE (showTitle LIKE ?))) COLLATE NOCASE") - self.cursor.execute(sql, (tvshow, tvshow, tvshow, )) + + sql = ("SELECT id, unix, mediaID, title, duration, MIN(episodeNumber), MIN(seasonNumber), " + "showTitle, plexMediaID, customSectionName FROM episodes WHERE ( showTitle LIKE ?) COLLATE NOCASE") + self.cursor.execute(sql, (tvshow, )) first_episode = self.cursor.fetchone() return first_episode def get_first_episode_by_id(self, tvshow): - sql = ("SELECT * FROM episodes WHERE ( mediaID LIKE ? AND " - "episodeNumber LIKE (SELECT MIN(episodeNumber) FROM episodes WHERE (mediaID LIKE ?)) AND " - "seasonNumber LIKE (SELECT MIN(seasonNumber) FROM episodes WHERE (mediaID LIKE ?))) COLLATE NOCASE") - self.cursor.execute(sql, (tvshow, tvshow, tvshow, )) + + sql = ("SELECT id, unix, mediaID, title, duration, MIN(episodeNumber), MIN(seasonNumber), " + "showTitle, plexMediaID, customSectionName FROM episodes WHERE ( mediaID LIKE ?) COLLATE NOCASE") + self.cursor.execute(sql, (tvshow, )) first_episode = self.cursor.fetchone() return first_episode diff --git a/main-dir/Global_DailySchedule.py b/main-dir/Global_DailySchedule.py index da1ce50..74be8d8 100644 --- a/main-dir/Global_DailySchedule.py +++ b/main-dir/Global_DailySchedule.py @@ -20,6 +20,6 @@ os.chdir(os.path.abspath(os.path.dirname(__file__))) for channel in channelsList: os.chdir(os.path.abspath(os.path.dirname(__file__))+'/pseudo-channel_'+channel) print("GENERATING SCHEDULE FOR CHANNEL "+channel) - process = subprocess.call(["python", "-u", "PseudoChannel.py", "-g"], stdout=None, stderr=None, stdin=None) + process = subprocess.call(["python3", "-u", "PseudoChannel.py", "-g"], stdout=None, stderr=None, stdin=None) os.chdir('../') print("ALERT: ALL DAILY SCHEDULE GENERATION COMPLETE") \ No newline at end of file