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;
|
2020-12-20 19:54:12 +01:00
|
|
|
import org.schabi.newpipe.extractor.MetaInfo;
|
2018-12-23 19:41:18 +01:00
|
|
|
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;
|
2020-02-09 11:59:23 +01:00
|
|
|
import org.schabi.newpipe.extractor.localization.Localization;
|
2020-04-09 20:25:22 +02:00
|
|
|
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
|
|
|
|
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCStreamLinkHandlerFactory;
|
2021-01-22 01:44:58 +01:00
|
|
|
import org.schabi.newpipe.extractor.stream.*;
|
2020-02-09 11:59:23 +01:00
|
|
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
2018-12-23 19:41:18 +01:00
|
|
|
|
2020-04-01 11:40:03 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2020-10-24 21:17:58 +02:00
|
|
|
import javax.annotation.Nullable;
|
2021-01-22 01:44:58 +01:00
|
|
|
import java.io.IOException;
|
2020-02-09 11:59:23 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
2018-12-23 19:41:18 +01:00
|
|
|
|
2020-04-01 11:40:03 +02:00
|
|
|
public class MediaCCCStreamExtractor extends StreamExtractor {
|
2018-12-23 19:41:18 +01:00
|
|
|
private JsonObject data;
|
|
|
|
private JsonObject conferenceData;
|
|
|
|
|
2020-04-01 11:40:03 +02:00
|
|
|
public MediaCCCStreamExtractor(final StreamingService service, final LinkHandler linkHandler) {
|
2019-04-28 22:03:16 +02:00
|
|
|
super(service, linkHandler);
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public String getTextualUploadDate() {
|
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
|
2020-04-01 11:40:03 +02:00
|
|
|
public String getThumbnailUrl() {
|
2018-12-23 19:41:18 +01:00
|
|
|
return data.getString("thumb_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public Description getDescription() {
|
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
|
2020-04-01 11:40:03 +02:00
|
|
|
public long getLength() {
|
2018-12-23 19:41:18 +01:00
|
|
|
return data.getInt("length");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public long getViewCount() {
|
2018-12-23 19:41:18 +01:00
|
|
|
return data.getInt("view_count");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public String getUploaderUrl() {
|
2020-04-09 20:25:22 +02:00
|
|
|
return MediaCCCConferenceLinkHandlerFactory.CONFERENCE_PATH + getUploaderName();
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public String getUploaderName() {
|
2018-12-23 19:41:18 +01:00
|
|
|
return data.getString("conference_url")
|
2020-04-01 11:40:03 +02:00
|
|
|
.replaceFirst("https://(api\\.)?media\\.ccc\\.de/public/conferences/", "");
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public String getUploaderAvatarUrl() {
|
2018-12-23 19:41:18 +01:00
|
|
|
return conferenceData.getString("logo_url");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public List<AudioStream> getAudioStreams() throws ExtractionException {
|
2018-12-23 19:41:18 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-04-01 11:40:03 +02:00
|
|
|
audioStreams.add(new AudioStream(recording.getString("recording_url"),
|
|
|
|
mediaFormat, -1));
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return audioStreams;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public List<VideoStream> getVideoStreams() throws ExtractionException {
|
2018-12-23 19:41:18 +01:00
|
|
|
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
|
2020-04-01 11:40:03 +02:00
|
|
|
public List<VideoStream> getVideoOnlyStreams() {
|
2020-04-11 17:43:26 +02:00
|
|
|
return Collections.emptyList();
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public StreamType getStreamType() {
|
2018-12-23 19:41:18 +01:00
|
|
|
return StreamType.VIDEO_STREAM;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-01 11:40:03 +02:00
|
|
|
public void onFetchPage(@Nonnull final Downloader downloader)
|
|
|
|
throws IOException, ExtractionException {
|
2020-04-09 20:25:22 +02:00
|
|
|
final String videoUrl = MediaCCCStreamLinkHandlerFactory.VIDEO_API_ENDPOINT + getId();
|
2018-12-23 19:41:18 +01:00
|
|
|
try {
|
2020-04-09 20:25:22 +02:00
|
|
|
data = JsonParser.object().from(downloader.get(videoUrl).responseBody());
|
2018-12-23 19:41:18 +01:00
|
|
|
conferenceData = JsonParser.object()
|
2020-04-09 20:25:22 +02:00
|
|
|
.from(downloader.get(data.getString("conference_url")).responseBody());
|
2018-12-23 19:41:18 +01:00
|
|
|
} catch (JsonParserException jpe) {
|
2020-04-09 20:25:22 +02:00
|
|
|
throw new ExtractionException("Could not parse json returned by url: " + videoUrl, jpe);
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
2020-04-01 11:40:03 +02:00
|
|
|
public String getOriginalUrl() {
|
2018-12-23 19:41:18 +01:00
|
|
|
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
|
2020-02-09 11:59:23 +01:00
|
|
|
public Locale getLanguageInfo() throws ParsingException {
|
|
|
|
return Localization.getLocaleFromThreeLetterCode(data.getString("original_language"));
|
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
|
2020-04-11 17:17:14 +02:00
|
|
|
public List<String> getTags() {
|
2020-02-09 11:59:23 +01:00
|
|
|
return JsonUtils.getStringListFromJsonArray(data.getArray("tags"));
|
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
|
|
|
}
|
2018-12-23 19:41:18 +01:00
|
|
|
}
|