Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mp3 frame not found. #196

Merged
merged 3 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Comparator;

public class YandexMusicAudioTrack extends DelegatedAudioTrack {

Expand Down Expand Up @@ -51,10 +52,16 @@ private String getDownloadURL(String id) throws IOException, NoSuchAlgorithmExce
throw new IllegalStateException("No download URL found for track " + id);
}

var downloadInfoLink = json.get("result").values().get(0).get("downloadInfoUrl").text();
var downloadInfo = this.sourceManager.getDownloadStrings(downloadInfoLink);
if (downloadInfo == null) {
throw new IllegalStateException("No download URL found for track " + id);
var mp3ItemUrl = json.get("result")
.values()
.stream()
.filter(c -> c.get("codec").text().equals("mp3"))
.max(Comparator.comparingLong(b -> b.get("bitrateInKbps").asLong(0)))
.map(d -> d.get("downloadInfoUrl").text())
.orElseThrow(() -> new IllegalStateException("No download Mp3 item URL found for track " + id));
var downloadInfo = this.sourceManager.getDownloadStrings(mp3ItemUrl);
if (downloadInfo.isEmpty()) {
throw new IllegalStateException("No downloadInfo found for track " + id);
}

var doc = Jsoup.parse(downloadInfo, "", Parser.xmlParser());
Expand Down