Skip to content

Commit 387d077

Browse files
committed
fix: sort formats on language preference to prevent downloading auto dubs
Fixes #592
1 parent 9e293ea commit 387d077

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src-tauri/src/runners/ytdlp_args.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ pub fn build_format_args(
1515
args.push("-f".into());
1616
args.push("ba/best".into());
1717

18-
args.push("-S".into());
19-
if let Some(abr) = format_options.abr {
20-
args.push(format!("abr~{abr}"));
18+
let mut sort_fields = Vec::new();
19+
sort_fields.push("lang".into());
20+
21+
if let Some(asr) = format_options.asr {
22+
sort_fields.push(format!("asr~{asr}"));
2123
} else {
22-
args.push("abr".into());
24+
sort_fields.push("asr".into());
2325
}
26+
27+
let sort_arg = sort_fields.join(",");
28+
29+
args.push("-S".into());
30+
args.push(sort_arg);
2431
}
2532

2633
TrackType::Video | TrackType::Both => {
@@ -33,6 +40,8 @@ pub fn build_format_args(
3340
args.push(selector);
3441

3542
let mut sort_fields = Vec::new();
43+
sort_fields.push("lang".into());
44+
3645
if let Some(h) = format_options.height {
3746
sort_fields.push(format!("res:{h}"));
3847
} else {
@@ -45,11 +54,12 @@ pub fn build_format_args(
4554
}
4655

4756
if matches!(output_settings.video.container, VideoContainer::Mp4) {
48-
sort_fields.push("ext:mp4:m4a".into());
57+
sort_fields.push("ext:mp4".into());
58+
sort_fields.push("ext:m4a".into());
59+
} else {
60+
sort_fields.push("ext".into());
4961
}
5062

51-
sort_fields.push("ext".into());
52-
5363
let sort_arg = sort_fields.join(",");
5464

5565
args.push("-S".into());
@@ -174,13 +184,13 @@ mod tests {
174184
}
175185

176186
#[test]
177-
fn audio_format_args_without_abr() {
187+
fn audio_format_args_without_asr() {
178188
let format_options = make_audio_format_options(None);
179189
let settings = OutputSettings::default();
180190

181191
let args = build_format_args(&format_options, &settings);
182192

183-
let expected: Vec<String> = vec!["-x", "-f", "ba/best", "-S", "abr"]
193+
let expected: Vec<String> = vec!["-x", "-f", "ba/best", "-S", "lang,asr"]
184194
.into_iter()
185195
.map(String::from)
186196
.collect();
@@ -189,13 +199,13 @@ mod tests {
189199
}
190200

191201
#[test]
192-
fn audio_format_args_with_abr() {
193-
let format_options = make_audio_format_options(Some(192));
202+
fn audio_format_args_with_asr() {
203+
let format_options = make_audio_format_options(Some(44));
194204
let settings = OutputSettings::default();
195205

196206
let args = build_format_args(&format_options, &settings);
197207

198-
let expected: Vec<String> = vec!["-x", "-f", "ba/best", "-S", "abr~192"]
208+
let expected: Vec<String> = vec!["-x", "-f", "ba/best", "-S", "lang,asr~44"]
199209
.into_iter()
200210
.map(String::from)
201211
.collect();
@@ -210,7 +220,7 @@ mod tests {
210220

211221
let args = build_format_args(&format_options, &settings);
212222

213-
let expected: Vec<String> = vec!["-f", "bv", "-S", "res:720,fps:60,ext:mp4:m4a,ext"]
223+
let expected: Vec<String> = vec!["-f", "bv", "-S", "lang,res:720,fps:60,ext:mp4,ext:m4a"]
214224
.into_iter()
215225
.map(String::from)
216226
.collect();
@@ -227,7 +237,7 @@ mod tests {
227237

228238
let args = build_format_args(&format_options, &settings);
229239

230-
let expected: Vec<String> = vec!["-f", "bv", "-S", "res:720,fps:60,ext"]
240+
let expected: Vec<String> = vec!["-f", "bv", "-S", "lang,res:720,fps:60,ext"]
231241
.into_iter()
232242
.map(String::from)
233243
.collect();
@@ -246,7 +256,7 @@ mod tests {
246256
"-f",
247257
"bv*+ba/bv+ba/best",
248258
"-S",
249-
"res:1080,fps:30,ext:mp4:m4a,ext",
259+
"lang,res:1080,fps:30,ext:mp4,ext:m4a",
250260
]
251261
.into_iter()
252262
.map(String::from)

0 commit comments

Comments
 (0)