1
1
package org .schabi .newpipe .extractor .services .media_ccc .extractors ;
2
2
3
+ import static org .schabi .newpipe .extractor .services .media_ccc .extractors .MediaCCCParsingHelper .getImageListFromLogoImageUrl ;
4
+
3
5
import com .grack .nanojson .JsonObject ;
4
6
import com .grack .nanojson .JsonParser ;
5
7
import com .grack .nanojson .JsonParserException ;
6
8
7
- import org .schabi .newpipe .extractor .InfoItem ;
8
- import org .schabi .newpipe .extractor .ListExtractor ;
9
- import org .schabi .newpipe .extractor .MultiInfoItemsCollector ;
10
9
import org .schabi .newpipe .extractor .Image ;
11
- import org .schabi .newpipe .extractor .Page ;
12
10
import org .schabi .newpipe .extractor .StreamingService ;
13
11
import org .schabi .newpipe .extractor .channel .ChannelExtractor ;
14
- import org .schabi .newpipe .extractor .channel .tabs .ChannelTabExtractor ;
15
12
import org .schabi .newpipe .extractor .channel .tabs .ChannelTabs ;
16
13
import org .schabi .newpipe .extractor .downloader .Downloader ;
17
14
import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
18
15
import org .schabi .newpipe .extractor .exceptions .ParsingException ;
19
16
import org .schabi .newpipe .extractor .linkhandler .ListLinkHandler ;
20
17
import org .schabi .newpipe .extractor .linkhandler .ReadyChannelTabListLinkHandler ;
21
- import org .schabi .newpipe .extractor .services .media_ccc .extractors .infoItems .MediaCCCStreamInfoItemExtractor ;
22
18
import org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCConferenceLinkHandlerFactory ;
23
19
24
20
import java .io .IOException ;
27
23
28
24
import javax .annotation .Nonnull ;
29
25
30
- import static org .schabi .newpipe .extractor .services .media_ccc .extractors .MediaCCCParsingHelper .getImageListFromLogoImageUrl ;
31
-
32
26
public class MediaCCCConferenceExtractor extends ChannelExtractor {
33
27
private JsonObject conferenceData ;
34
28
@@ -37,6 +31,19 @@ public MediaCCCConferenceExtractor(final StreamingService service,
37
31
super (service , linkHandler );
38
32
}
39
33
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
+
40
47
@ Nonnull
41
48
@ Override
42
49
public List <Image > getAvatars () {
@@ -88,76 +95,22 @@ public boolean isVerified() {
88
95
@ Nonnull
89
96
@ Override
90
97
public List <ListLinkHandler > getTabs () throws ParsingException {
91
- return List .of (new ReadyChannelTabListLinkHandler (getUrl (), getId (),
92
- ChannelTabs .VIDEOS , new VideosTabExtractorBuilder (conferenceData )));
98
+ // avoid keeping a reference to MediaCCCConferenceExtractor inside the lambda
99
+ final JsonObject theConferenceData = conferenceData ;
100
+ return List .of (new ReadyChannelTabListLinkHandler (getUrl (), getId (), ChannelTabs .VIDEOS ,
101
+ (service , linkHandler ) ->
102
+ new MediaCCCChannelTabExtractor (service , linkHandler , theConferenceData )));
93
103
}
94
104
95
105
@ Override
96
106
public void onFetchPage (@ Nonnull final Downloader downloader )
97
107
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
- }
108
+ conferenceData = fetchConferenceData (downloader , getId ());
105
109
}
106
110
107
111
@ Nonnull
108
112
@ Override
109
113
public String getName () throws ParsingException {
110
114
return conferenceData .getString ("title" );
111
115
}
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
- }
163
116
}
0 commit comments