2020-12-23 00:07:37 +01:00
|
|
|
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
|
|
|
|
|
|
|
|
import com.grack.nanojson.JsonArray;
|
|
|
|
import com.grack.nanojson.JsonObject;
|
|
|
|
import com.grack.nanojson.JsonParser;
|
|
|
|
import com.grack.nanojson.JsonParserException;
|
|
|
|
import org.schabi.newpipe.extractor.Page;
|
|
|
|
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;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|
|
|
|
2020-12-26 13:15:03 +01:00
|
|
|
import javax.annotation.Nonnull;
|
2020-12-26 13:15:03 +01:00
|
|
|
import java.io.IOException;
|
2020-12-23 00:07:37 +01:00
|
|
|
|
|
|
|
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
|
|
|
|
|
|
|
|
private JsonObject doc;
|
|
|
|
|
|
|
|
public MediaCCCRecentKiosk(StreamingService streamingService, ListLinkHandler linkHandler, String kioskId) {
|
|
|
|
super(streamingService, linkHandler, kioskId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
|
|
|
final String site = downloader.get("https://api.media.ccc.de/public/events/recent",
|
|
|
|
getExtractorLocalization()).responseBody();
|
|
|
|
try {
|
|
|
|
doc = JsonParser.object().from(site);
|
|
|
|
} catch (JsonParserException jpe) {
|
|
|
|
throw new ExtractionException("Could not parse json.", jpe);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
|
|
|
final JsonArray events = doc.getArray("events");
|
|
|
|
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
|
|
|
for (int i = 0; i < events.size(); i++) {
|
2020-12-26 13:15:03 +01:00
|
|
|
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i)));
|
2020-12-23 00:07:37 +01:00
|
|
|
}
|
|
|
|
return new InfoItemsPage<>(collector, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public InfoItemsPage<StreamInfoItem> getPage(Page page) throws IOException, ExtractionException {
|
|
|
|
return InfoItemsPage.emptyPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getName() throws ParsingException {
|
|
|
|
return "recent";
|
|
|
|
}
|
|
|
|
}
|