Exemple #1
0
def split(args):
    """必要なストリームのみ残す"""

    remained_pids = set()
    with tsopen(args.inpath) as ts:
        pat = next(ts.sections(ProgramAssociationSection))
        # 置き換え後の新しいPAT
        new_pat = replace_pat(pat._packet)
        remained_pmt_pid = next(pat.pmt_pids)
        remained_pids.add(remained_pmt_pid)
        ProgramMapSection._pids = [remained_pmt_pid]
        pmt = next(ts.sections(ProgramMapSection))
        # PCRと最初のストリームのPIDを残す
        remained_pids.add(pmt.PCR_PID)
        remained_pids.update(pmt_map.elementary_PID for pmt_map in pmt.maps
                             if pmt_map.stream_type != 0x0d)

    pat_pid = ProgramAssociationSection._pids[0]
    with tsopen(args.inpath) as ts, open(args.outpath, 'wb') as out:
        for p in ts:
            pid = packet.pid(p)
            if pid == pat_pid:
                out.write(p[:5])
                out.write(new_pat)
            elif pid in remained_pids:
                out.write(p)
Exemple #2
0
def vtt(args):
    if args.outpath == '-':
        outpath = sys.stdout.fileno()
    else:
        outpath = args.outpath
    with tsopen(args.inpath) as ts, open(outpath, 'w') as out:
        SynchronizedPacketizedElementaryStream._pids = [ts.get_caption_pid()]

        base_pcr = next(ts.pcrs())
        base_time = next(ts.sections(TimeOffsetSection)).JST_time

        out.write('WEBVTT\n\n')
        number = 1
        base_date = datetime(2000, 1, 1)
        #fixme: DRCS処理を隠蔽して字幕文字オブジェクトだけ返すラッパークラスが必要
        # for caption in ts.captions(drcs=True, color=True):
        #     print(caption.datetime, caption.body) みたいな
        prev_caption_date = None
        prev_caption = ''
        for spes in ts.sections(SynchronizedPacketizedElementaryStream):
            caption_date = base_date + (spes.pts - base_pcr)
            for data in spes.data_units:
                if data.data_unit_parameter == 0x20:
                    caption = WebVTTCProfileString(data.data_unit_data)
                    if prev_caption_date:
                        out.write('{}\n{}.{:03d} --> {}.{:03d}\n{}\n\n'.format(
                            number, prev_caption_date.strftime('%H:%M:%S'),
                            prev_caption_date.microsecond // 1000,
                            caption_date.strftime('%H:%M:%S'),
                            caption_date.microsecond // 1000,
                            prev_caption))
                    number += 1
                    prev_caption_date = caption_date
                    prev_caption = caption
        if prev_caption:
            out.write('{}\n{}.{:03d} --> {}.{:03d}\n{}\n\n'.format(
                number, prev_caption_date.strftime('%H:%M:%S'),
                prev_caption_date.microsecond // 1000,
                caption_date.strftime('%H:%M:%S'),
                caption_date.microsecond // 1000,
                prev_caption))
Exemple #3
0
                        nibble.content_nibble_level_2])
                self.user_nibble.append(nibble.user_nibble)
                self.user_genre.append(USER_TYPE.get(nibble.user_nibble, ''))
        detail = [('', [])]
        for eed in desc.get(ExtendedEventDescriptor, []):
            for item in eed.items:
                key = item.item_description_char
                # タイトルが空か一つ前と同じ場合は本文を一つ前のものにつなげる
                if str(key) == '' or str(detail[-1][0]) == str(key):
                    detail[-1][1].extend(item.item_char)
                else:
                    detail.append((key, item.item_char))
        detail = [(str(key), AribString(value)) for key, value in detail[1:]]
        if detail:
            self.detail = dict(detail)
            self.longdesc = '\n'.join("{}\n{}\n".format(key, value)
                                      for key, value in detail)


if __name__ == '__main__':
    from subprocess import Popen, PIPE
    from ariblib import tsopen
    recpt1 = Popen(['recpt1', '236', '130', '-'], stdout=PIPE)
    with tsopen(recpt1.stdout.fileno()) as ts:
        for event in events(ts):
            print(dir(event))
            try:
                print(event.title, event.free_CA_mode)
            except:
                pass
Exemple #4
0
                    CONTENT_TYPE[nibble.content_nibble_level_1][1]
                                [nibble.content_nibble_level_2])
                self.user_nibble.append(nibble.user_nibble)
                self.user_genre.append(USER_TYPE.get(nibble.user_nibble, ''))
        detail = [('', [])]
        for eed in desc.get(ExtendedEventDescriptor, []):
            for item in eed.items:
                key = item.item_description_char
                # タイトルが空か一つ前と同じ場合は本文を一つ前のものにつなげる
                if str(key) == '' or str(detail[-1][0]) == str(key):
                    detail[-1][1].extend(item.item_char)
                else:
                    detail.append((key, item.item_char))
        detail = [(str(key), AribString(value)) for key, value in detail[1:]]
        if detail:
            self.detail = dict(detail)
            self.longdesc = '\n'.join(
                "{}\n{}\n".format(key, value) for key, value in detail)

if __name__ == '__main__':
    from subprocess import Popen, PIPE
    from ariblib import tsopen
    recpt1 = Popen(['recpt1', '236', '130', '-'], stdout=PIPE)
    with tsopen(recpt1.stdout.fileno()) as ts:
        for event in events(ts):
            print(dir(event))
            try:
                print(event.title, event.free_CA_mode)
            except:
                pass