Skip to content

Commit

Permalink
Merge pull request #301 from wb9688/media-ccc-non-api-urls
Browse files Browse the repository at this point in the history
Use media.ccc.de instead of api.media.ccc.de
  • Loading branch information
wb9688 authored Apr 19, 2020
2 parents 1b52230 + bf24caa commit 74f0ab1
Show file tree
Hide file tree
Showing 17 changed files with 184 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
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.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceExtractor;
Expand All @@ -21,19 +26,17 @@
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;

import java.io.IOException;

import static java.util.Arrays.asList;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.VIDEO;

public class MediaCCCService extends StreamingService {
public MediaCCCService(int id) {
public MediaCCCService(final int id) {
super(id, "MediaCCC", asList(AUDIO, VIDEO));
}

@Override
public SearchExtractor getSearchExtractor(SearchQueryHandler query) {
public SearchExtractor getSearchExtractor(final SearchQueryHandler query) {
return new MediaCCCSearchExtractor(this, query);
}

Expand All @@ -58,17 +61,17 @@ public SearchQueryHandlerFactory getSearchQHFactory() {
}

@Override
public StreamExtractor getStreamExtractor(LinkHandler linkHandler) {
public StreamExtractor getStreamExtractor(final LinkHandler linkHandler) {
return new MediaCCCStreamExtractor(this, linkHandler);
}

@Override
public ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler) {
public ChannelExtractor getChannelExtractor(final ListLinkHandler linkHandler) {
return new MediaCCCConferenceExtractor(this, linkHandler);
}

@Override
public PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler) {
public PlaylistExtractor getPlaylistExtractor(final ListLinkHandler linkHandler) {
return null;
}

Expand All @@ -85,9 +88,9 @@ public KioskList getKioskList() throws ExtractionException {
try {
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
@Override
public KioskExtractor createNewKiosk(StreamingService streamingService,
String url,
String kioskId) throws ExtractionException, IOException {
public KioskExtractor createNewKiosk(final StreamingService streamingService,
final String url, final String kioskId)
throws ExtractionException {
return new MediaCCCConferenceKiosk(MediaCCCService.this,
new MediaCCCConferencesListLinkHandlerFactory().fromUrl(url), kioskId);
}
Expand All @@ -111,8 +114,7 @@ public ListLinkHandlerFactory getCommentsLHFactory() {
}

@Override
public CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
throws ExtractionException {
public CommentsExtractor getCommentsExtractor(final ListLinkHandler linkHandler) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;

import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.downloader.Downloader;
Expand All @@ -14,45 +15,46 @@
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;

import javax.annotation.Nonnull;
import java.io.IOException;

public class MediaCCCConferenceExtractor extends ChannelExtractor {
import javax.annotation.Nonnull;

public class MediaCCCConferenceExtractor extends ChannelExtractor {
private JsonObject conferenceData;

public MediaCCCConferenceExtractor(StreamingService service, ListLinkHandler linkHandler) {
public MediaCCCConferenceExtractor(final StreamingService service,
final ListLinkHandler linkHandler) {
super(service, linkHandler);
}

@Override
public String getAvatarUrl() throws ParsingException {
public String getAvatarUrl() {
return conferenceData.getString("logo_url");
}

@Override
public String getBannerUrl() throws ParsingException {
public String getBannerUrl() {
return conferenceData.getString("logo_url");
}

@Override
public String getFeedUrl() throws ParsingException {
public String getFeedUrl() {
return null;
}

@Override
public long getSubscriberCount() throws ParsingException {
public long getSubscriberCount() {
return -1;
}

@Override
public String getDescription() throws ParsingException {
public String getDescription() {
return null;
}

@Nonnull
@Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
public InfoItemsPage<StreamInfoItem> getInitialPage() {
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
JsonArray events = conferenceData.getArray("events");
for (int i = 0; i < events.size(); i++) {
Expand All @@ -62,17 +64,18 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, Extrac
}

@Override
public String getNextPageUrl() throws IOException, ExtractionException {
public String getNextPageUrl() {
return null;
}

@Override
public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
public InfoItemsPage<StreamInfoItem> getPage(final String pageUrl) {
return null;
}

@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
public void onFetchPage(@Nonnull final Downloader downloader)
throws IOException, ExtractionException {
try {
conferenceData = JsonParser.object().from(downloader.get(getUrl()).responseBody());
} catch (JsonParserException jpe) {
Expand All @@ -88,7 +91,7 @@ public String getName() throws ParsingException {

@Nonnull
@Override
public String getOriginalUrl() throws ParsingException {
public String getOriginalUrl() {
return "https://media.ccc.de/c/" + conferenceData.getString("acronym");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;

import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemsCollector;
Expand All @@ -14,22 +15,22 @@
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems.MediaCCCConferenceInfoItemExtractor;

import javax.annotation.Nonnull;
import java.io.IOException;

public class MediaCCCConferenceKiosk extends KioskExtractor<ChannelInfoItem> {
import javax.annotation.Nonnull;

public class MediaCCCConferenceKiosk extends KioskExtractor<ChannelInfoItem> {
private JsonObject doc;

public MediaCCCConferenceKiosk(StreamingService streamingService,
ListLinkHandler linkHandler,
String kioskId) {
public MediaCCCConferenceKiosk(final StreamingService streamingService,
final ListLinkHandler linkHandler,
final String kioskId) {
super(streamingService, linkHandler, kioskId);
}

@Nonnull
@Override
public InfoItemsPage<ChannelInfoItem> getInitialPage() throws IOException, ExtractionException {
public InfoItemsPage<ChannelInfoItem> getInitialPage() {
JsonArray conferences = doc.getArray("conferences");
ChannelInfoItemsCollector collector = new ChannelInfoItemsCollector(getServiceId());
for (int i = 0; i < conferences.size(); i++) {
Expand All @@ -40,18 +41,20 @@ public InfoItemsPage<ChannelInfoItem> getInitialPage() throws IOException, Extra
}

@Override
public String getNextPageUrl() throws IOException, ExtractionException {
public String getNextPageUrl() {
return "";
}

@Override
public InfoItemsPage<ChannelInfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
public InfoItemsPage<ChannelInfoItem> getPage(final String pageUrl) {
return InfoItemsPage.emptyPage();
}

@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
String site = downloader.get(getLinkHandler().getUrl(), getExtractorLocalization()).responseBody();
public void onFetchPage(@Nonnull final Downloader downloader)
throws IOException, ExtractionException {
final String site = downloader.get(getLinkHandler().getUrl(), getExtractorLocalization())
.responseBody();
try {
doc = JsonParser.object().from(site);
} catch (JsonParserException jpe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import java.util.Calendar;
import java.util.Date;

public class MediaCCCParsingHelper {
private MediaCCCParsingHelper() {
}
public final class MediaCCCParsingHelper {
private MediaCCCParsingHelper() { }

public static Calendar parseDateFrom(String textualUploadDate) throws ParsingException {
public static Calendar parseDateFrom(final String textualUploadDate) throws ParsingException {
Date date;
try {
date = new SimpleDateFormat("yyyy-MM-dd").parse(textualUploadDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,34 @@
import com.grack.nanojson.JsonObject;
import com.grack.nanojson.JsonParser;
import com.grack.nanojson.JsonParserException;

import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelInfoItem;
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
import org.schabi.newpipe.extractor.search.SearchExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems.MediaCCCStreamInfoItemExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferencesListLinkHandlerFactory;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.List;

import static org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory.*;
import javax.annotation.Nonnull;

public class MediaCCCSearchExtractor extends SearchExtractor {
import static org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory.ALL;
import static org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory.CONFERENCES;
import static org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCSearchQueryHandlerFactory.EVENTS;

public class MediaCCCSearchExtractor extends SearchExtractor {
private JsonObject doc;
private MediaCCCConferenceKiosk conferenceKiosk;

public MediaCCCSearchExtractor(StreamingService service, SearchQueryHandler linkHandler) {
public MediaCCCSearchExtractor(final StreamingService service,
final SearchQueryHandler linkHandler) {
super(service, linkHandler);
try {
conferenceKiosk = new MediaCCCConferenceKiosk(service,
Expand All @@ -40,13 +43,13 @@ public MediaCCCSearchExtractor(StreamingService service, SearchQueryHandler link
}

@Override
public String getSearchSuggestion() throws ParsingException {
public String getSearchSuggestion() {
return null;
}

@Nonnull
@Override
public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionException {
public InfoItemsPage<InfoItem> getInitialPage() {
final InfoItemsSearchCollector searchItems = new InfoItemsSearchCollector(getServiceId());

if (getLinkHandler().getContentFilters().contains(CONFERENCES)
Expand All @@ -70,17 +73,18 @@ public InfoItemsPage<InfoItem> getInitialPage() throws IOException, ExtractionEx
}

@Override
public String getNextPageUrl() throws IOException, ExtractionException {
public String getNextPageUrl() {
return "";
}

@Override
public InfoItemsPage<InfoItem> getPage(String pageUrl) throws IOException, ExtractionException {
public InfoItemsPage<InfoItem> getPage(final String pageUrl) {
return InfoItemsPage.emptyPage();
}

@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
public void onFetchPage(@Nonnull final Downloader downloader)
throws IOException, ExtractionException {
if (getLinkHandler().getContentFilters().contains(EVENTS)
|| getLinkHandler().getContentFilters().contains(ALL)
|| getLinkHandler().getContentFilters().isEmpty()) {
Expand All @@ -95,44 +99,45 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
}
if (getLinkHandler().getContentFilters().contains(CONFERENCES)
|| getLinkHandler().getContentFilters().contains(ALL)
|| getLinkHandler().getContentFilters().isEmpty())
|| getLinkHandler().getContentFilters().isEmpty()) {
conferenceKiosk.fetchPage();
}
}

private void searchConferences(String searchString,
List<ChannelInfoItem> channelItems,
InfoItemsSearchCollector collector) {
private void searchConferences(final String searchString,
final List<ChannelInfoItem> channelItems,
final InfoItemsSearchCollector collector) {
for (final ChannelInfoItem item : channelItems) {
if (item.getName().toUpperCase().contains(
searchString.toUpperCase())) {
collector.commit(new ChannelInfoItemExtractor() {
@Override
public String getDescription() throws ParsingException {
public String getDescription() {
return item.getDescription();
}

@Override
public long getSubscriberCount() throws ParsingException {
public long getSubscriberCount() {
return item.getSubscriberCount();
}

@Override
public long getStreamCount() throws ParsingException {
public long getStreamCount() {
return item.getStreamCount();
}

@Override
public String getName() throws ParsingException {
public String getName() {
return item.getName();
}

@Override
public String getUrl() throws ParsingException {
public String getUrl() {
return item.getUrl();
}

@Override
public String getThumbnailUrl() throws ParsingException {
public String getThumbnailUrl() {
return item.getThumbnailUrl();
}
});
Expand Down
Loading

0 comments on commit 74f0ab1

Please sign in to comment.