Skip to content

Commit 14e1ccd

Browse files
committed
add conferences search
1 parent 1503459 commit 14e1ccd

6 files changed

Lines changed: 231 additions & 28 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCSearchExtractor.java

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,39 @@
88
import org.schabi.newpipe.extractor.InfoItem;
99
import org.schabi.newpipe.extractor.InfoItemsCollector;
1010
import org.schabi.newpipe.extractor.StreamingService;
11+
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
12+
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
1113
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1214
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1315
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
16+
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
1417
import org.schabi.newpipe.extractor.search.SearchExtractor;
1518
import 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;
1621
import 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;
1825
import javax.annotation.Nonnull;
1926
import java.io.IOException;
27+
import java.util.List;
2028

2129
public 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
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99

1010
public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1111

12+
public static final String ALL = "all";
13+
public static final String CONFERENCES = "conferences";
14+
public static final String EVENTS = "events";
15+
1216
@Override
1317
public String[] getAvailableContentFilter() {
14-
return new String[0];
18+
return new String[] {
19+
ALL,
20+
CONFERENCES,
21+
EVENTS
22+
};
1523
}
1624

1725
@Override
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.schabi.newpipe.extractor.services.media_ccc;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Test;
5+
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.InfoItem;
7+
import org.schabi.newpipe.extractor.ListExtractor;
8+
import org.schabi.newpipe.extractor.NewPipe;
9+
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
10+
import org.schabi.newpipe.extractor.search.SearchExtractor;
11+
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCSearchExtractor;
12+
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory;
13+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
14+
import org.schabi.newpipe.extractor.utils.Localization;
15+
16+
import java.util.Arrays;
17+
18+
import static junit.framework.TestCase.assertTrue;
19+
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
20+
21+
/**
22+
* Test for {@link MediaCCCSearchExtractor}
23+
*/
24+
public class MediaCCCSearchExtractorAllTest {
25+
26+
private static SearchExtractor extractor;
27+
private static ListExtractor.InfoItemsPage<InfoItem> itemsPage;
28+
29+
@BeforeClass
30+
public static void setUpClass() throws Exception {
31+
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
32+
extractor = MediaCCC.getSearchExtractor( new MediaCCCSearchQueryHandlerFactory()
33+
.fromQuery("c", Arrays.asList(new String[] {"all"}), "")
34+
,new Localization("GB", "en"));
35+
extractor.fetchPage();
36+
itemsPage = extractor.getInitialPage();
37+
}
38+
39+
@Test
40+
public void testIfChannelInfoItemsAvailable() {
41+
boolean isAvialable = false;
42+
for(InfoItem item : itemsPage.getItems()) {
43+
if(item instanceof ChannelInfoItem) {
44+
isAvialable = true;
45+
}
46+
}
47+
assertTrue("ChannelInfoItem not in all list", isAvialable);
48+
}
49+
50+
@Test
51+
public void testIfStreamInfoitemsAvailable() {
52+
boolean isAvialable = false;
53+
for(InfoItem item : itemsPage.getItems()) {
54+
if(item instanceof StreamInfoItem) {
55+
isAvialable = true;
56+
}
57+
}
58+
assertTrue("ChannelInfoItem not in all list", isAvialable);
59+
}
60+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.schabi.newpipe.extractor.services.media_ccc;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.Test;
5+
import org.schabi.newpipe.Downloader;
6+
import org.schabi.newpipe.extractor.InfoItem;
7+
import org.schabi.newpipe.extractor.ListExtractor;
8+
import org.schabi.newpipe.extractor.NewPipe;
9+
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
10+
import org.schabi.newpipe.extractor.search.SearchExtractor;
11+
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCSearchExtractor;
12+
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory;
13+
import org.schabi.newpipe.extractor.utils.Localization;
14+
15+
import java.util.Arrays;
16+
17+
import static junit.framework.TestCase.assertTrue;
18+
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
19+
20+
/**
21+
* Test for {@link MediaCCCSearchExtractor}
22+
*/
23+
public class MediaCCCSearchExtractorConferencesTest {
24+
25+
private static SearchExtractor extractor;
26+
private static ListExtractor.InfoItemsPage<InfoItem> itemsPage;
27+
28+
@BeforeClass
29+
public static void setUpClass() throws Exception {
30+
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
31+
extractor = MediaCCC.getSearchExtractor( new MediaCCCSearchQueryHandlerFactory()
32+
.fromQuery("c3", Arrays.asList(new String[] {"conferences"}), "")
33+
,new Localization("GB", "en"));
34+
extractor.fetchPage();
35+
itemsPage = extractor.getInitialPage();
36+
}
37+
38+
@Test
39+
public void testReturnTypeChannel() {
40+
for(InfoItem item : itemsPage.getItems()) {
41+
assertTrue("Item is not of type channel", item instanceof ChannelInfoItem);
42+
}
43+
}
44+
45+
@Test
46+
public void testItemCount() {
47+
assertTrue("Count is to hight: " + itemsPage.getItems().size(), itemsPage.getItems().size() < 127);
48+
assertTrue("Countis to low: " + itemsPage.getItems().size(), itemsPage.getItems().size() >= 29);
49+
}
50+
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorTest.java renamed to extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCSearchExtractorEventsTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
import org.schabi.newpipe.extractor.NewPipe;
99
import org.schabi.newpipe.extractor.search.SearchExtractor;
1010
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCSearchExtractor;
11+
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory;
12+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1113
import org.schabi.newpipe.extractor.utils.Localization;
1214

15+
import java.util.Arrays;
16+
1317
import static junit.framework.TestCase.assertEquals;
1418
import static junit.framework.TestCase.assertTrue;
1519
import static org.junit.Assert.assertFalse;
@@ -18,14 +22,16 @@
1822
/**
1923
* Test for {@link MediaCCCSearchExtractor}
2024
*/
21-
public class MediaCCCSearchExtractorTest {
25+
public class MediaCCCSearchExtractorEventsTest {
2226
private static SearchExtractor extractor;
2327
private static ListExtractor.InfoItemsPage<InfoItem> itemsPage;
2428

2529
@BeforeClass
2630
public static void setUpClass() throws Exception {
2731
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
28-
extractor = MediaCCC.getSearchExtractor("source");
32+
extractor = MediaCCC.getSearchExtractor( new MediaCCCSearchQueryHandlerFactory()
33+
.fromQuery("linux", Arrays.asList(new String[] {"events"}), "")
34+
,new Localization("GB", "en"));
2935
extractor.fetchPage();
3036
itemsPage = extractor.getInitialPage();
3137
}
@@ -58,4 +64,11 @@ public void testThumbnailUrl() throws Exception {
5864
itemsPage.getItems().get(0).getThumbnailUrl().startsWith("https://static.media.ccc.de/media/")
5965
&& itemsPage.getItems().get(0).getThumbnailUrl().endsWith(".jpg"));
6066
}
67+
68+
@Test
69+
public void testReturnTypeStream() throws Exception {
70+
for(InfoItem item : itemsPage.getItems()) {
71+
assertTrue("Item is not of type StreamInfoItem", item instanceof StreamInfoItem);
72+
}
73+
}
6174
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/soundcloud/search/SoundcloudSearchExtractorDefaultTest.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
import org.schabi.newpipe.extractor.NewPipe;
99
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
1010
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchExtractor;
11+
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudSearchQueryHandlerFactory;
1112
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
1213
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1314
import org.schabi.newpipe.extractor.utils.Localization;
1415

16+
import java.util.Arrays;
17+
1518
import static org.junit.Assert.*;
1619
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
1720
import static org.schabi.newpipe.extractor.ServiceList.YouTube;
@@ -44,26 +47,20 @@ public class SoundcloudSearchExtractorDefaultTest extends SoundcloudSearchExtrac
4447
@BeforeClass
4548
public static void setUpClass() throws Exception {
4649
NewPipe.init(Downloader.getInstance(), new Localization("GB", "en"));
47-
extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor("lill uzi vert");
50+
extractor = (SoundcloudSearchExtractor) SoundCloud.getSearchExtractor(
51+
new SoundcloudSearchQueryHandlerFactory().fromQuery("lill uzi vert",
52+
Arrays.asList(new String[]{"tracks"}), ""),
53+
new Localization("GB", "en"));
4854
extractor.fetchPage();
4955
itemsPage = extractor.getInitialPage();
5056
}
5157

5258
@Test
5359
public void testGetSecondPageUrl() throws Exception {
54-
assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&limit=10&offset=10",
60+
assertEquals("https://api-v2.soundcloud.com/search/tracks?q=lill+uzi+vert&limit=10&offset=10",
5561
removeClientId(extractor.getNextPageUrl()));
5662
}
5763

58-
@Test
59-
public void testResultList_FirstElement() {
60-
InfoItem firstInfoItem = itemsPage.getItems().get(0);
61-
62-
// THe channel should be the first item
63-
assertEquals("name", "Bad and Boujee (Feat. Lil Uzi Vert) [Prod. By Metro Boomin]", firstInfoItem.getName());
64-
assertEquals("url","https://soundcloud.com/migosatl/bad-and-boujee-feat-lil-uzi-vert-prod-by-metro-boomin", firstInfoItem.getUrl());
65-
}
66-
6764
@Test
6865
public void testResultListCheckIfContainsStreamItems() {
6966
boolean hasStreams = false;
@@ -94,7 +91,7 @@ public void testGetSecondPage() throws Exception {
9491
}
9592
assertFalse("First and second page are equal", equals);
9693

97-
assertEquals("https://api-v2.soundcloud.com/search?q=lill+uzi+vert&limit=10&offset=20",
94+
assertEquals("https://api-v2.soundcloud.com/search/tracks?q=lill+uzi+vert&limit=10&offset=20",
9895
removeClientId(secondPage.getNextPageUrl()));
9996
}
10097

0 commit comments

Comments
 (0)