116 lines
3.2 KiB
Python
116 lines
3.2 KiB
Python
import bluread
|
|
|
|
|
|
def get_title_audio_map(device, title):
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
if not 0 <= title < b.NumberOfTitles:
|
|
msg = f"Number of titles of of range. Use a number in [0, {b.NumberOfTitles}["
|
|
raise ValueError(msg)
|
|
|
|
t = b.GetTitle(title)
|
|
|
|
audio_map = set()
|
|
for i in range(0, t.NumberOfClips):
|
|
clip = t.GetClip(i)
|
|
for j in range(0, clip.NumberOfAudiosPrimary):
|
|
a = clip.GetAudio(j)
|
|
audio_map.add((0x1100 + j, a.Language))
|
|
return sorted(audio_map)
|
|
|
|
|
|
def get_title_subtitle_map(device, title):
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
if not 0 <= title < b.NumberOfTitles:
|
|
msg = f"Number of titles of of range. Use a number in [0, {b.NumberOfTitles}["
|
|
raise ValueError(msg)
|
|
|
|
t = b.GetTitle(title)
|
|
|
|
subtitles = set()
|
|
for i in range(0, t.NumberOfClips):
|
|
clip = t.GetClip(i)
|
|
for j in range(0, clip.NumberOfSubtitles):
|
|
s = clip.GetSubtitle(j)
|
|
subtitles.add((0x1200 + j, s.Language))
|
|
return sorted(subtitles)
|
|
|
|
|
|
def get_title_chapters(device, title):
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
if not 0 <= title < b.NumberOfTitles:
|
|
msg = f"Number of titles of of range. Use a number in [0, {b.NumberOfTitles}["
|
|
raise ValueError(msg)
|
|
|
|
t = b.GetTitle(title)
|
|
|
|
chapters = ['00:00:00.000,00']
|
|
|
|
for i in range(1, t.NumberOfChapters + 1):
|
|
c = t.GetChapter(i)
|
|
chapters.append(c.StartFancy)
|
|
|
|
return chapters
|
|
|
|
|
|
def get_num_titles(device):
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
return b.NumberOfTitles
|
|
|
|
|
|
def get_titles(device):
|
|
titles = []
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
for i in range(0, b.NumberOfTitles):
|
|
t = b.GetTitle(i)
|
|
titles.append(f"{t.LengthFancy} - {t.PlaylistNumber}")
|
|
|
|
return titles
|
|
|
|
|
|
def get_title_playlist_number(device, title):
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
return b.GetTitle(b.MainTitleNumber).PlaylistNumber
|
|
|
|
|
|
def get_main_title(device):
|
|
"""Return the main title number and it's playlist number as defined on the disk"""
|
|
with bluread.Bluray(device) as b:
|
|
b.Open()
|
|
|
|
return (b.MainTitleNumber, b.GetTitle(b.MainTitleNumber).PlaylistNumber)
|
|
|
|
|
|
def get_parameterized_mpv_dump_cmd(device):
|
|
"""Return function which accepts title and output_path as arguments and returns the final mpv dump command"""
|
|
cmd = ['mpv', '--quiet',
|
|
'--stream-dump={}',
|
|
'bd://mpls/{}',
|
|
f"--bluray-device={device}"]
|
|
|
|
def parameterized(title, output_path):
|
|
final_cmd = cmd.copy()
|
|
final_cmd[2] = final_cmd[2].format(output_path)
|
|
|
|
title = get_title_playlist_number(device, title)
|
|
final_cmd[3] = final_cmd[3].format(title)
|
|
return final_cmd
|
|
|
|
return parameterized
|
|
|
|
|
|
def get_mpv_dump_cmd(title, output_path, device):
|
|
"""Return a list to call mpv for dumping a BluRay title"""
|
|
return get_parameterized_mpv_dump_cmd(device)(title, output_path)
|