2018-12-23 19:41:18 +01:00
|
|
|
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.MediaFormat;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
|
|
|
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.stream.*;
|
|
|
|
import org.schabi.newpipe.extractor.utils.Localization;
|
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class MediaCCCStreamExtractor extends StreamExtractor {
|
|
|
|
|
|
|
|
private JsonObject data;
|
|
|
|
private JsonObject conferenceData;
|
|
|
|
|
|
|
|
public MediaCCCStreamExtractor(StreamingService service, LinkHandler linkHandler, Localization localization) {
|
|
|
|
super(service, linkHandler, localization);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getUploadDate() throws ParsingException {
|
|
|
|
return data.getString("release_date");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getThumbnailUrl() throws ParsingException {
|
|
|
|
return data.getString("thumb_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getDescription() throws ParsingException {
|
|
|
|
return data.getString("description");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getAgeLimit() throws ParsingException {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getLength() throws ParsingException {
|
|
|
|
return data.getInt("length");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getTimeStamp() throws ParsingException {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getViewCount() throws ParsingException {
|
|
|
|
return data.getInt("view_count");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getLikeCount() throws ParsingException {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getDislikeCount() throws ParsingException {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getUploaderUrl() throws ParsingException {
|
|
|
|
return data.getString("conference_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getUploaderName() throws ParsingException {
|
|
|
|
return data.getString("conference_url")
|
|
|
|
.replace("https://api.media.ccc.de/public/conferences/", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getUploaderAvatarUrl() throws ParsingException {
|
|
|
|
return conferenceData.getString("logo_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getDashMpdUrl() throws ParsingException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getHlsUrl() throws ParsingException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
|
|
|
|
final JsonArray recordings = data.getArray("recordings");
|
|
|
|
final List<AudioStream> audioStreams = new ArrayList<>();
|
|
|
|
for(int i = 0; i < recordings.size(); i++) {
|
|
|
|
final JsonObject recording = recordings.getObject(i);
|
|
|
|
final String mimeType = recording.getString("mime_type");
|
|
|
|
if(mimeType.startsWith("audio")) {
|
|
|
|
//first we need to resolve the actual video data from CDN
|
|
|
|
final MediaFormat mediaFormat;
|
|
|
|
if(mimeType.endsWith("opus")) {
|
|
|
|
mediaFormat = MediaFormat.OPUS;
|
|
|
|
} else if(mimeType.endsWith("mpeg")) {
|
|
|
|
mediaFormat = MediaFormat.MP3;
|
|
|
|
} else {
|
|
|
|
throw new ExtractionException("Unknown media format: " + mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
audioStreams.add(new AudioStream(recording.getString("recording_url"), mediaFormat, -1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return audioStreams;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
|
|
|
|
final JsonArray recordings = data.getArray("recordings");
|
|
|
|
final List<VideoStream> videoStreams = new ArrayList<>();
|
|
|
|
for(int i = 0; i < recordings.size(); i++) {
|
|
|
|
final JsonObject recording = recordings.getObject(i);
|
|
|
|
final String mimeType = recording.getString("mime_type");
|
|
|
|
if(mimeType.startsWith("video")) {
|
|
|
|
//first we need to resolve the actual video data from CDN
|
|
|
|
|
|
|
|
final MediaFormat mediaFormat;
|
|
|
|
if(mimeType.endsWith("webm")) {
|
|
|
|
mediaFormat = MediaFormat.WEBM;
|
|
|
|
} else if(mimeType.endsWith("mp4")) {
|
|
|
|
mediaFormat = MediaFormat.MPEG_4;
|
|
|
|
} else {
|
|
|
|
throw new ExtractionException("Unknown media format: " + mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
videoStreams.add(new VideoStream(recording.getString("recording_url"),
|
|
|
|
mediaFormat,
|
|
|
|
Integer.toString(recording.getInt("height"))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return videoStreams;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public List<SubtitlesStream> getSubtitles(MediaFormat format) throws IOException, ExtractionException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamType getStreamType() throws ParsingException {
|
|
|
|
return StreamType.VIDEO_STREAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamInfoItem getNextStream() throws IOException, ExtractionException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StreamInfoItemsCollector getRelatedStreams() throws IOException, ExtractionException {
|
2018-12-23 20:25:19 +01:00
|
|
|
return new StreamInfoItemsCollector(getServiceId());
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getErrorMessage() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
|
|
|
try {
|
|
|
|
data = JsonParser.object().from(
|
|
|
|
downloader.download(getLinkHandler().getUrl()));
|
|
|
|
conferenceData = JsonParser.object()
|
|
|
|
.from(downloader.download(getUploaderUrl()));
|
|
|
|
} catch (JsonParserException jpe) {
|
|
|
|
throw new ExtractionException("Could not parse json returned by url: " + getLinkHandler().getUrl(), jpe);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getName() throws ParsingException {
|
|
|
|
return data.getString("title");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getOriginalUrl() throws ParsingException {
|
|
|
|
return data.getString("frontend_link");
|
|
|
|
}
|
|
|
|
}
|