@@ -15,6 +15,7 @@ def parse_args() -> argparse.Namespace:
15
15
parser .add_argument ("--split-longer-than" )
16
16
parser .add_argument ("--min-split-segment" , default = DEFAULT_MIN_SPLIT )
17
17
parser .add_argument ("--delete-video" , action = "store_true" )
18
+ parser .add_argument ("--delete-unplayable" , action = "store_true" )
18
19
parser .add_argument ("--dry-run" , action = "store_true" )
19
20
parser .add_argument ("--verbose" , "-v" , action = "count" , default = 0 )
20
21
@@ -34,8 +35,8 @@ def process_path(
34
35
split_longer_than = None ,
35
36
min_split_segment = nums .human_to_seconds (DEFAULT_MIN_SPLIT ),
36
37
dry_run = False ,
37
- delete_video = False ,
38
38
delete_broken = False ,
39
+ delete_video = False ,
39
40
):
40
41
path = Path (path )
41
42
assert path .exists ()
@@ -90,8 +91,8 @@ def process_path(
90
91
output_path = path .with_suffix (".mka" )
91
92
is_split = always_split or (split_longer_than and duration > split_longer_than )
92
93
if is_split :
93
- splits = (
94
- subprocess .check_output (
94
+ try :
95
+ result = subprocess .check_output (
95
96
[
96
97
"ffmpeg" ,
97
98
"-v" ,
@@ -108,10 +109,14 @@ def process_path(
108
109
"/dev/null" ,
109
110
]
110
111
)
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
114
118
119
+ splits = result .decode ().split ("\n " )
115
120
splits = [line .split ("=" )[1 ] for line in splits if "lavfi.silence_start" in line ]
116
121
117
122
prev = 0.0
@@ -169,6 +174,7 @@ def process_audio():
169
174
always_split = args .always_split ,
170
175
split_longer_than = args .split_longer_than ,
171
176
min_split_segment = args .min_split_segment ,
177
+ delete_broken = args .delete_unplayable ,
172
178
delete_video = args .delete_video ,
173
179
dry_run = args .dry_run ,
174
180
)
0 commit comments