11package org .schabi .newpipe .extractor .services .media_ccc .extractors ;
22
3+ import static org .schabi .newpipe .extractor .services .media_ccc .extractors .MediaCCCParsingHelper .getImageListFromLogoImageUrl ;
4+
35import com .grack .nanojson .JsonObject ;
46import com .grack .nanojson .JsonParser ;
57import com .grack .nanojson .JsonParserException ;
68
7- import org .schabi .newpipe .extractor .InfoItem ;
8- import org .schabi .newpipe .extractor .ListExtractor ;
9- import org .schabi .newpipe .extractor .MultiInfoItemsCollector ;
109import org .schabi .newpipe .extractor .Image ;
11- import org .schabi .newpipe .extractor .Page ;
1210import org .schabi .newpipe .extractor .StreamingService ;
1311import org .schabi .newpipe .extractor .channel .ChannelExtractor ;
14- import org .schabi .newpipe .extractor .channel .tabs .ChannelTabExtractor ;
1512import org .schabi .newpipe .extractor .channel .tabs .ChannelTabs ;
1613import org .schabi .newpipe .extractor .downloader .Downloader ;
1714import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
1815import org .schabi .newpipe .extractor .exceptions .ParsingException ;
1916import org .schabi .newpipe .extractor .linkhandler .ListLinkHandler ;
2017import org .schabi .newpipe .extractor .linkhandler .ReadyChannelTabListLinkHandler ;
21- import org .schabi .newpipe .extractor .services .media_ccc .extractors .infoItems .MediaCCCStreamInfoItemExtractor ;
2218import org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCConferenceLinkHandlerFactory ;
2319
2420import java .io .IOException ;
2723
2824import javax .annotation .Nonnull ;
2925
30- import static org .schabi .newpipe .extractor .services .media_ccc .extractors .MediaCCCParsingHelper .getImageListFromLogoImageUrl ;
31-
3226public class MediaCCCConferenceExtractor extends ChannelExtractor {
3327 private JsonObject conferenceData ;
3428
@@ -37,6 +31,19 @@ public MediaCCCConferenceExtractor(final StreamingService service,
3731 super (service , linkHandler );
3832 }
3933
34+ static JsonObject fetchConferenceData (@ Nonnull final Downloader downloader ,
35+ @ Nonnull final String conferenceId )
36+ throws IOException , ExtractionException {
37+ final String conferenceUrl
38+ = MediaCCCConferenceLinkHandlerFactory .CONFERENCE_API_ENDPOINT + conferenceId ;
39+ try {
40+ return JsonParser .object ().from (downloader .get (conferenceUrl ).responseBody ());
41+ } catch (final JsonParserException jpe ) {
42+ throw new ExtractionException ("Could not parse json returned by URL: " + conferenceUrl );
43+ }
44+ }
45+
46+
4047 @ Nonnull
4148 @ Override
4249 public List <Image > getAvatars () {
@@ -88,76 +95,20 @@ public boolean isVerified() {
8895 @ Nonnull
8996 @ Override
9097 public List <ListLinkHandler > getTabs () throws ParsingException {
91- return List .of (new ReadyChannelTabListLinkHandler (getUrl (), getId (),
92- ChannelTabs .VIDEOS , new VideosTabExtractorBuilder (conferenceData )));
98+ return List .of (new ReadyChannelTabListLinkHandler (getUrl (), getId (), ChannelTabs .VIDEOS ,
99+ (service , linkHandler ) ->
100+ new MediaCCCChannelTabExtractor (service , linkHandler , conferenceData )));
93101 }
94102
95103 @ Override
96104 public void onFetchPage (@ Nonnull final Downloader downloader )
97105 throws IOException , ExtractionException {
98- final String conferenceUrl
99- = MediaCCCConferenceLinkHandlerFactory .CONFERENCE_API_ENDPOINT + getId ();
100- try {
101- conferenceData = JsonParser .object ().from (downloader .get (conferenceUrl ).responseBody ());
102- } catch (final JsonParserException jpe ) {
103- throw new ExtractionException ("Could not parse json returned by URL: " + conferenceUrl );
104- }
106+ conferenceData = fetchConferenceData (downloader , getId ());
105107 }
106108
107109 @ Nonnull
108110 @ Override
109111 public String getName () throws ParsingException {
110112 return conferenceData .getString ("title" );
111113 }
112-
113- private static final class VideosTabExtractorBuilder
114- implements ReadyChannelTabListLinkHandler .ChannelTabExtractorBuilder {
115-
116- private final JsonObject conferenceData ;
117-
118- VideosTabExtractorBuilder (final JsonObject conferenceData ) {
119- this .conferenceData = conferenceData ;
120- }
121-
122- @ Nonnull
123- @ Override
124- public ChannelTabExtractor build (@ Nonnull final StreamingService service ,
125- @ Nonnull final ListLinkHandler linkHandler ) {
126- return new VideosChannelTabExtractor (service , linkHandler , conferenceData );
127- }
128- }
129-
130- private static final class VideosChannelTabExtractor extends ChannelTabExtractor {
131- private final JsonObject conferenceData ;
132-
133- VideosChannelTabExtractor (final StreamingService service ,
134- final ListLinkHandler linkHandler ,
135- final JsonObject conferenceData ) {
136- super (service , linkHandler );
137- this .conferenceData = conferenceData ;
138- }
139-
140- @ Override
141- public void onFetchPage (@ Nonnull final Downloader downloader ) {
142- // Nothing to do here, as data was already fetched
143- }
144-
145- @ Nonnull
146- @ Override
147- public ListExtractor .InfoItemsPage <InfoItem > getInitialPage () {
148- final MultiInfoItemsCollector collector =
149- new MultiInfoItemsCollector (getServiceId ());
150- conferenceData .getArray ("events" )
151- .stream ()
152- .filter (JsonObject .class ::isInstance )
153- .map (JsonObject .class ::cast )
154- .forEach (event -> collector .commit (new MediaCCCStreamInfoItemExtractor (event )));
155- return new InfoItemsPage <>(collector , null );
156- }
157-
158- @ Override
159- public InfoItemsPage <InfoItem > getPage (final Page page ) {
160- return InfoItemsPage .emptyPage ();
161- }
162- }
163114}
0 commit comments