Skip to content

Commit 2154f46

Browse files
committed
api/soundcloud: prefer progressive format over hls
1 parent eae6a7a commit 2154f46

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

api/src/processing/services/soundcloud.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,25 @@ async function findClientID() {
4040
} catch {}
4141
}
4242

43+
const findBestForPreset = (transcodings, preset) => {
44+
let inferior;
45+
for (const entry of transcodings) {
46+
if (entry.snipped) {
47+
continue;
48+
}
49+
50+
if (entry.preset === preset) {
51+
if (entry?.format?.protocol === 'progressive') {
52+
return entry;
53+
}
54+
55+
inferior = entry;
56+
}
57+
}
58+
59+
return inferior;
60+
}
61+
4362
export default async function(obj) {
4463
const clientId = await findClientID();
4564
if (!clientId) return { error: "fetch.fail" };
@@ -89,9 +108,9 @@ export default async function(obj) {
89108
}
90109

91110
let bestAudio = "opus",
92-
selectedStream = json.media.transcodings.find(v => v.preset === "opus_0_0");
111+
selectedStream = findBestForPreset(json.media.transcodings, "opus_0_0");
93112

94-
const mp3Media = json.media.transcodings.find(v => v.preset === "mp3_0_0");
113+
const mp3Media = findBestForPreset(json.media.transcodings, "mp3_0_0");
95114

96115
// use mp3 if present if user prefers it or if opus isn't available
97116
if (mp3Media && (obj.format === "mp3" || !selectedStream)) {

0 commit comments

Comments
 (0)