soundcloud: fix fallback & use source mp3 if preferred

This commit is contained in:
wukko 2024-05-10 23:57:14 +06:00
parent 7cf08c5eeb
commit 0e6ea09b16
No known key found for this signature in database
GPG key ID: 3E30B3F26C7B4AA2
2 changed files with 6 additions and 4 deletions

View file

@ -114,6 +114,7 @@ export default async function(host, patternMatch, url, lang, obj) {
url,
author: patternMatch.author,
song: patternMatch.song,
format: obj.aFormat,
shortLink: patternMatch.shortLink || false,
accessKey: patternMatch.accessKey || false
});

View file

@ -63,11 +63,12 @@ export default async function(obj) {
if (!json["media"]["transcodings"]) return { error: 'ErrorEmptyDownload' };
let bestAudio = "opus",
selectedStream = json.media.transcodings.find(v => v.preset === "opus_0_0");
selectedStream = json.media.transcodings.find(v => v.preset === "opus_0_0"),
mp3Media = json.media.transcodings.find(v => v.preset === "mp3_0_0");
// fall back to mp3 if no opus is available
if (selectedStream.length === 0) {
selectedStream = json.media.transcodings.find(v => v.preset === "mp3_0_0");
// use mp3 if present if user prefers it or if opus isn't available
if (mp3Media && (obj.format === "mp3" || !selectedStream)) {
selectedStream = mp3Media;
bestAudio = "mp3"
}