def ToXml(self): doc = docroot() doc.AddChild( dnode('Tags', 'matroskatags.dtd') ) root = doc.AddChild( node('Tags') ) for tag in self._tags: t = root.AddChild( node('Tag') ) tt = t.AddChild( node('Targets') ) for uid in tag.AttachmentUIDs: tt.AddChild( tnode("AttachmentUID", uid) ) for uid in tag.ChapterUIDs: tt.AddChild( tnode("ChapterUID", uid) ) for uid in tag.EditionUIDs: tt.AddChild( tnode("EditionUID", uid) ) for uid in tag.TrackUIDs: tt.AddChild( tnode("TrackUID", uid) ) if tag.TargetType: ttt = tt.AddChild( tnode('TargetType', tag.TargetType) ) if tag.TargetTypeValue: ttv = tt.AddChild( tnode('TargetTypeValue', tag.TargetTypeValue) ) for k in sorted(tag.Simples.keys()): v = tag.Simples[k] s = t.AddChild( node('Simple') ) s.AddChild( tnode('Name', k) ) s.AddChild( tnode('String', v) ) s.AddChild( tnode('TagLanguage', 'eng') ) # XXX: assumed return doc.OuterXMLPretty
def DVDToXML(device, pretty=True): """ Given a device path, this returns a 'pretty' XML string that contains all of the information that this library implements. Pass pretty=False to get a non-pretty version. """ with DVD(device) as d: d.Open() root = node('dvd', numtitles=d.NumberOfTitles, parser="pydvdread %s"%Version) root.AddChild( tnode('device', d.Path) ) root.AddChild( tnode('name', d.GetName(), fancy=d.GetNameTitleCase()) ) root.AddChild( tnode('vmg_id', d.VMGID) ) root.AddChild( tnode('provider_id', d.ProviderID) ) titles = root.AddChild( node('titles') ) for i in range(1, d.NumberOfTitles+1): t = d.GetTitle(i) try: title = titles.AddChild( node('title', idx=t.TitleNum) ) title.AddChild( tnode('length', t.PlaybackTime, fancy=t.PlaybackTimeFancy) ) title.AddChild( node('picture', aspectratio=t.AspectRatio, framerate=t.FrameRate, width=t.Width, height=t.Height) ) title.AddChild( node('angle', num=t.NumberOfAngles) ) except Exception as e: raise Exception('Exception caught when adding title %d' % (i,)) from e audios = title.AddChild( node('audios', num=t.NumberOfAudios) ) for j in range(1, t.NumberOfAudios+1): try: a = t.GetAudio(j) audio = audios.AddChild( node('audio', idx=j, langcode=a.LangCode, language=a.Language, format=a.Format, samplingrate=a.SamplingRate) ) except Exception as e: raise Exception('Exception caught when adding audio %d to title %d' % (j,i)) from e chapters = title.AddChild( node('chapters', num=t.NumberOfChapters) ) for j in range(1, t.NumberOfChapters+1): try: c = t.GetChapter(j) chapter = chapters.AddChild( node('chapter', idx=j) ) chapter.AddChild( tnode('length', c.Length, fancy=c.LengthFancy) ) chapter.AddChild( node('cells', start=c.StartCell, end=c.EndCell) ) except Exception as e: raise Exception('Exception caught when adding chapter %d to title %d' % (j,i)) from e subpictures = title.AddChild( node('subpictures', num=t.NumberOfSubpictures) ) for j in range(1, t.NumberOfSubpictures+1): try: s = t.GetSubpicture(j) subpicture = subpictures.AddChild( node('subpicture', idx=j, langcode=s.LangCode, language=s.Language) ) except Exception as e: raise Exception('Exception caught when adding subtitle %d to title %d' % (j,i)) from e if pretty: return root.OuterXMLPretty else: return root.OuterXML
def ToXml(self): """ Output chapters as XML document in a format it expects. """ doc = docroot() doc.AddChild( dnode('Chapters', 'matroskachapters.dtd') ) root = doc.AddChild( node('Chapters') ) ee = root.AddChild( node('EditionEntry') ) for chap in self._chapters: ca = ee.AddChild( node('ChapterAtom') ) ct = ca.AddChild( node('ChapterTrack') ) ct.AddChild( tnode('ChapterTrackNumber', chap['num']) ) ca.AddChild( tnode('ChapterTimeStart', chap['lengthfancy']) ) cd = ca.AddChild( node('ChapterDisplay') ) cd.AddChild( tnode('ChapterString', chap['title']) ) cd.AddChild( tnode('ChapterLanguage', 'eng') ) # Prefix content with fancy headers return doc.OuterXMLPretty
def BRToXML(device, KEYDB, pretty=True): with Bluray(device, KEYDB) as b: b.Open() root = node('br', numtitles=b.NumberOfTitles, parser="pybluread %s" % Version) root.AddChild(tnode('device', b.Path)) root.AddChild(tnode('KEYDB', b.KeyDB)) titles = root.AddChild(node('titles', main=b.MainTitleNumber)) for tnum in range(b.NumberOfTitles): t = b.GetTitle(tnum) title = titles.AddChild( node('title', idx=tnum, playlist=t.Playlist)) title.AddChild(tnode('length', t.Length, fancy=t.LengthFancy)) angles = title.AddChild(node('angles', num=t.NumberOfAngles)) #print([tnum, 'num chaps', t.NumberOfChapters]) chapters = title.AddChild(node('chapters', num=t.NumberOfChapters)) for cnum in range(1, t.NumberOfChapters + 1): c = t.GetChapter(cnum) #print([tnum, 'chap', cnum, c.ClipNum]) chapter = chapters.AddChild(node('chapter', num=c.Num)) chapter.AddChild(tnode('start', c.Start, fancy=c.StartFancy)) chapter.AddChild(tnode('end', c.End, fancy=c.EndFancy)) chapter.AddChild(tnode('length', c.Length, fancy=c.LengthFancy)) chapter.AddChild(tnode('clipnum', c.ClipNum)) #print([tnum, 'num clips', t.NumberOfClips]) clips = title.AddChild(node('clips', num=t.NumberOfClips)) for cnum in range(t.NumberOfClips): c = t.GetClip(cnum) #print([tnum, cnum, ((c.NumberOfVideosPrimary, c.NumberOfVideosSecondary), (c.NumberOfAudiosPrimary, c.NumberOfAudiosSecondary), c.NumberOfSubtitles)]) clip = clips.AddChild(node('clip', num=c.Num)) videos = clip.AddChild( node('videos', num=c.NumberOfVideosPrimary)) for snum in range(c.NumberOfVideosPrimary): s = c.GetVideo(snum) video = videos.AddChild(node('video', num=s.Num)) video.AddChild(tnode('Language', s.Language)) video.AddChild(tnode('CodingType', s.CodingType)) video.AddChild(tnode('Format', s.Format)) video.AddChild(tnode('Rate', s.Rate)) video.AddChild(tnode('Aspect', s.Aspect)) audios = clip.AddChild( node('audios', num=c.NumberOfAudiosPrimary)) for snum in range(c.NumberOfAudiosPrimary): s = c.GetAudio(snum) audio = audios.AddChild(node('audio', num=s.Num)) audio.AddChild(tnode('Language', s.Language)) audio.AddChild(tnode('CodingType', s.CodingType)) audio.AddChild(tnode('Format', s.Format)) audio.AddChild(tnode('Rate', s.Rate)) subs = clip.AddChild(node('subtitles', num=c.NumberOfSubtitles)) for snum in range(c.NumberOfSubtitles): s = c.GetSubtitle(snum) sub = subs.AddChild(node('subtitle', num=s.Num)) sub.AddChild(tnode('Language', s.Language)) if pretty: return root.OuterXMLPretty else: return root.outerXML
def DVDToXML(device, pretty=True): """ Given a device path, this returns a 'pretty' XML string that contains all of the information that this library implements. Pass pretty=False to get a non-pretty version. """ with DVD(device) as d: d.Open() root = node('dvd', numtitles=d.NumberOfTitles, parser="pydvdread %s" % Version) root.AddChild(tnode('device', d.Path)) root.AddChild(tnode('name', d.GetName(), fancy=d.GetNameTitleCase())) root.AddChild(tnode('vmg_id', d.VMGID)) root.AddChild(tnode('provider_id', d.ProviderID)) titles = root.AddChild(node('titles')) for i in range(1, d.NumberOfTitles + 1): t = d.GetTitle(i) try: title = titles.AddChild(node('title', idx=t.TitleNum)) title.AddChild( tnode('length', t.PlaybackTime, fancy=t.PlaybackTimeFancy)) title.AddChild( node('picture', aspectratio=t.AspectRatio, framerate=t.FrameRate, width=t.Width, height=t.Height)) title.AddChild(node('angle', num=t.NumberOfAngles)) except Exception as e: raise Exception('Exception caught when adding title %d' % (i, )) from e audios = title.AddChild(node('audios', num=t.NumberOfAudios)) for j in range(1, t.NumberOfAudios + 1): try: a = t.GetAudio(j) audio = audios.AddChild( node('audio', idx=j, langcode=a.LangCode, language=a.Language, format=a.Format, samplingrate=a.SamplingRate)) except Exception as e: raise Exception( 'Exception caught when adding audio %d to title %d' % (j, i)) from e chapters = title.AddChild(node('chapters', num=t.NumberOfChapters)) for j in range(1, t.NumberOfChapters + 1): try: c = t.GetChapter(j) chapter = chapters.AddChild(node('chapter', idx=j)) chapter.AddChild( tnode('length', c.Length, fancy=c.LengthFancy)) chapter.AddChild( node('cells', start=c.StartCell, end=c.EndCell)) except Exception as e: raise Exception( 'Exception caught when adding chapter %d to title %d' % (j, i)) from e subpictures = title.AddChild( node('subpictures', num=t.NumberOfSubpictures)) for j in range(1, t.NumberOfSubpictures + 1): try: s = t.GetSubpicture(j) subpicture = subpictures.AddChild( node('subpicture', idx=j, langcode=s.LangCode, language=s.Language)) except Exception as e: raise Exception( 'Exception caught when adding subtitle %d to title %d' % (j, i)) from e if pretty: return root.OuterXMLPretty else: return root.OuterXML
def BRToXML(device, KEYDB, pretty=True): with Bluray(device, KEYDB) as b: b.Open() root = node('br', numtitles=b.NumberOfTitles, parser="pybluread %s"%Version) root.AddChild( tnode('device', b.Path) ) root.AddChild( tnode('KEYDB', b.KeyDB) ) titles = root.AddChild( node('titles', main=b.MainTitleNumber) ) for tnum in range(b.NumberOfTitles): t = b.GetTitle(tnum) title = titles.AddChild( node('title', idx=tnum, playlist=t.Playlist) ) title.AddChild( tnode('length', t.Length, fancy=t.LengthFancy) ) angles = title.AddChild( node('angles', num=t.NumberOfAngles) ) #print([tnum, 'num chaps', t.NumberOfChapters]) chapters = title.AddChild( node('chapters', num=t.NumberOfChapters) ) for cnum in range(1,t.NumberOfChapters+1): c = t.GetChapter(cnum) #print([tnum, 'chap', cnum, c.ClipNum]) chapter = chapters.AddChild( node('chapter', num=c.Num) ) chapter.AddChild( tnode('start', c.Start, fancy=c.StartFancy) ) chapter.AddChild( tnode('end', c.End, fancy=c.EndFancy) ) chapter.AddChild( tnode('length', c.Length, fancy=c.LengthFancy) ) chapter.AddChild( tnode('clipnum', c.ClipNum) ) #print([tnum, 'num clips', t.NumberOfClips]) clips = title.AddChild( node('clips', num=t.NumberOfClips) ) for cnum in range(t.NumberOfClips): c = t.GetClip(cnum) #print([tnum, cnum, ((c.NumberOfVideosPrimary, c.NumberOfVideosSecondary), (c.NumberOfAudiosPrimary, c.NumberOfAudiosSecondary), c.NumberOfSubtitles)]) clip = clips.AddChild( node('clip', num=c.Num) ) videos = clip.AddChild( node('videos', num=c.NumberOfVideosPrimary) ) for snum in range(c.NumberOfVideosPrimary): s = c.GetVideo(snum) video = videos.AddChild( node('video', num=s.Num) ) video.AddChild( tnode('Language', s.Language) ) video.AddChild( tnode('CodingType', s.CodingType) ) video.AddChild( tnode('Format', s.Format) ) video.AddChild( tnode('Rate', s.Rate) ) video.AddChild( tnode('Aspect', s.Aspect) ) audios = clip.AddChild( node('audios', num=c.NumberOfAudiosPrimary) ) for snum in range(c.NumberOfAudiosPrimary): s = c.GetAudio(snum) audio = audios.AddChild( node('audio', num=s.Num) ) audio.AddChild( tnode('Language', s.Language) ) audio.AddChild( tnode('CodingType', s.CodingType) ) audio.AddChild( tnode('Format', s.Format) ) audio.AddChild( tnode('Rate', s.Rate) ) subs = clip.AddChild( node('subtitles', num=c.NumberOfSubtitles) ) for snum in range(c.NumberOfSubtitles): s = c.GetSubtitle(snum) sub = subs.AddChild( node('subtitle', num=s.Num) ) sub.AddChild( tnode('Language', s.Language) ) if pretty: return root.OuterXMLPretty else: return root.outerXML