129 lines
3.6 KiB
Python
129 lines
3.6 KiB
Python
from datetime import timedelta
|
|
|
|
import dvdread
|
|
|
|
|
|
# ## What I need from dvdread
|
|
# - audio information for each title
|
|
# - count
|
|
# - language code
|
|
# - subpicture (subtitle) information for each title
|
|
# - count
|
|
# - language code
|
|
# - chapter information per title
|
|
# - count
|
|
# - length
|
|
# - title information
|
|
# - number of titles
|
|
# - length ("playback time fancy")
|
|
|
|
# python3-mediainfodll
|
|
# In [71]: for i in range(308):
|
|
# ...: if not mi.GetI(MediaInfoDLL3.Stream.Video, 0, i, 1):
|
|
# ...: continue
|
|
# ...: print('{}: {} - {}'.format(mi.GetI(MediaInfoDLL3.Stream.Video, 0, i, 4)
|
|
# ...: , mi.GetI(MediaInfoDLL3.Stream.Video, 0, i, 1), mi.GetI(MediaInfoDLL3.Strea
|
|
# ...: m.Video, 0, i, 6)))
|
|
|
|
|
|
def get_title_audio_map(device, title):
|
|
with dvdread.DVD(device) as d:
|
|
d.Open()
|
|
|
|
if not 0 <= title <= d.NumberOfTitles:
|
|
msg = f"Number of titles of of range. Use a number in [0, {d.NumberOfTitles}["
|
|
raise ValueError(msg)
|
|
|
|
# DvdRead starts counting titles at 1, we start at 0
|
|
title += 1
|
|
t = d.GetTitle(title)
|
|
audio_map = []
|
|
for i in range(1, t.NumberOfAudios + 1):
|
|
a = t.GetAudio(i)
|
|
audio_map.append((128 + i - 1, a.LangCode))
|
|
return audio_map
|
|
|
|
|
|
def get_title_subtitle_map(device, title):
|
|
with dvdread.DVD(device) as d:
|
|
d.Open()
|
|
|
|
if not 0 <= title <= d.NumberOfTitles:
|
|
msg = f"Number of titles of of range. Use a number in [0, {d.NumberOfTitles}["
|
|
raise ValueError(msg)
|
|
|
|
# DvdRead starts counting titles at 1, we start at 0
|
|
title += 1
|
|
t = d.GetTitle(title)
|
|
subtitles = []
|
|
for i in range(1, t.NumberOfSubpictures + 1):
|
|
s = t.GetSubpicture(i)
|
|
subtitles.append((0x20 + i - 1, s.LangCode))
|
|
return subtitles
|
|
|
|
|
|
def get_title_chapters(device, title):
|
|
with dvdread.DVD(device) as d:
|
|
d.Open()
|
|
|
|
if not 0 <= title <= d.NumberOfTitles:
|
|
msg = f"Number of titles of of range. Use a number in [0, {d.NumberOfTitles}["
|
|
raise ValueError(msg)
|
|
|
|
# we usually start at 0, but dvdread starts at 1
|
|
title += 1
|
|
t = d.GetTitle(title)
|
|
|
|
# we need to put in at least a microsecond to get the full
|
|
# 0:00:00.000001 format
|
|
td = timedelta(microseconds=1)
|
|
chapters = [str(td)]
|
|
|
|
for i in range(1, t.NumberOfChapters + 1):
|
|
td += timedelta(milliseconds=t.GetChapter(i).Length)
|
|
chapters.append(str(td))
|
|
|
|
return chapters
|
|
|
|
|
|
def get_num_titles(device):
|
|
with dvdread.DVD(device) as d:
|
|
d.Open()
|
|
|
|
return d.NumberOfTitles
|
|
|
|
|
|
def get_titles(device):
|
|
titles = []
|
|
with dvdread.DVD(device) as d:
|
|
d.Open()
|
|
|
|
for i in range(1, d.NumberOfTitles + 1):
|
|
t = d.GetTitle(i)
|
|
titles.append(t.PlaybackTimeFancy)
|
|
|
|
return titles
|
|
|
|
|
|
def get_parameterized_mpv_dump_cmd(device=None):
|
|
"""Return function which accepts title and output_path as arguments and returns the final mpv dump command"""
|
|
cmd = ['mpv', '--quiet',
|
|
'--stream-dump={}',
|
|
'dvd://{}']
|
|
|
|
if device:
|
|
cmd.append(f"--dvd-device={device}")
|
|
|
|
def parameterized(title, output_path):
|
|
final_cmd = cmd.copy()
|
|
final_cmd[2] = final_cmd[2].format(output_path)
|
|
final_cmd[3] = final_cmd[3].format(title)
|
|
return final_cmd
|
|
|
|
return parameterized
|
|
|
|
|
|
def get_mpv_dump_cmd(title, output_path, device=None):
|
|
"""Return a list to call mpv for dumping a BluRay title"""
|
|
return get_parameterized_mpv_dump_cmd(device=device)(title, output_path)
|