Exemplo n.º 1
0
    def stop_live_recording(cls, db_session, recording):
        with cls._live_recordings_to_recording_thread_lock:
            try:
                cls._live_recordings_to_recording_thread[
                    recording.id].force_stop()

                del cls._live_recordings_to_recording_thread[recording.id]
            except KeyError:
                recording = DatabaseAccess.query_recording(
                    db_session, recording.id)

                if recording is not None:
                    if recording.status == RecordingStatus.LIVE.value:
                        segment_row = DatabaseAccess.query_segments_count(
                            db_session, recording.id)

                        if segment_row is not None and segment_row.count > 0:
                            recording.status = RecordingStatus.PERSISTED.value
                else:
                    raise RecordingNotFoundError
Exemplo n.º 2
0
    def _initialize_recordings(cls, db_session):
        deleted_recordings_log_message = []
        loaded_recordings_log_message = []

        unformatted_message_to_log = 'Provider          => {0}\n' \
                                     'Channel number    => {1}\n' \
                                     'Channel name      => {2}\n' \
                                     'Program title     => {3}\n' \
                                     'Start date & time => {4}\n' \
                                     'End date & time   => {5}\n' \
                                     'Status            => {6}\n'

        for recording in DatabaseAccess.query_recordings(db_session):
            current_date_time_in_utc = datetime.now(pytz.utc)

            formatted_message_to_log = unformatted_message_to_log.format(
                recording.provider, recording.channel_number,
                recording.channel_name, recording.program_title,
                recording.start_date_time_in_utc.astimezone(
                    tzlocal.get_localzone()).strftime('%Y-%m-%d %H:%M:%S%z'),
                recording.end_date_time_in_utc.astimezone(
                    tzlocal.get_localzone()).strftime('%Y-%m-%d %H:%M:%S%z'),
                recording.status)

            if current_date_time_in_utc >= recording.end_date_time_in_utc:
                if recording.status == RecordingStatus.LIVE.value:
                    segment_row = DatabaseAccess.query_segments_count(
                        db_session, recording.id)

                    if segment_row is not None and segment_row.count > 0:
                        recording.status = RecordingStatus.PERSISTED.value

                        loaded_recordings_log_message.append(
                            formatted_message_to_log)
                    else:
                        DatabaseAccess.delete_recording(
                            db_session, recording.id)

                        deleted_recordings_log_message.append(
                            formatted_message_to_log)
                elif recording.status == RecordingStatus.SCHEDULED.value:
                    DatabaseAccess.delete_recording(db_session, recording.id)

                    deleted_recordings_log_message.append(
                        formatted_message_to_log)
            else:
                loaded_recordings_log_message.append(formatted_message_to_log)

        if deleted_recordings_log_message:
            deleted_recordings_log_message.insert(
                0, 'Deleted expired recording{0}\n'.format(
                    's' if len(deleted_recordings_log_message) > 1 else ''))

            logger.debug('\n'.join(deleted_recordings_log_message).strip())

        if loaded_recordings_log_message:
            loaded_recordings_log_message.insert(
                0, 'Loaded recording{0}\n'.format(
                    's' if len(loaded_recordings_log_message) > 1 else ''))

            logger.debug('\n'.join(loaded_recordings_log_message).strip())