Esempio n. 1
0
    def main(self):
        time_until_next_play = None
        schedule_deque = deque()
        media_schedule = None

        while True:
            try:
                print 'time_until_next_play: %s' % time_until_next_play
                if time_until_next_play is None:
                    self.logger.info("waiting indefinitely for schedule")
                    media_schedule = self.queue.get(block=True)
                else:
                    self.logger.info("waiting %ss until next scheduled item" %
                            time_until_next_play)
                    media_schedule = self.queue.get(block=True, \
                            timeout=time_until_next_play)
            except Empty, e:
                print 'queue empty: %s' % e
                #Time to push a scheduled item.
                media_item = schedule_deque.popleft()
                self.pypo_liquidsoap.play(media_item)
                if len(schedule_deque):
                    time_until_next_play = \
                            pure.date_interval_to_seconds(
                                schedule_deque[0]['start'] - datetime.now())
                                #schedule_deque[0]['start'] - timedelta(milliseconds=int(schedule_deque[0]['fade_cross'] * 1000)) - datetime.now())
                    if time_until_next_play < 0:
                        time_until_next_play = 0
                else:
                    time_until_next_play = None
            else:
                # self.logger.info("New schedule received: %s", media_schedule)
                self.logger.info("New schedule received")

                #new schedule received. Replace old one with this.
                schedule_deque.clear()

                keys = sorted(media_schedule.keys())
                print 'KEYS:'
                print keys
                for i in keys:
                    print 'keys loop - i: %s' % i
                    schedule_deque.append(media_schedule[i])

                if len(keys):
                    time_until_next_play = pure.date_interval_to_seconds(\
                            keys[0] - datetime.now())
                else:
                    time_until_next_play = None
Esempio n. 2
0
    def modify_cue_point(self, link):
        if not self.is_file(link):
            return

        tnow = datetime.now()

        link_start = link['start']

        diff_td = tnow - link_start
        diff_sec = pure.date_interval_to_seconds(diff_td)

        if diff_sec > 0:
            self.logger.debug("media item was supposed to start %s ago. " + 
                    "Preparing to start..", diff_sec)
            original_cue_in_td = timedelta(seconds=float(link['cue_in']))
            link['cue_in'] = \
                pure.date_interval_to_seconds(original_cue_in_td) + diff_sec
Esempio n. 3
0
    def modify_cue_point(self, link):
        if not self.is_file(link):
            return

        tnow = datetime.utcnow()

        link_start = link['start']

        diff_td = tnow - link_start
        diff_sec = pure.date_interval_to_seconds(diff_td)

        if diff_sec > 0:
            self.logger.debug("media item was supposed to start %s ago. " + 
                    "Preparing to start..", diff_sec)
            original_cue_in_td = timedelta(seconds=float(link['cue_in']))
            link['cue_in'] = \
                pure.date_interval_to_seconds(original_cue_in_td) + diff_sec
Esempio n. 4
0
    def main(self):
        time_until_next_play = None
        schedule_deque = deque()
        media_schedule = None

        while True:
            try:
                if time_until_next_play is None:
                    self.logger.info("waiting indefinitely for schedule")
                    media_schedule = self.queue.get(block=True)
                else:
                    self.logger.info("waiting %ss until next scheduled item" %
                            time_until_next_play)
                    media_schedule = self.queue.get(block=True, \
                            timeout=time_until_next_play)
            except Empty, e:
                #Time to push a scheduled item.
                media_item = schedule_deque.popleft()
                self.pypo_liquidsoap.play(media_item)
                if len(schedule_deque):
                    time_until_next_play = \
                            pure.date_interval_to_seconds(
                                schedule_deque[0]['start'] - datetime.utcnow())
                    if time_until_next_play < 0:
                        time_until_next_play = 0
                else:
                    time_until_next_play = None
            else:
                self.logger.info("New schedule received: %s", media_schedule)

                #new schedule received. Replace old one with this.
                schedule_deque.clear()

                keys = sorted(media_schedule.keys())
                for i in keys:
                    schedule_deque.append(media_schedule[i])

                if len(keys):
                    time_until_next_play = pure.date_interval_to_seconds(\
                            keys[0] - datetime.utcnow())
                else:
                    time_until_next_play = None
Esempio n. 5
0
    def separate_present_future(self, media_schedule):
        tnow = datetime.utcnow()

        present = []
        future = {}

        sorted_keys = sorted(media_schedule.keys())
        for mkey in sorted_keys:
            media_item = media_schedule[mkey]

            diff_td = tnow - media_item['start']
            diff_sec = pure.date_interval_to_seconds(diff_td)

            if diff_sec >= 0:
                present.append(media_item)
            else:
                future[media_item['start']] = media_item

        return present, future