def to_dict(self):
     return {
         'id': self.id,
         'title': self.title,
         'start': duration_to_str(self.start_time),
         'end': duration_to_str(self.end_time)
     }
Beispiel #2
0
 def cb(ffmpeg_progress: FFMpegProgress):
     if duration:
         remaining_time = duration_to_str(
             ffmpeg_progress.remaining_time(duration))
         d.gauge_update(percent=int(
             ffmpeg_progress.progress(duration) * 100),
                        text='Remaining: {}'.format(remaining_time),
                        update_text=True)
def print_metadata(input, show_popup=False, interlace='none'):
    extractor = create_metadata_extractor()
    meta = extractor.extract(input, interlace != 'none')
    o = []

    o.append(os.path.basename(input))
    o.append(output('Directory: {}', os.path.dirname(input)))
    size = os.path.getsize(input)
    if meta.title:
        o.append(output('Title: {}', meta.title))
    o.append(output('Size: {}', sizeof_fmt(size)))
    o.append(output('Format: {}', meta.format))

    durations = [float(s.duration) for s in meta.streams if s.duration]
    if len(durations) > 0:
        o.append(output('Duration: {}', duration_to_str(max(durations))))

    o.append(output('Bitrate: {}', bitrate_to_str(meta.bit_rate)))
    for video in meta.video_streams:
        if video.bit_depth:
            o.append(output('Video: {} {} bit ({}x{})', video.codec,video.bit_depth, video.width, video.height))
        else:
            o.append(output('Video: {} ({}x{})', video.codec, video.width, video.height))

    audio_streams = []
    for audio in meta.audio_streams:
        audio_streams.append((audio.codec, audio.language, audio.channel_layout))
    audio_streams.sort()
    o.append(output('Audio:'))
    for a in audio_streams:
        o.append(output('  {} ({}, {})', *a))

    subtitles = [s.language for s in meta.subtitle_streams]
    if len(subtitles) == 0:
        subtitles = ['None']
    o.append(output('Subtitles: {}', ', '.join(subtitles)))
    o.append(output('Ripped: {}', meta.ripped))

    if meta.interlace_report:
        if interlace == 'summary':
            o.append(output('Interlaced: {}', meta.interlace_report.is_interlaced()))
        elif interlace == 'report':
            o.append(output('Interlaced:'))
            single = meta.interlace_report.single
            o.append(output('  Single: TFF={}, BFF={}, Progressive={}, Undetermined={} ({:.2f}%)', single.tff, single.bff,
                            single.progressive, single.undetermined, single.ratio * 100))
            multi = meta.interlace_report.multi
            o.append(output('  Multi: TFF={}, BFF={}, Progressive={}, Undetermined={} ({:.2f}%)', multi.tff, multi.bff,
                            multi.progressive, multi.undetermined, multi.ratio * 100))

    final = '\n'.join(o)
    if show_popup:
        popup(final)
    else:
        print(final)
 def to_dict(self):
     d = {
         'index': self.index,
         'title': self.title,
         'type': self.type,
         'codec': self.codec,
         'codec_long_name': self.codec_long_name,
         'duration': self.duration,
         'duration_str': duration_to_str(self.duration) if self.duration else None
     }
     if self.is_audio():
         d['channels'] = self.channels
         d['channel_layout'] = self.channel_layout
     if self.is_audio() or self.is_subtitle():
         d['language'] = self.language
     if self.is_video():
         d['width'] = self.width
         d['height'] = self.height
         d['bit_depth'] = self.bit_depth
     d['tags'] = self.tags
     return d
def create_table_object(input_to_cmd, interlace='none'):
    from media_management_scripts.utils import create_metadata_extractor
    from media_management_scripts.support.formatting import sizeof_fmt, duration_to_str
    extractor = create_metadata_extractor()
    metadatas = [
        extractor.extract(i, interlace != 'none') for i in input_to_cmd
    ]
    header = [''] + [os.path.basename(f.file) for f in metadatas]
    num_audio = max([len(m.audio_streams) for m in metadatas])
    rows = [
        'Size', 'Duration', 'Bitrate (kb/s)', 'Video Codec', 'Resolution',
        'Audio'
    ]
    for i in range(1, num_audio):
        rows.append('')
    rows.append('Subtitles')
    file_columns = [rows]
    first_size = os.path.getsize(metadatas[0].file)
    for m in metadatas:
        data = []
        size = os.path.getsize(m.file)
        size_ratio = '{:.1f}%'.format(size / first_size * 100)
        data.append('{} ({})'.format(sizeof_fmt(size), size_ratio))
        data.append(
            duration_to_str(m.estimated_duration) if m.
            estimated_duration else '')
        data.append('{:.2f}'.format(m.bit_rate / 1024.0))
        video = m.video_streams[0]
        data.append(video.codec)
        data.append('{}x{}'.format(video.width, video.height))
        for a in m.audio_streams:
            data.append('{} ({}, {})'.format(a.codec, a.language,
                                             a.channel_layout))
        for i in range(len(m.audio_streams), num_audio):
            data.append('')
        data.append(','.join([s.language for s in m.subtitle_streams]))
        file_columns.append(data)
    table = list(map(list, zip(*file_columns)))
    return header, table
 def to_dict(self):
     return {
         'file': self.file,
         'title': self.title,
         'duration': self.estimated_duration,
         'duration_str': duration_to_str(self.estimated_duration) if self.estimated_duration else None,
         'size': self.size,
         'size_str': sizeof_fmt(self.size),
         'resolution': self.resolution._name_ if self.resolution else None,
         'bit_rate': self.bit_rate,
         'bit_rate_str': bitrate_to_str(self.bit_rate),
         'ripped': self.ripped,
         'format': self.format,
         'format_long_name': self.format_long_name,
         'mime_type': self.mime_type,
         'tags': self.tags,
         # 'streams': [s.to_dict() for s in self.streams],
         'video_streams': [s.to_dict() for s in self.video_streams],
         'audio_streams': [s.to_dict() for s in self.audio_streams],
         'subtitle_streams': [s.to_dict() for s in self.subtitle_streams],
         'other_streams': [s.to_dict() for s in self.other_streams],
         'chapters': [c.to_dict() for c in self.chapters] if self.chapters else [],
         'interlace': self.interlace_report.to_dict() if self.interlace_report else None
     }