Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ public String getId() {
}

/**
* Id should be the name of the kiosk, tho Id is used for identifing it in the frontend,
* Id should be the name of the kiosk, tho Id is used for identifying it in the frontend,
* so id should be kept in english.
* In order to get the name of the kiosk in the desired language we have to
* crawl if from the website.
* @return the tranlsated version of id
* @return the translated version of id
* @throws ParsingException
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
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;
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.services.media_ccc.extractors.*;
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.*;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
Expand Down Expand Up @@ -62,6 +56,9 @@ public SearchQueryHandlerFactory getSearchQHFactory() {

@Override
public StreamExtractor getStreamExtractor(final LinkHandler linkHandler) {
if (MediaCCCParsingHelper.isLiveStreamId(linkHandler.getId())) {
return new MediaCCCLiveStreamExtractor(this, linkHandler);
}
return new MediaCCCStreamExtractor(this, linkHandler);
}

Expand Down Expand Up @@ -95,7 +92,28 @@ public KioskExtractor createNewKiosk(final StreamingService streamingService,
new MediaCCCConferencesListLinkHandlerFactory().fromUrl(url), kioskId);
}
}, new MediaCCCConferencesListLinkHandlerFactory(), "conferences");
list.setDefaultKiosk("conferences");

list.addKioskEntry(new KioskList.KioskExtractorFactory() {
@Override
public KioskExtractor createNewKiosk(final StreamingService streamingService,
final String url, final String kioskId)
throws ExtractionException {
return new MediaCCCRecentKiosk(MediaCCCService.this,
new MediaCCCRecentListLinkHandlerFactory().fromUrl(url), kioskId);
}
}, new MediaCCCRecentListLinkHandlerFactory(), "recent");

list.addKioskEntry(new KioskList.KioskExtractorFactory() {
@Override
public KioskExtractor createNewKiosk(final StreamingService streamingService,
final String url, final String kioskId)
throws ExtractionException {
return new MediaCCCLiveStreamKiosk(MediaCCCService.this,
new MediaCCCLiveListLinkHandlerFactory().fromUrl(url), kioskId);
}
}, new MediaCCCLiveListLinkHandlerFactory(), "live");

list.setDefaultKiosk("recent");
} catch (Exception e) {
throw new ExtractionException(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
package org.schabi.newpipe.extractor.services.media_ccc.extractors;

import com.grack.nanojson.JsonArray;
import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.StreamingService;
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.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.stream.*;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

public class MediaCCCLiveStreamExtractor extends StreamExtractor {
private JsonArray doc = null;
private JsonObject conference = null;
private String group = "";
private JsonObject room = null;

public MediaCCCLiveStreamExtractor(StreamingService service, LinkHandler linkHandler) {
super(service, linkHandler);
}

@Override
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
doc = MediaCCCParsingHelper.getLiveStreams(downloader, getExtractorLocalization());
// find correct room
for (int c = 0; c < doc.size(); c++) {
final JsonObject conference = doc.getObject(c);
final JsonArray groups = conference.getArray("groups");
for (int g = 0; g < groups.size(); g++) {
final String group = groups.getObject(g).getString("group");
final JsonArray rooms = groups.getObject(g).getArray("rooms");
for (int r = 0; r < rooms.size(); r++) {
final JsonObject room = rooms.getObject(r);
if (getId().equals(conference.getString("slug") + "/" + room.getString("slug"))) {
this.conference = conference;
this.group = group;
this.room = room;
return;
}
}
}
}
throw new ExtractionException("Could not find room matching id: '" + getId() + "'");
}

@Nonnull
@Override
public String getName() throws ParsingException {
return room.getString("display");
}

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

@Nullable
@Override
public DateWrapper getUploadDate() throws ParsingException {
return null;
}

@Nonnull
@Override
public String getThumbnailUrl() throws ParsingException {
return room.getString("thumb");
}

@Nonnull
@Override
public Description getDescription() throws ParsingException {
return new Description(conference.getString("description") + " - " + group, Description.PLAIN_TEXT);
}

@Override
public int getAgeLimit() {
return 0;
}

@Override
public long getLength() {
return 0;
}

@Override
public long getTimeStamp() throws ParsingException {
return 0;
}

@Override
public long getViewCount() {
return -1;
}

@Override
public long getLikeCount() {
return -1;
}

@Override
public long getDislikeCount() {
return -1;
}

@Nonnull
@Override
public String getUploaderUrl() throws ParsingException {
return "https://streaming.media.ccc.de/" + conference.getString("slug");
}

@Nonnull
@Override
public String getUploaderName() throws ParsingException {
return conference.getString("conference");
}

@Nonnull
@Override
public String getUploaderAvatarUrl() {
return "";
}

@Nonnull
@Override
public String getSubChannelUrl() {
return "";
}

@Nonnull
@Override
public String getSubChannelName() {
return "";
}

@Nonnull
@Override
public String getSubChannelAvatarUrl() {
return "";
}

@Nonnull
@Override
public String getDashMpdUrl() throws ParsingException {
return "";
}

@Nonnull
@Override
public String getHlsUrl() {
// TODO: There are multiple HLS streams.
// Make getHlsUrl() and getDashMpdUrl() return lists of VideoStreams, so the user can choose a resolution.
for (int s = 0; s < room.getArray("streams").size(); s++) {
final JsonObject stream = room.getArray("streams").getObject(s);
if (stream.getString("type").equals("video")) {
final String resolution = stream.getArray("videoSize").getInt(0) + "x"
+ stream.getArray("videoSize").getInt(1);
if (stream.has("hls")) {
return stream.getObject("urls").getObject("hls").getString("url");
}
}
}
return "";
}

@Override
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
final List<AudioStream> audioStreams = new ArrayList<>();
for (int s = 0; s < room.getArray("streams").size(); s++) {
final JsonObject stream = room.getArray("streams").getObject(s);
if (stream.getString("type").equals("audio")) {
for (final String type :stream.getObject("urls").keySet()) {
final JsonObject url = stream.getObject("urls").getObject(type);
audioStreams.add(new AudioStream(url.getString("url"), MediaFormat.getFromSuffix(type), -1));
}
}
}
return audioStreams;
}

@Override
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
final List<VideoStream> videoStreams = new ArrayList<>();
for (int s = 0; s < room.getArray("streams").size(); s++) {
final JsonObject stream = room.getArray("streams").getObject(s);
if (stream.getString("type").equals("video")) {
final String resolution = stream.getArray("videoSize").getInt(0) + "x"
+ stream.getArray("videoSize").getInt(1);
for (final String type :stream.getObject("urls").keySet()) {
if (!type.equals("hls")) {
final JsonObject url = stream.getObject("urls").getObject(type);
videoStreams.add(new VideoStream(
url.getString("url"),
MediaFormat.getFromSuffix(type),
resolution));
}
}
}
}
return videoStreams;
}

@Override
public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException {
return null;
}

@Nonnull
@Override
public List<SubtitlesStream> getSubtitlesDefault(){
return Collections.emptyList();
}

@Nonnull
@Override
public List<SubtitlesStream> getSubtitles(MediaFormat format) {
return Collections.emptyList();
}

@Override
public StreamType getStreamType() throws ParsingException {
return StreamType.LIVE_STREAM; // TODO: video and audio only streams are both available
}

@Nullable
@Override
public StreamInfoItemsCollector getRelatedStreams() {
return null;
}

@Override
public String getErrorMessage() {
return null;
}

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

@Nonnull
@Override
public String getPrivacy() {
return "Public";
}

@Nonnull
@Override
public String getCategory() {
return group;
}

@Nonnull
@Override
public String getLicence() {
return "";
}

@Nullable
@Override
public Locale getLanguageInfo() {
return null;
}

@Nonnull
@Override
public List<String> getTags() {
return Collections.emptyList();
}

@Nonnull
@Override
public String getSupportInfo() {
return "";
}

@Nonnull
@Override
public List<StreamSegment> getStreamSegments() {
return Collections.emptyList();
}

@Nonnull
@Override
public List<MetaInfo> getMetaInfo() {
return Collections.emptyList();
}
}
Loading