Skip to content

Commit 621e944

Browse files
committed
fs_extract process_audio
1 parent 6929814 commit 621e944

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

xklb/fs_extract.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,14 @@ def extract_metadata(mp_args, path) -> Optional[Dict[str, int]]:
212212

213213
if getattr(mp_args, "process", False):
214214
if objects.is_profile(mp_args, DBType.audio) and Path(path).suffix not in [".opus", ".mka"]:
215-
path = media["path"] = str(
216-
process_audio.process_path(
217-
path,
218-
split_longer_than=2160 if "audiobook" in path.lower() else None,
219-
delete_broken=getattr(mp_args, "delete_unplayable", False),
220-
)
215+
result = process_audio.process_path(
216+
path,
217+
split_longer_than=2160 if "audiobook" in path.lower() else None,
218+
delete_broken=getattr(mp_args, "delete_unplayable", False),
221219
)
220+
if result is None:
221+
return None
222+
path = media["path"] = str(result)
222223

223224
return media
224225

xklb/scripts/process_audio.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def parse_args() -> argparse.Namespace:
1515
parser.add_argument("--split-longer-than")
1616
parser.add_argument("--min-split-segment", default=DEFAULT_MIN_SPLIT)
1717
parser.add_argument("--delete-video", action="store_true")
18+
parser.add_argument("--delete-unplayable", action="store_true")
1819
parser.add_argument("--dry-run", action="store_true")
1920
parser.add_argument("--verbose", "-v", action="count", default=0)
2021

@@ -34,8 +35,8 @@ def process_path(
3435
split_longer_than=None,
3536
min_split_segment=nums.human_to_seconds(DEFAULT_MIN_SPLIT),
3637
dry_run=False,
37-
delete_video=False,
3838
delete_broken=False,
39+
delete_video=False,
3940
):
4041
path = Path(path)
4142
assert path.exists()
@@ -90,8 +91,8 @@ def process_path(
9091
output_path = path.with_suffix(".mka")
9192
is_split = always_split or (split_longer_than and duration > split_longer_than)
9293
if is_split:
93-
splits = (
94-
subprocess.check_output(
94+
try:
95+
result = subprocess.check_output(
9596
[
9697
"ffmpeg",
9798
"-v",
@@ -108,10 +109,14 @@ def process_path(
108109
"/dev/null",
109110
]
110111
)
111-
.decode()
112-
.split("\n")
113-
)
112+
except subprocess.CalledProcessError:
113+
log.exception("Splits could not be identified. Likely broken file: %s", path)
114+
if delete_broken:
115+
path.unlink()
116+
return None
117+
raise
114118

119+
splits = result.decode().split("\n")
115120
splits = [line.split("=")[1] for line in splits if "lavfi.silence_start" in line]
116121

117122
prev = 0.0
@@ -169,6 +174,7 @@ def process_audio():
169174
always_split=args.always_split,
170175
split_longer_than=args.split_longer_than,
171176
min_split_segment=args.min_split_segment,
177+
delete_broken=args.delete_unplayable,
172178
delete_video=args.delete_video,
173179
dry_run=args.dry_run,
174180
)

0 commit comments

Comments
 (0)