diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java index 2656f7d64..91da8976e 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKiosk.java @@ -4,6 +4,7 @@ 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; @@ -14,12 +15,16 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector; -import javax.annotation.Nonnull; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nonnull; public class MediaCCCRecentKiosk extends KioskExtractor { private JsonObject doc; + private final Map conferenceNames = new HashMap<>(); public MediaCCCRecentKiosk(StreamingService streamingService, ListLinkHandler linkHandler, String kioskId) { super(streamingService, linkHandler, kioskId); @@ -41,8 +46,9 @@ public class MediaCCCRecentKiosk extends KioskExtractor { public InfoItemsPage getInitialPage() throws IOException, ExtractionException { final JsonArray events = doc.getArray("events"); StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId()); + 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); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKioskExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKioskExtractor.java index 724b3e06b..ac75cfc72 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKioskExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCRecentKioskExtractor.java @@ -1,22 +1,34 @@ package org.schabi.newpipe.extractor.services.media_ccc.extractors; 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.localization.DateWrapper; import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; import org.schabi.newpipe.extractor.stream.StreamType; -import javax.annotation.Nullable; +import java.io.IOException; import java.time.ZonedDateTime; 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 { private final JsonObject event; + private final Map conferenceNames; - public MediaCCCRecentKioskExtractor(final JsonObject event) { + public MediaCCCRecentKioskExtractor(final JsonObject event, + final Map conferenceNames) { this.event = event; + this.conferenceNames = conferenceNames; } @Override @@ -56,7 +68,25 @@ public class MediaCCCRecentKioskExtractor implements StreamInfoItemExtractor { @Override 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