diff --git a/autokara/preprocess/lyrics.py b/autokara/preprocess/lyrics.py index 5e286aae1c1003b46f52a6f88e1b81a88d7104d1..f0191f2f3d6d94bf0c8bb4b189571db92cbb0fe6 100644 --- a/autokara/preprocess/lyrics.py +++ b/autokara/preprocess/lyrics.py @@ -3,6 +3,8 @@ import argparse import subprocess import shlex from pathlib import Path +import re + @@ -12,7 +14,9 @@ def extract_subtitles(source_file, output_file=None): else: out_path = output_file - data = subprocess.run(f'mkvmerge --identify "{source_file:s}" | sed -n "s/Track ID \\([[:digit:]]*\\).*subtitles.*/\\1/p"', capture_output=True, shell=True, text=True) - track_id = data.stdout.rstrip() + data = subprocess.run(f'mkvmerge --identify "{source_file:s}"', capture_output=True, shell=True, text=True) + RGX_TRACK = re.compile(r"Track ID (\d+): subtitles") + matches = RGX_TRACK.findall(data.stdout) + track_id = matches[0][0] subprocess.call(shlex.split(f'mkvextract "{source_file:s}" tracks "{track_id:s}":"{out_path:s}"')) \ No newline at end of file