mirror of
https://github.com/FakeTV/pseudo-channel.git
synced 2025-12-22 03:03:33 +00:00
Adjusted logic to calculate start / stop times for commercials. This should solve the commercials getting cut off. I do hoever see some issues, pushing anyway.
This commit is contained in:
@@ -81,6 +81,9 @@ class PseudoChannelCommercial():
|
|||||||
|
|
||||||
prev_item = entry
|
prev_item = entry
|
||||||
|
|
||||||
|
def timedelta_milliseconds(self, td):
|
||||||
|
return td.days*86400000 + td.seconds*1000 + td.microseconds/1000
|
||||||
|
|
||||||
def get_commercials_to_place_between_media(self, last_ep, now_ep):
|
def get_commercials_to_place_between_media(self, last_ep, now_ep):
|
||||||
|
|
||||||
print last_ep.end_time, now_ep.start_time
|
print last_ep.end_time, now_ep.start_time
|
||||||
@@ -91,27 +94,39 @@ class PseudoChannelCommercial():
|
|||||||
|
|
||||||
time_diff = (curr_item_start_time - prev_item_end_time)
|
time_diff = (curr_item_start_time - prev_item_end_time)
|
||||||
|
|
||||||
days, hours, minutes = time_diff.days, time_diff.seconds // 3600, time_diff.seconds // 60 % 60
|
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
commercial_list = []
|
commercial_list = []
|
||||||
|
|
||||||
commercial_dur_sum = 0
|
commercial_dur_sum = 0
|
||||||
|
|
||||||
while int(time_diff.total_seconds()) >= commercial_dur_sum and (count*10000) < len(self.commercials):
|
time_diff_milli = self.timedelta_milliseconds(time_diff)
|
||||||
|
|
||||||
|
last_commercial = None
|
||||||
|
|
||||||
|
time_watch = prev_item_end_time
|
||||||
|
|
||||||
|
print "here", time_diff.seconds
|
||||||
|
|
||||||
|
while curr_item_start_time > time_watch and (count) < len(self.commercials):
|
||||||
|
|
||||||
random_commercial = self.get_random_commercial()
|
random_commercial = self.get_random_commercial()
|
||||||
|
|
||||||
new_commercial_seconds = (int(random_commercial[4])/1000)%60
|
last_commercial = random_commercial
|
||||||
|
|
||||||
commercial_dur_sum += new_commercial_seconds
|
#new_commercial_seconds = (int(random_commercial[4])/1000)%60
|
||||||
|
|
||||||
new_commercial_start_time = prev_item_end_time + datetime.timedelta(seconds=commercial_dur_sum)
|
new_commercial_milli = int(random_commercial[4])
|
||||||
|
|
||||||
new_commercial_end_time = new_commercial_start_time + datetime.timedelta(seconds=int(new_commercial_seconds))
|
commercial_dur_sum += new_commercial_milli
|
||||||
|
|
||||||
formatted_time_for_new_commercial = new_commercial_start_time.strftime('%I:%M:%S %p')
|
new_commercial_start_time = time_watch
|
||||||
|
|
||||||
|
new_commercial_end_time = new_commercial_start_time
|
||||||
|
|
||||||
|
new_commercial_end_time += datetime.timedelta(milliseconds=int(new_commercial_milli))
|
||||||
|
|
||||||
|
formatted_time_for_new_commercial = time_watch.strftime('%I:%M:%S %p')
|
||||||
|
|
||||||
new_commercial = Commercial(
|
new_commercial = Commercial(
|
||||||
"Commercials",
|
"Commercials",
|
||||||
@@ -126,7 +141,9 @@ class PseudoChannelCommercial():
|
|||||||
"", # plex_media_id
|
"", # plex_media_id
|
||||||
)
|
)
|
||||||
|
|
||||||
if int(time_diff.total_seconds()) < commercial_dur_sum:
|
time_watch += datetime.timedelta(milliseconds=commercial_dur_sum)
|
||||||
|
|
||||||
|
if time_diff_milli < commercial_dur_sum or new_commercial_end_time > curr_item_start_time:
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user