[media.ccc.de] Get conference name from API URL
This commit is contained in:
parent
41699798fe
commit
d1a0686d2f
|
@ -4,6 +4,7 @@ import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
|
@ -14,12 +15,16 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
|
public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
|
||||||
|
|
||||||
private JsonObject doc;
|
private JsonObject doc;
|
||||||
|
private final Map<String, String> conferenceNames = new HashMap<>();
|
||||||
|
|
||||||
public MediaCCCRecentKiosk(StreamingService streamingService, ListLinkHandler linkHandler, String kioskId) {
|
public MediaCCCRecentKiosk(StreamingService streamingService, ListLinkHandler linkHandler, String kioskId) {
|
||||||
super(streamingService, linkHandler, kioskId);
|
super(streamingService, linkHandler, kioskId);
|
||||||
|
@ -41,8 +46,9 @@ public class MediaCCCRecentKiosk extends KioskExtractor<StreamInfoItem> {
|
||||||
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
|
||||||
final JsonArray events = doc.getArray("events");
|
final JsonArray events = doc.getArray("events");
|
||||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||||
|
|
||||||
for (int i = 0; i < events.size(); i++) {
|
for (int i = 0; i < events.size(); i++) {
|
||||||
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i)));
|
collector.commit(new MediaCCCRecentKioskExtractor(events.getObject(i), conferenceNames));
|
||||||
}
|
}
|
||||||
return new InfoItemsPage<>(collector, null);
|
return new InfoItemsPage<>(collector, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,34 @@
|
||||||
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
|
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.ServiceList;
|
||||||
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||||
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import java.io.IOException;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
public class MediaCCCRecentKioskExtractor implements StreamInfoItemExtractor {
|
public class MediaCCCRecentKioskExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
private final JsonObject event;
|
private final JsonObject event;
|
||||||
|
private final Map<String, String> conferenceNames;
|
||||||
|
|
||||||
public MediaCCCRecentKioskExtractor(final JsonObject event) {
|
public MediaCCCRecentKioskExtractor(final JsonObject event,
|
||||||
|
final Map<String, String> conferenceNames) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
|
this.conferenceNames = conferenceNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,7 +68,25 @@ public class MediaCCCRecentKioskExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderName() throws ParsingException {
|
public String getUploaderName() throws ParsingException {
|
||||||
return "";
|
final String conferenceApiUrl = event.getString("conference_url");
|
||||||
|
if (isNullOrEmpty(conferenceApiUrl)) {
|
||||||
|
throw new ParsingException("conference url is empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conferenceNames.containsKey(conferenceApiUrl)) {
|
||||||
|
return conferenceNames.get(conferenceApiUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
// get conference name from API.
|
||||||
|
try {
|
||||||
|
ChannelExtractor extractor = ServiceList.MediaCCC.getChannelExtractor(
|
||||||
|
new MediaCCCConferenceLinkHandlerFactory().fromUrl(conferenceApiUrl));
|
||||||
|
extractor.fetchPage();
|
||||||
|
conferenceNames.put(conferenceApiUrl, extractor.getName());
|
||||||
|
return extractor.getName();
|
||||||
|
} catch (IOException | ExtractionException e) {
|
||||||
|
throw new ParsingException("Could not get conference name from conference API URL", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue