88import org .schabi .newpipe .extractor .InfoItem ;
99import org .schabi .newpipe .extractor .InfoItemsCollector ;
1010import org .schabi .newpipe .extractor .StreamingService ;
11+ import org .schabi .newpipe .extractor .channel .ChannelInfoItem ;
12+ import org .schabi .newpipe .extractor .channel .ChannelInfoItemExtractor ;
1113import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
1214import org .schabi .newpipe .extractor .exceptions .ParsingException ;
1315import org .schabi .newpipe .extractor .linkhandler .SearchQueryHandler ;
16+ import org .schabi .newpipe .extractor .search .InfoItemsSearchCollector ;
1417import org .schabi .newpipe .extractor .search .SearchExtractor ;
1518import org .schabi .newpipe .extractor .services .media_ccc .extractors .infoItems .MediaCCCStreamInfoItemExtractor ;
19+ import org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCConferenceLinkHandlerFactory ;
20+ import org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCConferencesListLinkHandlerFactory ;
1621import org .schabi .newpipe .extractor .utils .Localization ;
17-
22+ import static org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCSearchQueryHandlerFactory .CONFERENCES ;
23+ import static org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCSearchQueryHandlerFactory .EVENTS ;
24+ import static org .schabi .newpipe .extractor .services .media_ccc .linkHandler .MediaCCCSearchQueryHandlerFactory .ALL ;
1825import javax .annotation .Nonnull ;
1926import java .io .IOException ;
27+ import java .util .List ;
2028
2129public class MediaCCCSearchExtractor extends SearchExtractor {
2230
2331 private JsonObject doc ;
32+ private MediaCCCConferenceKiosk conferenceKiosk ;
2433
2534 public MediaCCCSearchExtractor (StreamingService service , SearchQueryHandler linkHandler , Localization localization ) {
2635 super (service , linkHandler , localization );
36+ try {
37+ conferenceKiosk = new MediaCCCConferenceKiosk (service ,
38+ new MediaCCCConferencesListLinkHandlerFactory ().fromId ("conferences" ),
39+ "conferences" ,
40+ localization );
41+ } catch (Exception e ) {
42+ e .printStackTrace ();
43+ }
2744 }
2845
2946 @ Override
@@ -34,11 +51,22 @@ public String getSearchSuggestion() throws ParsingException {
3451 @ Nonnull
3552 @ Override
3653 public InfoItemsPage <InfoItem > getInitialPage () throws IOException , ExtractionException {
37- InfoItemsCollector searchItems = getInfoItemSearchCollector ();
38- JsonArray events = doc .getArray ("events" );
39- for (int i = 0 ; i < events .size (); i ++) {
40- searchItems .commit (new MediaCCCStreamInfoItemExtractor (
41- events .getObject (i )));
54+ InfoItemsSearchCollector searchItems = getInfoItemSearchCollector ();
55+
56+ if (getLinkHandler ().getContentFilters ().contains (CONFERENCES )
57+ || getLinkHandler ().getContentFilters ().contains (ALL )) {
58+ searchConferences (getSearchString (),
59+ conferenceKiosk .getInitialPage ().getItems (),
60+ searchItems );
61+ }
62+
63+ if (getLinkHandler ().getContentFilters ().contains (EVENTS )
64+ || getLinkHandler ().getContentFilters ().contains (ALL )) {
65+ JsonArray events = doc .getArray ("events" );
66+ for (int i = 0 ; i < events .size (); i ++) {
67+ searchItems .commit (new MediaCCCStreamInfoItemExtractor (
68+ events .getObject (i )));
69+ }
4270 }
4371 return new InfoItemsPage <>(searchItems , null );
4472 }
@@ -55,13 +83,60 @@ public InfoItemsPage<InfoItem> getPage(String pageUrl) throws IOException, Extra
5583
5684 @ Override
5785 public void onFetchPage (@ Nonnull Downloader downloader ) throws IOException , ExtractionException {
58- final String site ;
59- final String url = getUrl ();
60- site = downloader .download (url , getLocalization ());
61- try {
62- doc = JsonParser .object ().from (site );
63- } catch (JsonParserException jpe ) {
64- throw new ExtractionException ("Could not parse json." , jpe );
86+ if (getLinkHandler ().getContentFilters ().contains (EVENTS )
87+ || getLinkHandler ().getContentFilters ().contains (ALL )) {
88+ final String site ;
89+ final String url = getUrl ();
90+ site = downloader .download (url , getLocalization ());
91+ try {
92+ doc = JsonParser .object ().from (site );
93+ } catch (JsonParserException jpe ) {
94+ throw new ExtractionException ("Could not parse json." , jpe );
95+ }
96+ }
97+ if (getLinkHandler ().getContentFilters ().contains (CONFERENCES )
98+ || getLinkHandler ().getContentFilters ().contains (ALL ))
99+ conferenceKiosk .fetchPage ();
100+ }
101+
102+ private void searchConferences (String searchString ,
103+ List <ChannelInfoItem > channelItems ,
104+ InfoItemsSearchCollector collector ) {
105+ for (final ChannelInfoItem item : channelItems ) {
106+ if (item .getName ().toUpperCase ().contains (
107+ searchString .toUpperCase ())) {
108+ collector .commit (new ChannelInfoItemExtractor () {
109+ @ Override
110+ public String getDescription () throws ParsingException {
111+ return item .getDescription ();
112+ }
113+
114+ @ Override
115+ public long getSubscriberCount () throws ParsingException {
116+ return item .getSubscriberCount ();
117+ }
118+
119+ @ Override
120+ public long getStreamCount () throws ParsingException {
121+ return item .getStreamCount ();
122+ }
123+
124+ @ Override
125+ public String getName () throws ParsingException {
126+ return item .getName ();
127+ }
128+
129+ @ Override
130+ public String getUrl () throws ParsingException {
131+ return item .getUrl ();
132+ }
133+
134+ @ Override
135+ public String getThumbnailUrl () throws ParsingException {
136+ return item .getThumbnailUrl ();
137+ }
138+ });
139+ }
65140 }
66141 }
67142}
0 commit comments