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.MediaFormat;
|
|
|
|
import org.schabi.newpipe.extractor.StreamingService;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
2018-12-23 19:41:18 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
2019-11-03 19:45:25 +01:00
|
|
|
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
2018-12-23 19:41:18 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.*;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
2020-03-02 22:38:44 +01:00
|
|
|
import java.util.Collections;
|
2018-12-23 19:41:18 +01:00
|
|
|
import java.util.List;
|
2020-01-25 13:16:42 +01:00
|
|
|
import java.util.Locale;
|
2018-12-23 19:41:18 +01:00
|
|
|
|
|
|
|
public class MediaCCCStreamExtractor extends StreamExtractor {
|
|
|
|
|
|
|
|
private JsonObject data;
|
|
|
|
private JsonObject conferenceData;
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
public MediaCCCStreamExtractor(StreamingService service, LinkHandler linkHandler) {
|
|
|
|
super(service, linkHandler);
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2019-04-28 22:03:16 +02:00
|
|
|
public String getTextualUploadDate() throws ParsingException {
|
2018-12-23 19:41:18 +01:00
|
|
|
return data.getString("release_date");
|
|
|
|
}
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
2019-11-03 19:45:25 +01:00
|
|
|
public DateWrapper getUploadDate() throws ParsingException {
|
|
|
|
return new DateWrapper(MediaCCCParsingHelper.parseDateFrom(getTextualUploadDate()));
|
2019-04-28 22:03:16 +02:00
|
|
|
}
|
|
|
|
|
2018-12-23 19:41:18 +01:00
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getThumbnailUrl() throws ParsingException {
|
|
|
|
return data.getString("thumb_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-02-06 23:35:46 +01:00
|
|
|
public Description getDescription() throws ParsingException {
|
2020-02-07 13:28:27 +01:00
|
|
|
return new Description(data.getString("description"), Description.PLAIN_TEXT);
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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 {
|
2020-03-02 22:38:44 +01:00
|
|
|
return "";
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getHlsUrl() throws ParsingException {
|
2020-03-02 22:38:44 +01:00
|
|
|
return "";
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<AudioStream> getAudioStreams() throws IOException, ExtractionException {
|
|
|
|
final JsonArray recordings = data.getArray("recordings");
|
|
|
|
final List<AudioStream> audioStreams = new ArrayList<>();
|
2020-02-08 23:58:46 +01:00
|
|
|
for (int i = 0; i < recordings.size(); i++) {
|
2018-12-23 19:41:18 +01:00
|
|
|
final JsonObject recording = recordings.getObject(i);
|
|
|
|
final String mimeType = recording.getString("mime_type");
|
2020-02-08 23:58:46 +01:00
|
|
|
if (mimeType.startsWith("audio")) {
|
2018-12-23 19:41:18 +01:00
|
|
|
//first we need to resolve the actual video data from CDN
|
|
|
|
final MediaFormat mediaFormat;
|
2020-02-08 23:58:46 +01:00
|
|
|
if (mimeType.endsWith("opus")) {
|
2018-12-23 19:41:18 +01:00
|
|
|
mediaFormat = MediaFormat.OPUS;
|
2020-02-08 23:58:46 +01:00
|
|
|
} else if (mimeType.endsWith("mpeg")) {
|
2018-12-23 19:41:18 +01:00
|
|
|
mediaFormat = MediaFormat.MP3;
|
2020-02-08 23:58:46 +01:00
|
|
|
} else if (mimeType.endsWith("ogg")) {
|
2019-01-29 16:04:19 +01:00
|
|
|
mediaFormat = MediaFormat.OGG;
|
2018-12-23 19:41:18 +01:00
|
|
|
} 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<>();
|
2020-02-08 23:58:46 +01:00
|
|
|
for (int i = 0; i < recordings.size(); i++) {
|
2018-12-23 19:41:18 +01:00
|
|
|
final JsonObject recording = recordings.getObject(i);
|
|
|
|
final String mimeType = recording.getString("mime_type");
|
2020-02-08 23:58:46 +01:00
|
|
|
if (mimeType.startsWith("video")) {
|
2018-12-23 19:41:18 +01:00
|
|
|
//first we need to resolve the actual video data from CDN
|
|
|
|
|
|
|
|
final MediaFormat mediaFormat;
|
2020-02-08 23:58:46 +01:00
|
|
|
if (mimeType.endsWith("webm")) {
|
2018-12-23 19:41:18 +01:00
|
|
|
mediaFormat = MediaFormat.WEBM;
|
2020-02-08 23:58:46 +01:00
|
|
|
} else if (mimeType.endsWith("mp4")) {
|
2018-12-23 19:41:18 +01:00
|
|
|
mediaFormat = MediaFormat.MPEG_4;
|
|
|
|
} else {
|
|
|
|
throw new ExtractionException("Unknown media format: " + mimeType);
|
|
|
|
}
|
|
|
|
|
|
|
|
videoStreams.add(new VideoStream(recording.getString("recording_url"),
|
2018-12-23 21:16:05 +01:00
|
|
|
mediaFormat, recording.getInt("height") + "p"));
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return videoStreams;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-02 22:38:44 +01:00
|
|
|
@Nonnull
|
2018-12-23 19:41:18 +01:00
|
|
|
@Override
|
|
|
|
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
|
2020-03-02 22:38:44 +01:00
|
|
|
return Collections.emptyList();
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
2020-03-02 22:38:44 +01:00
|
|
|
@Nonnull
|
2018-12-23 19:41:18 +01:00
|
|
|
@Override
|
2020-02-12 00:25:34 +01:00
|
|
|
public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
|
2020-03-02 22:38:44 +01:00
|
|
|
return Collections.emptyList();
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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(
|
2019-04-28 22:03:16 +02:00
|
|
|
downloader.get(getLinkHandler().getUrl()).responseBody());
|
2018-12-23 19:41:18 +01:00
|
|
|
conferenceData = JsonParser.object()
|
2019-04-28 22:03:16 +02:00
|
|
|
.from(downloader.get(getUploaderUrl()).responseBody());
|
2018-12-23 19:41:18 +01:00
|
|
|
} 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");
|
|
|
|
}
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
@Nonnull
|
2018-12-23 19:41:18 +01:00
|
|
|
@Override
|
|
|
|
public String getOriginalUrl() throws ParsingException {
|
|
|
|
return data.getString("frontend_link");
|
|
|
|
}
|
added metadata, fix descriptions, fix thumbnail, update tests
thumbnail: quality before: https://peertube.cpy.re/static/thumbnails/d2a5ec78-5f85-4090-8ec5-dc1102e022ea.jpg
quality after: https://peertube.cpy.re/static/previews/d2a5ec78-5f85-4090-8ec5-dc1102e022ea.jpg
description: we were getting about the first 260 characters, we now get full description (with fallback to first 260 chars if the get request for full description fails)
test: updated tests to match description, also changed some test: it was assertEquals(extracted, expected), but the proper way to do it is assertEquals(expected, extracted)
metadata: got host, privacy (public, private, unlisted), licence, language, tags
2020-01-19 12:45:52 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getHost() throws ParsingException {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getPrivacy() throws ParsingException {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getCategory() throws ParsingException {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getLicence() throws ParsingException {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-25 13:16:42 +01:00
|
|
|
public Locale getLanguageInfo() throws ParsingException {
|
|
|
|
return null;
|
added metadata, fix descriptions, fix thumbnail, update tests
thumbnail: quality before: https://peertube.cpy.re/static/thumbnails/d2a5ec78-5f85-4090-8ec5-dc1102e022ea.jpg
quality after: https://peertube.cpy.re/static/previews/d2a5ec78-5f85-4090-8ec5-dc1102e022ea.jpg
description: we were getting about the first 260 characters, we now get full description (with fallback to first 260 chars if the get request for full description fails)
test: updated tests to match description, also changed some test: it was assertEquals(extracted, expected), but the proper way to do it is assertEquals(expected, extracted)
metadata: got host, privacy (public, private, unlisted), licence, language, tags
2020-01-19 12:45:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public List<String> getTags() throws ParsingException {
|
|
|
|
return new ArrayList<>();
|
|
|
|
}
|
2020-01-23 14:19:22 +01:00
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
|
|
|
public String getSupportInfo() throws ParsingException {
|
|
|
|
return "";
|
|
|
|
}
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|