diff --git a/PseudoChannel.py b/PseudoChannel.py index 7900ec9..68d8aa1 100644 --- a/PseudoChannel.py +++ b/PseudoChannel.py @@ -47,6 +47,8 @@ class PseudoChannel(): APP_TIME_FORMAT_STR = '%I:%M:%S %p' + COMMERCIAL_PADDING_IN_SECONDS = config.commercialPadding + DEBUG = config.debug_mode def __init__(self): @@ -573,7 +575,8 @@ class PseudoChannel(): if self.USING_COMMERCIAL_INJECTION: self.commercials = PseudoChannelCommercial( - self.db.get_commercials() + self.db.get_commercials(), + self.COMMERCIAL_PADDING_IN_SECONDS ) schedule = self.db.get_schedule() @@ -816,7 +819,7 @@ class PseudoChannel(): def run_commercial_injection(self): - print "#### Running commercial injection." + """print "#### Running commercial injection." self.commercials = PseudoChannelCommercial( self.db.get_commercials(), @@ -825,7 +828,9 @@ class PseudoChannel(): commercials_to_inject = self.commercials.get_commercials_to_inject() - print commercials_to_inject + print commercials_to_inject""" + + pass def run(self): diff --git a/pseudo_config.py b/pseudo_config.py index a0fbb0e..c7cd7dd 100644 --- a/pseudo_config.py +++ b/pseudo_config.py @@ -63,6 +63,9 @@ useGoogleCalendar = False useCommercialInjection = True +# How many seconds to pad commercials between each other / other media +commercialPadding = 5 + dailyUpdateTime = "12:00 AM" debug_mode = False diff --git a/src/PseudoChannelCommercial.py b/src/PseudoChannelCommercial.py index 866bbe1..0104967 100644 --- a/src/PseudoChannelCommercial.py +++ b/src/PseudoChannelCommercial.py @@ -11,12 +11,15 @@ from src import Commercial class PseudoChannelCommercial(): MIN_DURATION_FOR_COMMERCIAL = 10 #seconds + COMMERCIAL_PADDING_IN_SECONDS = 0 daily_schedule = [] - def __init__(self, commercials): + def __init__(self, commercials, commercialPadding): self.commercials = commercials + self.COMMERCIAL_PADDING_IN_SECONDS = commercialPadding + def get_commercials_to_inject(self): self.go() @@ -86,6 +89,16 @@ class PseudoChannelCommercial(): def timedelta_milliseconds(self, td): return td.days*86400000 + td.seconds*1000 + td.microseconds/1000 + def pad_the_commercial_dur(self, commercial): + + commercial_as_list = list(commercial) + + commercial_as_list[4] = int(commercial_as_list[4]) + (self.COMMERCIAL_PADDING_IN_SECONDS * 1000) + + commercial = tuple(commercial_as_list) + + return commercial + def get_commercials_to_place_between_media(self, last_ep, now_ep): #print last_ep.end_time, now_ep.start_time @@ -114,7 +127,12 @@ class PseudoChannelCommercial(): while curr_item_start_time > new_commercial_start_time and (count) < len(self.commercials)*100: - random_commercial = self.get_random_commercial() + random_commercial_without_pad = self.get_random_commercial() + + """ + Padding the duration of commercials as per user specified padding. + """ + random_commercial = self.pad_the_commercial_dur(random_commercial_without_pad) #new_commercial_seconds = (int(random_commercial[4])/1000)%60