2019-12-22 15:15:12 +01:00
|
|
|
// Created by Fynn Godau 2019, licensed GNU GPL version 3 or later
|
|
|
|
|
|
|
|
package org.schabi.newpipe.extractor.services.bandcamp.extractors;
|
|
|
|
|
2020-03-19 11:18:29 +01:00
|
|
|
import com.grack.nanojson.JsonArray;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
|
|
|
import com.grack.nanojson.JsonParser;
|
|
|
|
import com.grack.nanojson.JsonParserException;
|
2020-08-02 16:23:53 +02:00
|
|
|
import org.schabi.newpipe.extractor.Page;
|
2019-12-22 15:15:12 +01:00
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
2020-05-25 18:51:31 +02:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItem;
|
2019-12-22 15:15:12 +01:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2021-02-21 12:15:45 +01:00
|
|
|
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.BASE_API_URL;
|
|
|
|
|
2020-05-25 18:51:31 +02:00
|
|
|
public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem> {
|
2019-12-22 15:15:12 +01:00
|
|
|
|
|
|
|
public static final String KIOSK_FEATURED = "Featured";
|
2021-02-21 12:15:45 +01:00
|
|
|
public static final String FEATURED_API_URL = BASE_API_URL + "/mobile/24/bootstrap_data";
|
2019-12-22 15:15:12 +01:00
|
|
|
|
2021-02-16 21:09:35 +01:00
|
|
|
private JsonObject json;
|
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
public BandcampFeaturedExtractor(final StreamingService streamingService, final ListLinkHandler listLinkHandler,
|
|
|
|
final String kioskId) {
|
2019-12-22 15:15:12 +01:00
|
|
|
super(streamingService, listLinkHandler, kioskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
2021-02-16 21:09:35 +01:00
|
|
|
try {
|
|
|
|
json = JsonParser.object().from(
|
|
|
|
getDownloader().post(
|
|
|
|
FEATURED_API_URL, null, "{\"platform\":\"\",\"version\":0}".getBytes()
|
|
|
|
).responseBody()
|
|
|
|
);
|
|
|
|
} catch (final JsonParserException e) {
|
|
|
|
throw new ParsingException("Could not parse Bandcamp featured API response", e);
|
|
|
|
}
|
2019-12-22 15:15:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getName() throws ParsingException {
|
2019-12-22 17:30:22 +01:00
|
|
|
return KIOSK_FEATURED;
|
2019-12-22 15:15:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-05-25 18:51:31 +02:00
|
|
|
public InfoItemsPage<PlaylistInfoItem> getInitialPage() throws IOException, ExtractionException {
|
2019-12-22 15:15:12 +01:00
|
|
|
|
2020-11-24 09:41:40 +01:00
|
|
|
final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector(getServiceId());
|
2019-12-22 15:15:12 +01:00
|
|
|
|
2021-02-16 21:09:35 +01:00
|
|
|
final JsonArray featuredStories = json.getObject("feed_content")
|
|
|
|
.getObject("stories")
|
|
|
|
.getArray("featured");
|
2019-12-22 15:15:12 +01:00
|
|
|
|
2021-02-16 21:09:35 +01:00
|
|
|
for (int i = 0; i < featuredStories.size(); i++) {
|
|
|
|
final JsonObject featuredStory = featuredStories.getObject(i);
|
2019-12-22 15:15:12 +01:00
|
|
|
|
2021-02-16 21:09:35 +01:00
|
|
|
if (featuredStory.isNull("album_title")) {
|
|
|
|
// Is not an album, ignore
|
|
|
|
continue;
|
2019-12-22 15:15:12 +01:00
|
|
|
}
|
|
|
|
|
2021-02-16 21:09:35 +01:00
|
|
|
c.commit(new BandcampPlaylistInfoItemFeaturedExtractor(featuredStory));
|
2019-12-22 15:15:12 +01:00
|
|
|
}
|
2021-02-16 21:09:35 +01:00
|
|
|
|
|
|
|
return new InfoItemsPage<>(c, null);
|
|
|
|
|
2019-12-22 15:15:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-08-02 16:23:53 +02:00
|
|
|
public InfoItemsPage<PlaylistInfoItem> getPage(Page page) {
|
2019-12-22 15:15:12 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|