Random TV Series episode capabilities added

Now, there is the ability to run random episodes in a TV series, without ruining your place in the series designation.

To do so, simply edit your xml file so the lines  title=<<name of show as usual>>, and the line's type=random.
This commit is contained in:
mutto233
2018-07-07 23:09:27 -04:00
parent bf994a91da
commit c94eb7dd68
2 changed files with 30 additions and 16 deletions

View File

@@ -312,7 +312,7 @@ class PseudoChannel():
"everyday" "everyday"
] ]
section_dict = { section_dict = {
"TV Shows" : ["series", "shows", "tv", "episodes", "tv shows", "show"], "TV Shows" : ["series", "shows", "tv", "episodes", "tv shows", "show","random"],
"Movies" : ["movie", "movies", "films", "film"], "Movies" : ["movie", "movies", "films", "film"],
"Videos" : ["video", "videos", "vid"], "Videos" : ["video", "videos", "vid"],
"Music" : ["music", "songs", "song", "tune", "tunes"] "Music" : ["music", "songs", "song", "tune", "tunes"]
@@ -328,6 +328,10 @@ class PseudoChannel():
natural_start_time = self.translate_time(time.text) natural_start_time = self.translate_time(time.text)
natural_end_time = 0 natural_end_time = 0
section = key section = key
if section == "TV Shows" and time.attrib['type'] == "random":
mediaID_place=9999
else:
mediaID_place=0
day_of_week = child.tag day_of_week = child.tag
strict_time = time.attrib['strict-time'] if 'strict-time' in time.attrib else 'false' strict_time = time.attrib['strict-time'] if 'strict-time' in time.attrib else 'false'
time_shift = time.attrib['time-shift'] if 'time-shift' in time.attrib else '1' time_shift = time.attrib['time-shift'] if 'time-shift' in time.attrib else '1'
@@ -348,7 +352,7 @@ class PseudoChannel():
print "Adding: ", time.tag, section, time.text, time.attrib['title'] print "Adding: ", time.tag, section, time.text, time.attrib['title']
self.db.add_schedule_to_db( self.db.add_schedule_to_db(
0, # mediaID mediaID_place, # mediaID
title, # title title, # title
0, # duration 0, # duration
natural_start_time, # startTime natural_start_time, # startTime
@@ -540,6 +544,8 @@ class PseudoChannel():
if section == "TV Shows": if section == "TV Shows":
if str(entry[3]).lower() == "random": if str(entry[3]).lower() == "random":
next_episode = self.db.get_random_episode() next_episode = self.db.get_random_episode()
elif entry[2] == 9999:
next_episode = self.db.get_random_episode_alternate(entry[3])
else: else:
next_episode = self.db.get_next_episode(entry[3]) next_episode = self.db.get_next_episode(entry[3])
if next_episode != None: if next_episode != None:
@@ -1088,16 +1094,16 @@ if __name__ == '__main__':
prevItem_time = datetime.datetime.strptime(''.join(str(prevItem[8])), "%I:%M:%S %p") prevItem_time = datetime.datetime.strptime(''.join(str(prevItem[8])), "%I:%M:%S %p")
elapsed_timeTwo = prevItem_time - now elapsed_timeTwo = prevItem_time - now
offsetTwo = int(abs(elapsed_timeTwo.total_seconds() * 1000)) offsetTwo = int(abs(elapsed_timeTwo.total_seconds() * 1000))
if prevItem_time.hour > now.hour: if prevItem_time.hour > now.hour:
print "we have a day skip" print "we have a day skip"
now = now.replace(hour=23,minute=59,second=59) now = now.replace(hour=23,minute=59,second=59)
elapsed_timeTwo = prevItem_time-now elapsed_timeTwo = prevItem_time-now
mnight = now.replace(hour=0,minute=0,second=0) mnight = now.replace(hour=0,minute=0,second=0)
now = datetime.datetime.now() now = datetime.datetime.now()
now = now.replace(year=1900, month=1, day=1) now = now.replace(year=1900, month=1, day=1)
elapsed_timeTwo = elapsed_timeTwo + (mnight-now) elapsed_timeTwo = elapsed_timeTwo + (mnight-now)
print elapsed_timeTwo.total_seconds() print elapsed_timeTwo.total_seconds()
offsetTwo = int(abs(elapsed_timeTwo.total_seconds() * 1000)) offsetTwo = int(abs(elapsed_timeTwo.total_seconds() * 1000))
if pseudo_channel.DEBUG: if pseudo_channel.DEBUG:
print "+++++ Closest media was the next media " \ print "+++++ Closest media was the next media " \
"but we were in the middle of something so triggering that instead." "but we were in the middle of something so triggering that instead."

View File

@@ -514,6 +514,14 @@ class PseudoChannelDatabase():
self.cursor.execute(sql) self.cursor.execute(sql)
return self.cursor.fetchone() return self.cursor.fetchone()
####mutto233 made this one####
def get_random_episode_alternate(self,series):
sql = "SELECT * FROM episodes WHERE (showTitle LIKE ? AND id IN (SELECT id FROM episodes ORDER BY RANDOM() LIMIT 1))"
self.cursor.execute(sql, (series, ))
return self.cursor.fetchone()
####mutto233 made this one####
def get_random_movie(self): def get_random_movie(self):
sql = "SELECT * FROM movies WHERE id IN (SELECT id FROM movies ORDER BY RANDOM() LIMIT 1)" sql = "SELECT * FROM movies WHERE id IN (SELECT id FROM movies ORDER BY RANDOM() LIMIT 1)"