2020-12-27 01:28:08 +01:00
|
|
|
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
|
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
import com.grack.nanojson.JsonArray;
|
2020-12-27 01:28:08 +01:00
|
|
|
import com.grack.nanojson.JsonObject;
|
2022-03-18 09:41:05 +01:00
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
import org.schabi.newpipe.extractor.MediaFormat;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2020-12-27 01:28:08 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2020-12-27 13:25:48 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
2022-03-18 09:41:05 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.AudioStream;
|
|
|
|
import org.schabi.newpipe.extractor.stream.Description;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
|
|
|
import org.schabi.newpipe.extractor.stream.StreamType;
|
|
|
|
import org.schabi.newpipe.extractor.stream.VideoStream;
|
2020-12-27 01:28:08 +01:00
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2022-03-18 09:41:05 +01:00
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
2020-12-27 01:28:08 +01:00
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
public class MediaCCCLiveStreamExtractor extends StreamExtractor {
|
|
|
|
private JsonObject conference = null;
|
|
|
|
private String group = "";
|
|
|
|
private JsonObject room = null;
|
2020-12-27 01:28:08 +01:00
|
|
|
|
2022-03-18 09:41:05 +01:00
|
|
|
public MediaCCCLiveStreamExtractor(final StreamingService service,
|
|
|
|
final LinkHandler linkHandler) {
|
2020-12-27 13:25:48 +01:00
|
|
|
super(service, linkHandler);
|
|
|
|
}
|
2020-12-27 01:28:08 +01:00
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
@Override
|
2022-03-18 09:41:05 +01:00
|
|
|
public void onFetchPage(@Nonnull final Downloader downloader)
|
|
|
|
throws IOException, ExtractionException {
|
|
|
|
final JsonArray doc =
|
|
|
|
MediaCCCParsingHelper.getLiveStreams(downloader, getExtractorLocalization());
|
2020-12-27 13:25:48 +01:00
|
|
|
// find correct room
|
|
|
|
for (int c = 0; c < doc.size(); c++) {
|
2022-03-18 09:41:05 +01:00
|
|
|
conference = doc.getObject(c);
|
2020-12-27 13:25:48 +01:00
|
|
|
final JsonArray groups = conference.getArray("groups");
|
|
|
|
for (int g = 0; g < groups.size(); g++) {
|
2022-03-18 09:41:05 +01:00
|
|
|
group = groups.getObject(g).getString("group");
|
2020-12-27 13:25:48 +01:00
|
|
|
final JsonArray rooms = groups.getObject(g).getArray("rooms");
|
|
|
|
for (int r = 0; r < rooms.size(); r++) {
|
2022-03-18 09:41:05 +01:00
|
|
|
room = rooms.getObject(r);
|
|
|
|
if (getId().equals(
|
|
|
|
conference.getString("slug") + "/" + room.getString("slug"))) {
|
2020-12-27 13:25:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new ExtractionException("Could not find room matching id: '" + getId() + "'");
|
2020-12-27 01:28:08 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
@Nonnull
|
2020-12-27 01:28:08 +01:00
|
|
|
@Override
|
|
|
|
public String getName() throws ParsingException {
|
2020-12-27 13:25:48 +01:00
|
|
|
return room.getString("display");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
2020-12-27 01:28:08 +01:00
|
|
|
@Override
|
|
|
|
public String getThumbnailUrl() throws ParsingException {
|
2020-12-27 13:25:48 +01:00
|
|
|
return room.getString("thumb");
|
2020-12-27 01:28:08 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
@Nonnull
|
2020-12-27 01:28:08 +01:00
|
|
|
@Override
|
2020-12-27 13:25:48 +01:00
|
|
|
public Description getDescription() throws ParsingException {
|
2022-03-18 09:41:05 +01:00
|
|
|
return new Description(conference.getString("description")
|
|
|
|
+ " - " + group, Description.PLAIN_TEXT);
|
2020-12-27 01:28:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-12-27 13:25:48 +01:00
|
|
|
public long getViewCount() {
|
2020-12-27 01:28:08 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
@Nonnull
|
2020-12-27 01:28:08 +01:00
|
|
|
@Override
|
|
|
|
public String getUploaderUrl() throws ParsingException {
|
2020-12-27 13:25:48 +01:00
|
|
|
return "https://streaming.media.ccc.de/" + conference.getString("slug");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getUploaderName() throws ParsingException {
|
|
|
|
return conference.getString("conference");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getHlsUrl() {
|
|
|
|
// TODO: There are multiple HLS streams.
|
2022-03-18 09:41:05 +01:00
|
|
|
// Make getHlsUrl() and getDashMpdUrl() return lists of VideoStreams,
|
|
|
|
// so the user can choose a resolution.
|
2020-12-27 13:25:48 +01:00
|
|
|
for (int s = 0; s < room.getArray("streams").size(); s++) {
|
|
|
|
final JsonObject stream = room.getArray("streams").getObject(s);
|
|
|
|
if (stream.getString("type").equals("video")) {
|
|
|
|
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")) {
|
2021-01-22 01:44:58 +01:00
|
|
|
for (final String type : stream.getObject("urls").keySet()) {
|
2020-12-27 13:25:48 +01:00
|
|
|
final JsonObject url = stream.getObject("urls").getObject(type);
|
2022-03-18 09:41:05 +01:00
|
|
|
audioStreams.add(new AudioStream(url.getString("url"),
|
|
|
|
MediaFormat.getFromSuffix(type), -1));
|
2020-12-27 13:25:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
2021-01-22 01:44:58 +01:00
|
|
|
for (final String type : stream.getObject("urls").keySet()) {
|
2020-12-27 13:25:48 +01:00
|
|
|
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
|
2021-03-14 00:43:46 +01:00
|
|
|
public List<VideoStream> getVideoOnlyStreams() {
|
2020-12-27 13:25:48 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamType getStreamType() throws ParsingException {
|
|
|
|
return StreamType.LIVE_STREAM; // TODO: video and audio only streams are both available
|
2020-12-27 01:28:08 +01:00
|
|
|
}
|
|
|
|
|
2020-12-27 13:25:48 +01:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getCategory() {
|
|
|
|
return group;
|
|
|
|
}
|
2020-12-27 01:28:08 +01:00
|
|
|
}
|