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();
|
httpInterfaceManager = HttpClientTools.createDefaultThreadLocalManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpInterface getHttpInterface() {
|
|
||||||
return httpInterfaceManager.getInterface();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSourceName() {
|
public String getSourceName() {
|
||||||
return "udio";
|
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 {
|
private AudioItem loadFromTrackPage(HttpInterface httpInterface, String trackUrl) throws IOException {
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(trackUrl))) {
|
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);
|
throw new FriendlyException("Udio: Failed to extract track information from web page.", SUSPICIOUS, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new UdioAudioTrack(new AudioTrackInfo(
|
String title = trackInfo.get("title").text();
|
||||||
trackInfo.get("title").text(),
|
String artist = trackInfo.get("artist").text();
|
||||||
trackInfo.get("artist").text(),
|
long duration = (long) (trackInfo.get("duration").as(Double.class) * 1000.0);
|
||||||
(long) (trackInfo.get("duration").as(Double.class) * 1000.0),
|
String playbackUrl = trackInfo.get("song_path").text();
|
||||||
trackUrl,
|
String artworkUrl = getArtworkUrlFromImagePath(trackInfo);
|
||||||
false,
|
|
||||||
trackUrl
|
AudioTrackInfo audioTrackInfo = new AudioTrackInfo(title, artist, duration, trackUrl, false, playbackUrl, artworkUrl, null);
|
||||||
), this);
|
|
||||||
|
return new UdioAudioTrack(audioTrackInfo, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonBrowser loadTrackInfoFromPageContent(String content) throws IOException {
|
protected JsonBrowser loadTrackInfoFromPageContent(String content) throws IOException {
|
||||||
// start = self.__next_f.push([1,"8:
|
String startTag = "self.__next_f.push([1,\"9:";
|
||||||
// end = \n"])
|
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) {
|
if (json == null) {
|
||||||
log.error("Track JSON not found in page");
|
log.error("Track JSON not found in page");
|
||||||
@@ -127,24 +150,11 @@ public class UdioAudioSourceManager implements AudioSourceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private String getArtworkUrlFromImagePath(JsonBrowser trackInfo) {
|
||||||
public boolean isTrackEncodable(AudioTrack track) {
|
String imagePath = trackInfo.get("image_path").text();
|
||||||
return true;
|
String artworkOptions = "width=3840,quality=50";
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return imagePath.replace("public", artworkOptions);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,10 @@ public class MessageFunction {
|
|||||||
thumbnail = String.format("https://i3.ytimg.com/vi/%s/hqdefault.jpg", track.getIdentifier());
|
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) {
|
if (thumbnail != null) {
|
||||||
message.setThumbnail(thumbnail);
|
message.setThumbnail(thumbnail);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class UdioAudioSourceManagerTest {
|
public class UdioAudioSourceManagerTest {
|
||||||
|
|
||||||
@@ -27,5 +28,11 @@ public class UdioAudioSourceManagerTest {
|
|||||||
AudioTrackInfo info = audioTrack.getInfo();
|
AudioTrackInfo info = audioTrack.getInfo();
|
||||||
|
|
||||||
assertNotNull(info);
|
assertNotNull(info);
|
||||||
|
|
||||||
|
assertNotNull(info.artworkUrl);
|
||||||
|
|
||||||
|
String artworkOptions = "width=3840,quality=50";
|
||||||
|
assertTrue(info.artworkUrl.contains(artworkOptions));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user