Updated time-shift logic.

This commit is contained in:
Justin Emter
2017-07-20 14:32:28 -07:00
parent 1b936adc3c
commit 2c57dc3c8d
3 changed files with 89 additions and 50 deletions

View File

@@ -23,12 +23,6 @@ class PseudoChannel():
MEDIA = [] MEDIA = []
TIME_GAP = 15
OVERLAP_GAP = 15
OVERLAP_MAX = 30
def __init__(self): def __init__(self):
self.db = PseudoChannelDatabase("pseudo-channel.db") self.db = PseudoChannelDatabase("pseudo-channel.db")
@@ -71,7 +65,7 @@ class PseudoChannel():
def update_db(self): def update_db(self):
print("Updating Local Database") print("#### Updating Local Database")
self.db.create_tables() self.db.create_tables()
@@ -83,20 +77,38 @@ class PseudoChannel():
sectionMedia = self.PLEX.library.section(section.title).all() sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress(0, len(sectionMedia), prefix = 'Progress '+section.title+":", suffix = 'Complete', bar_length = 50) self.print_progress(
0,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
for i, media in enumerate(sectionMedia): for i, media in enumerate(sectionMedia):
self.db.add_movies_to_db(1, media.title, media.duration) self.db.add_movies_to_db(1, media.title, media.duration)
self.print_progress(i + 1, len(sectionMedia), prefix = 'Progress '+section.title+":", suffix = 'Complete', bar_length = 50) self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
elif section.title == "TV Shows": elif section.title == "TV Shows":
sectionMedia = self.PLEX.library.section(section.title).all() sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress(0, len(sectionMedia), prefix = 'Progress '+section.title+":", suffix = 'Complete', bar_length = 50) self.print_progress(
0,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
for i, media in enumerate(sectionMedia): for i, media in enumerate(sectionMedia):
@@ -110,7 +122,13 @@ class PseudoChannel():
self.db.add_shows_to_db(2, media.title, media.duration, '', backgroundImgURL) self.db.add_shows_to_db(2, media.title, media.duration, '', backgroundImgURL)
self.print_progress(i + 1, len(sectionMedia), prefix = 'Progress '+section.title+":", suffix = 'Complete', bar_length = 50) self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
#add all episodes of each tv show to episodes table #add all episodes of each tv show to episodes table
episodes = self.PLEX.library.section(section.title).get(media.title).episodes() episodes = self.PLEX.library.section(section.title).get(media.title).episodes()
@@ -121,23 +139,49 @@ class PseudoChannel():
if duration: if duration:
self.db.add_episodes_to_db(4, episode.title, duration, episode.index, episode.parentIndex, media.title) self.db.add_episodes_to_db(
4,
episode.title,
duration,
episode.index,
episode.parentIndex,
media.title
)
else: else:
self.db.add_episodes_to_db(4, episode.title, 0, episode.index, episode.parentIndex, media.title) self.db.add_episodes_to_db(
4,
episode.title,
0,
episode.index,
episode.parentIndex,
media.title
)
elif section.title == "Commercials": elif section.title == "Commercials":
sectionMedia = self.PLEX.library.section(section.title).all() sectionMedia = self.PLEX.library.section(section.title).all()
self.print_progress(0, len(sectionMedia), prefix = 'Progress '+section.title+":", suffix = 'Complete', bar_length = 50) self.print_progress(
0,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
for i, media in enumerate(sectionMedia): for i, media in enumerate(sectionMedia):
self.db.add_commercials_to_db(3, media.title, media.duration) self.db.add_commercials_to_db(3, media.title, media.duration)
self.print_progress(i + 1, len(sectionMedia), prefix = 'Progress '+section.title+":", suffix = 'Complete', bar_length = 50) self.print_progress(
i + 1,
len(sectionMedia),
prefix = 'Progress '+section.title+":",
suffix = 'Complete',
bar_length = 50
)
def update_schedule(self): def update_schedule(self):
@@ -273,20 +317,24 @@ class PseudoChannel():
self.TIME_GAP = timeGap self.TIME_GAP = timeGap
self.OVERLAP_GAP = timeGap
self.OVERLAP_MAX = overlapMax self.OVERLAP_MAX = overlapMax
time1 = datetime.datetime.strptime(prevEndTime, '%I:%M %p').strftime('%-I:%M %p') time1 = prevEndTime.strftime('%-I:%M %p')
timeB = intendedStartTime.strftime('%-I:%M %p') timeB = datetime.datetime.strptime(intendedStartTime, '%I:%M %p').strftime('%-I:%M %p')
print "++++ Previous End Time: ", time1, "Intended start time: ", timeB
timeDiff = self.time_diff(time1, timeB) timeDiff = self.time_diff(time1, timeB)
print("timeDiff "+ str(timeDiff)) """print("timeDiff "+ str(timeDiff))
print("startTimeUNIX: "+ str(intendedStartTime)) print("startTimeUNIX: "+ str(intendedStartTime))"""
newTimeObj = intendedStartTime.strftime('%-I:%M %p') newTimeObj = timeB
newStartTime = intendedStartTime.strftime('%-I:%M %p') newStartTime = timeB
''' '''
* *
@@ -294,9 +342,6 @@ class PseudoChannel():
* *
''' '''
if timeDiff < 0: if timeDiff < 0:
print("There is overlap ")
''' '''
* *
* If there is an overlap, then the overlapGap var in config will determine the next increment. If it is set to "15", then the show will will bump up to the next 15 minute interval past the hour. * If there is an overlap, then the overlapGap var in config will determine the next increment. If it is set to "15", then the show will will bump up to the next 15 minute interval past the hour.
@@ -304,7 +349,7 @@ class PseudoChannel():
''' '''
timeset=[datetime.time(h,m).strftime("%H:%M") for h,m in itertools.product(xrange(0,24),xrange(0,60,int(self.OVERLAP_GAP)))] timeset=[datetime.time(h,m).strftime("%H:%M") for h,m in itertools.product(xrange(0,24),xrange(0,60,int(self.OVERLAP_GAP)))]
print(timeset) #print(timeset)
timeSetToUse = None timeSetToUse = None
@@ -319,8 +364,7 @@ class PseudoChannel():
if theTimeSetInterval >= prevEndTime: if theTimeSetInterval >= prevEndTime:
print("Setting new time by interval... " + time) print "++++ There is overlap. Setting new time-interval:", theTimeSetInterval
print("made it!")
newStartTime = theTimeSetInterval newStartTime = theTimeSetInterval
@@ -339,25 +383,17 @@ class PseudoChannel():
# print(timeset) # print(timeset)
timeSetToUse = None
for time in timeset: for time in timeset:
#print(time)
theTimeSetInterval = datetime.datetime.strptime(time, '%H:%M') theTimeSetInterval = datetime.datetime.strptime(time, '%H:%M')
tempTimeTwoStr = datetime.datetime.strptime(time1, '%I:%M %p').strftime('%H:%M') tempTimeTwoStr = datetime.datetime.strptime(time1, '%I:%M %p').strftime('%H:%M')
formatted_time_two = datetime.datetime.strptime(tempTimeTwoStr, '%H:%M') formatted_time_two = datetime.datetime.strptime(tempTimeTwoStr, '%H:%M')
# print(theTimeSetInterval)
# print(prevEndTime)
if theTimeSetInterval >= formatted_time_two: if theTimeSetInterval >= formatted_time_two:
print("Setting new time by interval... " + time) print "++++ Setting new time-interval:", theTimeSetInterval
print("made it!")
newStartTime = theTimeSetInterval newStartTime = theTimeSetInterval
@@ -381,7 +417,7 @@ class PseudoChannel():
def generate_daily_schedule(self): def generate_daily_schedule(self):
print("Generating Daily Schedule") print("#### Generating Daily Schedule")
schedule = self.db.get_schedule() schedule = self.db.get_schedule()
@@ -519,32 +555,32 @@ class PseudoChannel():
if previous_episode != None: if previous_episode != None:
previous_episode = entry
natural_start_time = datetime.datetime.strptime(entry.natural_start_time, '%I:%M %p') natural_start_time = datetime.datetime.strptime(entry.natural_start_time, '%I:%M %p')
natural_end_time = entry.natural_end_time natural_end_time = entry.natural_end_time
if entry.is_strict_time.lower() == "true": if entry.is_strict_time.lower() == "true":
print "Using strict-time: {}".format(entry.title) print "++++ Strict-time: {}".format(entry.title)
entry.end_time = self.get_end_time_from_duration(entry.start_time, entry.duration) entry.end_time = self.get_end_time_from_duration(entry.start_time, entry.duration)
self.db.add_media_to_daily_schedule(entry) self.db.add_media_to_daily_schedule(entry)
previous_episode = entry
else: else:
print "NOT strict-time. {}".format(entry.title) print "++++ NOT strict-time: {}".format(entry.title)
new_starttime = self.calculate_start_time( new_starttime = self.calculate_start_time(
entry.natural_start_time, previous_episode.end_time,
entry.end_time, entry.natural_start_time,
previous_episode.time_shift, previous_episode.time_shift,
previous_episode.overlap_max previous_episode.overlap_max
) )
print new_starttime print "++++ New start time:", new_starttime
entry.start_time = datetime.datetime.strptime(new_starttime, '%I:%M %p').strftime('%-I:%M %p') entry.start_time = datetime.datetime.strptime(new_starttime, '%I:%M %p').strftime('%-I:%M %p')
@@ -552,6 +588,8 @@ class PseudoChannel():
self.db.add_media_to_daily_schedule(entry) self.db.add_media_to_daily_schedule(entry)
previous_episode = entry
else: else:
self.db.add_media_to_daily_schedule(entry) self.db.add_media_to_daily_schedule(entry)
@@ -566,7 +604,7 @@ if __name__ == '__main__':
#pseudo_channel.update_db() #pseudo_channel.update_db()
#pseudo_channel.update_schedule() pseudo_channel.update_schedule()
pseudo_channel.generate_daily_schedule() pseudo_channel.generate_daily_schedule()

View File

@@ -10,10 +10,11 @@
<weekends></weekends> <weekends></weekends>
<everyday></everyday> <everyday></everyday>
<weekdays> <weekdays>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">6:00 AM</time> <default title="Seinfeld" type="series" ></default>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">6:30 AM</time> <time title="Looney Tunes" type="series" strict-time="false" time-shift="1" overlap-max="">6:00 AM</time>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">7:00 AM</time> <time title="Looney Tunes" type="series" strict-time="false" time-shift="1" overlap-max="">6:30 AM</time>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="5" overlap-max="">7:30 AM</time> <time title="Looney Tunes" type="series" strict-time="false" time-shift="1" overlap-max="">7:00 AM</time>
<time title="Looney Tunes" type="series" strict-time="false" time-shift="1" overlap-max="">7:30 AM</time>
<time title="Garfield &#38; Friends" type="series" strict-time="false" time-shift="5" overlap-max="">8:00 AM</time> <time title="Garfield &#38; Friends" type="series" strict-time="false" time-shift="5" overlap-max="">8:00 AM</time>
<time title="Garfield &#38; Friends" type="series" strict-time="false" time-shift="5" overlap-max="">8:30 AM</time> <time title="Garfield &#38; Friends" type="series" strict-time="false" time-shift="5" overlap-max="">8:30 AM</time>

View File

@@ -247,7 +247,7 @@ class PseudoChannelDatabase():
def add_media_to_daily_schedule(self, media): def add_media_to_daily_schedule(self, media):
print "Adding media to db", media.title, media.start_time print "#### Adding media to db", media.title, media.start_time
self.add_daily_schedule_to_db( self.add_daily_schedule_to_db(
0, 0,