add kiosk for conferences

This commit is contained in:
Christian Schabesberger 2019-01-28 12:18:16 +01:00
parent cb51254aa3
commit 1503459292
10 changed files with 224 additions and 6 deletions

View File

@ -20,6 +20,7 @@ package org.schabi.newpipe.extractor.kiosk;
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@ -29,7 +30,7 @@ import org.schabi.newpipe.extractor.utils.Localization;
import javax.annotation.Nonnull;
public abstract class KioskExtractor extends ListExtractor<StreamInfoItem> {
public abstract class KioskExtractor<T extends InfoItem> extends ListExtractor<T> {
private final String id;
public KioskExtractor(StreamingService streamingService,

View File

@ -49,6 +49,11 @@ public class KioskList {
defaultKiosk = kioskType;
}
public KioskExtractor getDefaultKioskExtractor()
throws ExtractionException, IOException {
return getDefaultKioskExtractor("");
}
public KioskExtractor getDefaultKioskExtractor(String nextPageUrl)
throws ExtractionException, IOException {
return getDefaultKioskExtractor(nextPageUrl, NewPipe.getPreferredLocalization());

View File

@ -4,20 +4,25 @@ import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.SuggestionExtractor;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.kiosk.KioskList;
import org.schabi.newpipe.extractor.linkhandler.*;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceKiosk;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCSearchExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCStreamExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferencesListLinkHandlerFactory;
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory;
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCStreamLinkHandlerFactory;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.utils.Localization;
import java.io.IOException;
import static java.util.Arrays.asList;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.*;
@ -77,7 +82,17 @@ public class MediaCCCService extends StreamingService {
// add kiosks here e.g.:
try {
// Add kiosk here
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
@Override
public KioskExtractor createNewKiosk(StreamingService streamingService,
String url,
String kioskId,
Localization localization) throws ExtractionException, IOException {
return new MediaCCCConferenceKiosk(MediaCCCService.this,
new MediaCCCConferencesListLinkHandlerFactory().fromUrl(url), kioskId, localization);
}
}, new MediaCCCConferencesListLinkHandlerFactory(), "conferences");
list.setDefaultKiosk("conferences");
} catch (Exception e) {
throw new ExtractionException(e);
}

View File

@ -0,0 +1,69 @@
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
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.Downloader;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems.MediaCCCConferenceInfoItemExtractor;
import org.schabi.newpipe.extractor.utils.Localization;
import javax.annotation.Nonnull;
import java.io.IOException;
public class MediaCCCConferenceKiosk extends KioskExtractor<ChannelInfoItem> {
private JsonObject doc;
public MediaCCCConferenceKiosk(StreamingService streamingService,
ListLinkHandler linkHandler,
String kioskId,
Localization localization) {
super(streamingService, linkHandler, kioskId, localization);
}
@Nonnull
@Override
public InfoItemsPage<ChannelInfoItem> getInitialPage() throws IOException, ExtractionException {
JsonArray conferences = doc.getArray("conferences");
ChannelInfoItemsCollector collector = new ChannelInfoItemsCollector(getServiceId());
for(int i = 0; i < conferences.size(); i++) {
collector.commit(new MediaCCCConferenceInfoItemExtractor(conferences.getObject(i)));
}
return new InfoItemsPage<>(collector, "");
}
@Override
public String getNextPageUrl() throws IOException, ExtractionException {
return "";
}
@Override
public InfoItemsPage<ChannelInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
return InfoItemsPage.emptyPage();
}
@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
String site = downloader.download(getLinkHandler().getUrl());
try {
doc = JsonParser.object().from(site);
} catch (JsonParserException jpe) {
throw new ExtractionException("Could not parse json.", jpe);
}
}
@Nonnull
@Override
public String getName() throws ParsingException {
return doc.getString("Conferences");
}
}

View File

@ -20,7 +20,7 @@ import java.io.IOException;
public class MediaCCCSearchExtractor extends SearchExtractor {
JsonObject doc;
private JsonObject doc;
public MediaCCCSearchExtractor(StreamingService service, SearchQueryHandler linkHandler, Localization localization) {
super(service, linkHandler, localization);
@ -50,7 +50,7 @@ public class MediaCCCSearchExtractor extends SearchExtractor {
@Override
public InfoItemsPage<InfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
return null;
return InfoItemsPage.emptyPage();
}
@Override

View File

@ -0,0 +1,44 @@
package org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems;
import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
public class MediaCCCConferenceInfoItemExtractor implements ChannelInfoItemExtractor {
JsonObject conference;
public MediaCCCConferenceInfoItemExtractor(JsonObject conference) {
this.conference = conference;
}
@Override
public String getDescription() throws ParsingException {
return "";
}
@Override
public long getSubscriberCount() throws ParsingException {
return -1;
}
@Override
public long getStreamCount() throws ParsingException {
return -1;
}
@Override
public String getName() throws ParsingException {
return conference.getString("title");
}
@Override
public String getUrl() throws ParsingException {
return conference.getString("url");
}
@Override
public String getThumbnailUrl() throws ParsingException {
return conference.getString("logo_url");
}
}

View File

@ -0,0 +1,25 @@
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import java.util.List;
public class MediaCCCConferencesListLinkHandlerFactory extends ListLinkHandlerFactory {
@Override
public String getId(String url) throws ParsingException {
return "conferences";
}
@Override
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
return "https://api.media.ccc.de/public/conferences";
}
@Override
public boolean onAcceptUrl(String url) throws ParsingException {
return url.equals("https://media.ccc.de/b/conferences")
|| url.equals("https://api.media.ccc.de/public/conferences");
}
}

View File

@ -14,7 +14,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.List;
public class SoundcloudChartsExtractor extends KioskExtractor {
public class SoundcloudChartsExtractor extends KioskExtractor<StreamInfoItem> {
private StreamInfoItemsCollector collector = null;
private String nextPageUrl = null;

View File

@ -37,7 +37,7 @@ import org.schabi.newpipe.extractor.utils.Localization;
import javax.annotation.Nonnull;
import java.io.IOException;
public class YoutubeTrendingExtractor extends KioskExtractor {
public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
private Document doc;

View File

@ -0,0 +1,59 @@
package org.schabi.newpipe.extractor.services.media_ccc;
import org.junit.BeforeClass;
import org.junit.Test;
import org.schabi.newpipe.Downloader;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceKiosk;
import org.schabi.newpipe.extractor.utils.Localization;
import java.util.List;
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
import static org.junit.Assert.assertTrue;
/**
* Test {@link MediaCCCConferenceKiosk}
*/
public class MediaCCCConferenceListExtractorTest {
private static KioskExtractor extractor;
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(Downloader.getInstance(), new Localization("en", "en_GB"));
extractor = MediaCCC.getKioskList().getDefaultKioskExtractor();
extractor.fetchPage();
}
@Test
public void getConferencesListTest() throws Exception {
assertTrue("returned list was to small",
extractor.getInitialPage().getItems().size() >= 174);
}
@Test
public void conferenceTypeTest() throws Exception {
assertTrue(contains(extractor.getInitialPage().getItems(), "FrOSCon 2016"));
assertTrue(contains(extractor.getInitialPage().getItems(), "ChaosWest @ 35c3"));
assertTrue(contains(extractor.getInitialPage().getItems(), "CTreffOS chaOStalks"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Datenspuren 2015"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Chaos Singularity 2017"));
assertTrue(contains(extractor.getInitialPage().getItems(), "SIGINT10"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Vintage Computing Festival Berlin 2015"));
assertTrue(contains(extractor.getInitialPage().getItems(), "FIfFKon 2015"));
assertTrue(contains(extractor.getInitialPage().getItems(), "33C3: trailers"));
assertTrue(contains(extractor.getInitialPage().getItems(), "Blinkenlights"));
}
private boolean contains(List<InfoItem> itemList, String name) {
for(InfoItem item : itemList) {
if(item.getName().equals(name))
return true;
}
return false;
}
}