mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-15 14:50:33 +05:30
Workaround enourmous load times for long bandcamp playlists
Additionally, get cover art from json instead of html
This commit is contained in:
parent
46e1f3922c
commit
ba967f1a15
@ -18,11 +18,19 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getJSONFromJavaScriptVariables;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getJSONFromJavaScriptVariables;
|
||||||
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
|
||||||
|
|
||||||
public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An arbitrarily chosen number above which cover arts won't be fetched individually for each track;
|
||||||
|
* instead, it will be assumed that every track has the same cover art as the album, which is not
|
||||||
|
* always the case.
|
||||||
|
*/
|
||||||
|
private static final int MAXIMUM_INDIVIDUAL_COVER_ARTS = 10;
|
||||||
|
|
||||||
private Document document;
|
private Document document;
|
||||||
private JSONObject albumJson;
|
private JSONObject albumJson;
|
||||||
private JSONArray trackInfo;
|
private JSONArray trackInfo;
|
||||||
@ -57,11 +65,8 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getThumbnailUrl() throws ParsingException {
|
public String getThumbnailUrl() throws ParsingException {
|
||||||
try {
|
if (albumJson.isNull("art_id")) return "";
|
||||||
return document.getElementsByAttributeValue("property", "og:image").get(0).attr("content");
|
else return getImageUrl(albumJson.getLong("art_id"), true);
|
||||||
} catch (NullPointerException e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -104,13 +109,26 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
|
|||||||
for (int i = 0; i < trackInfo.length(); i++) {
|
for (int i = 0; i < trackInfo.length(); i++) {
|
||||||
JSONObject track = trackInfo.getJSONObject(i);
|
JSONObject track = trackInfo.getJSONObject(i);
|
||||||
|
|
||||||
collector.commit(new BandcampStreamInfoItemExtractor(
|
if (trackInfo.length() < MAXIMUM_INDIVIDUAL_COVER_ARTS) {
|
||||||
track.getString("title"),
|
// Load cover art of every track individually
|
||||||
getUploaderUrl() + track.getString("title_link"),
|
collector.commit(new BandcampStreamInfoItemExtractor(
|
||||||
"",
|
track.getString("title"),
|
||||||
track.getLong("duration"),
|
getUploaderUrl() + track.getString("title_link"),
|
||||||
getService()
|
"",
|
||||||
));
|
track.getLong("duration"),
|
||||||
|
getService()
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
// Pretend every track has the same cover art as the album
|
||||||
|
collector.commit(new BandcampStreamInfoItemExtractor(
|
||||||
|
track.getString("title"),
|
||||||
|
getUploaderUrl() + track.getString("title_link"),
|
||||||
|
getThumbnailUrl(),
|
||||||
|
"",
|
||||||
|
track.getLong("duration")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new InfoItemsPage<>(collector, null);
|
return new InfoItemsPage<>(collector, null);
|
||||||
|
@ -21,6 +21,8 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampChannelExtractor.getImageUrl;
|
||||||
|
|
||||||
public class BandcampStreamExtractor extends StreamExtractor {
|
public class BandcampStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
private JSONObject albumJson;
|
private JSONObject albumJson;
|
||||||
@ -103,11 +105,8 @@ public class BandcampStreamExtractor extends StreamExtractor {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getThumbnailUrl() throws ParsingException {
|
public String getThumbnailUrl() throws ParsingException {
|
||||||
try {
|
if (albumJson.isNull("art_id")) return "";
|
||||||
return document.getElementsByAttributeValue("property", "og:image").get(0).attr("content");
|
else return getImageUrl(albumJson.getLong("art_id"), true);
|
||||||
} catch (NullPointerException e) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -52,6 +52,22 @@ public class BandcampPlaylistExtractorTest {
|
|||||||
assertNotEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
|
assertNotEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that no attempt to load every track's cover individually is made
|
||||||
|
*/
|
||||||
|
@Test(timeout = 10000L)
|
||||||
|
public void testDifferentTrackCoversDuration() throws ExtractionException, IOException {
|
||||||
|
PlaylistExtractor extractor = bandcamp.getPlaylistExtractor("https://infiniteammo.bandcamp.com/album/night-in-the-woods-vol-1-at-the-end-of-everything");
|
||||||
|
extractor.fetchPage();
|
||||||
|
|
||||||
|
/* All tracks in this album have the same cover art, but I don't know any albums with more than 10 tracks
|
||||||
|
* that has at least one track with a cover art different from the rest.
|
||||||
|
*/
|
||||||
|
List<StreamInfoItem> l = extractor.getInitialPage().getItems();
|
||||||
|
assertEquals(extractor.getThumbnailUrl(), l.get(0).getThumbnailUrl());
|
||||||
|
assertEquals(extractor.getThumbnailUrl(), l.get(5).getThumbnailUrl());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test playlists with locked content
|
* Test playlists with locked content
|
||||||
*/
|
*/
|
||||||
|
@ -34,7 +34,6 @@ public class BandcampRadioExtractorTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRadioCount() throws ExtractionException, IOException {
|
public void testRadioCount() throws ExtractionException, IOException {
|
||||||
List<InfoItem> list = bandcamp.getKioskList().getExtractorById("Radio", null).getInitialPage().getItems();
|
List<InfoItem> list = bandcamp.getKioskList().getExtractorById("Radio", null).getInitialPage().getItems();
|
||||||
System.out.println(list.size());
|
|
||||||
assertTrue(list.size() > 300);
|
assertTrue(list.size() > 300);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user