From 3482b96f09ba460b8a2148c83df12ed76ba3ea85 Mon Sep 17 00:00:00 2001 From: Sting <loic.allegre@ensiie.fr> Date: Sun, 26 Nov 2023 08:06:45 -0800 Subject: [PATCH] Replace sed call --- autokara/preprocess/lyrics.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/autokara/preprocess/lyrics.py b/autokara/preprocess/lyrics.py index 5e286aa..f0191f2 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 -- GitLab