Udio: fix json extraction from updated webpage and add artwork url to audio track
This commit is contained in:
1 parent
1ced46e075
commit
b392d892ad
3 files changed
+54
-33
No files matched your search
@@ -48,10 +48,6 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
httpInterfaceManager = HttpClientTools.createDefaultThreadLocalManager();
|
||||
}
|
||||
|
||||
public HttpInterface getHttpInterface() {
|
||||
return httpInterfaceManager.getInterface();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return "udio";
|
||||
@@ -71,6 +67,32 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isTrackEncodable(AudioTrack track) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encodeTrack(AudioTrack track, DataOutput output) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) throws IOException {
|
||||
return new UdioAudioTrack(trackInfo, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
ExceptionTools.closeWithWarnings(httpInterfaceManager);
|
||||
}
|
||||
|
||||
public HttpInterface getHttpInterface() {
|
||||
return httpInterfaceManager.getInterface();
|
||||
}
|
||||
|
||||
private AudioItem loadFromTrackPage(HttpInterface httpInterface, String trackUrl) throws IOException {
|
||||
|
||||
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(trackUrl))) {
|
||||
@@ -95,21 +117,22 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
throw new FriendlyException("Udio: Failed to extract track information from web page.", SUSPICIOUS, null);
|
||||
}
|
||||
|
||||
return new UdioAudioTrack(new AudioTrackInfo(
|
||||
trackInfo.get("title").text(),
|
||||
trackInfo.get("artist").text(),
|
||||
(long) (trackInfo.get("duration").as(Double.class) * 1000.0),
|
||||
trackUrl,
|
||||
false,
|
||||
trackUrl
|
||||
), this);
|
||||
String title = trackInfo.get("title").text();
|
||||
String artist = trackInfo.get("artist").text();
|
||||
long duration = (long) (trackInfo.get("duration").as(Double.class) * 1000.0);
|
||||
String playbackUrl = trackInfo.get("song_path").text();
|
||||
String artworkUrl = getArtworkUrlFromImagePath(trackInfo);
|
||||
|
||||
AudioTrackInfo audioTrackInfo = new AudioTrackInfo(title, artist, duration, trackUrl, false, playbackUrl, artworkUrl, null);
|
||||
|
||||
return new UdioAudioTrack(audioTrackInfo, this);
|
||||
}
|
||||
|
||||
JsonBrowser loadTrackInfoFromPageContent(String content) throws IOException {
|
||||
// start = self.__next_f.push([1,"8:
|
||||
// end = \n"])
|
||||
protected JsonBrowser loadTrackInfoFromPageContent(String content) throws IOException {
|
||||
String startTag = "self.__next_f.push([1,\"9:";
|
||||
String endTag = "\\n\"])";
|
||||
|
||||
String json = DataFormatTools.extractBetween(content, "self.__next_f.push([1,\"8:", "\\n\"])");
|
||||
String json = DataFormatTools.extractBetween(content, startTag, endTag);
|
||||
|
||||
if (json == null) {
|
||||
log.error("Track JSON not found in page");
|
||||
@@ -127,24 +150,11 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTrackEncodable(AudioTrack track) {
|
||||
return true;
|
||||
}
|
||||
private String getArtworkUrlFromImagePath(JsonBrowser trackInfo) {
|
||||
String imagePath = trackInfo.get("image_path").text();
|
||||
String artworkOptions = "width=3840,quality=50";
|
||||
|
||||
@Override
|
||||
public void encodeTrack(AudioTrack track, DataOutput output) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public AudioTrack decodeTrack(AudioTrackInfo trackInfo, DataInput input) throws IOException {
|
||||
return new UdioAudioTrack(trackInfo, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
ExceptionTools.closeWithWarnings(httpInterfaceManager);
|
||||
return imagePath.replace("public", artworkOptions);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -63,6 +63,10 @@ public class MessageFunction {
|
||||
thumbnail = String.format("https://i3.ytimg.com/vi/%s/hqdefault.jpg", track.getIdentifier());
|
||||
}
|
||||
|
||||
if (type == SourceFinder.AudioSourceType.Udio) {
|
||||
thumbnail = track.getInfo().artworkUrl;
|
||||
}
|
||||
|
||||
if (thumbnail != null) {
|
||||
message.setThumbnail(thumbnail);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user