[MediaCCC] Fix link handler inconsistency providing API links
This commit is contained in:
parent
aeeae87641
commit
b461da792f
|
@ -13,6 +13,7 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
|||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.services.media_ccc.extractors.infoItems.MediaCCCStreamInfoItemExtractor;
|
||||
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||
|
||||
|
@ -87,10 +88,11 @@ public class MediaCCCConferenceExtractor extends ChannelExtractor {
|
|||
@Override
|
||||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
final String conferenceUrl = MediaCCCConferenceLinkHandlerFactory.CONFERENCE_API_ENDPOINT + getId();
|
||||
try {
|
||||
conferenceData = JsonParser.object().from(downloader.get(getUrl()).responseBody());
|
||||
conferenceData = JsonParser.object().from(downloader.get(conferenceUrl).responseBody());
|
||||
} catch (JsonParserException jpe) {
|
||||
throw new ExtractionException("Could not parse json returnd by url: " + getUrl());
|
||||
throw new ExtractionException("Could not parse json returnd by url: " + conferenceUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,10 +101,4 @@ public class MediaCCCConferenceExtractor extends ChannelExtractor {
|
|||
public String getName() throws ParsingException {
|
||||
return conferenceData.getString("title");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getOriginalUrl() {
|
||||
return "https://media.ccc.de/c/" + conferenceData.getString("acronym");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
|||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCConferenceLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.media_ccc.linkHandler.MediaCCCStreamLinkHandlerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -93,7 +95,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
|
|||
@Nonnull
|
||||
@Override
|
||||
public String getUploaderUrl() {
|
||||
return data.getString("conference_url");
|
||||
return MediaCCCConferenceLinkHandlerFactory.CONFERENCE_PATH + getUploaderName();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
@ -111,25 +113,25 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getSubChannelUrl() throws ParsingException {
|
||||
public String getSubChannelUrl() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getSubChannelName() throws ParsingException {
|
||||
public String getSubChannelName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getSubChannelAvatarUrl() throws ParsingException {
|
||||
public String getSubChannelAvatarUrl() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getDashMpdUrl() throws ParsingException {
|
||||
public String getDashMpdUrl() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -227,14 +229,13 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
|
|||
@Override
|
||||
public void onFetchPage(@Nonnull final Downloader downloader)
|
||||
throws IOException, ExtractionException {
|
||||
final String videoUrl = MediaCCCStreamLinkHandlerFactory.VIDEO_API_ENDPOINT + getId();
|
||||
try {
|
||||
data = JsonParser.object().from(
|
||||
downloader.get(getLinkHandler().getUrl()).responseBody());
|
||||
data = JsonParser.object().from(downloader.get(videoUrl).responseBody());
|
||||
conferenceData = JsonParser.object()
|
||||
.from(downloader.get(getUploaderUrl()).responseBody());
|
||||
.from(downloader.get(data.getString("conference_url")).responseBody());
|
||||
} catch (JsonParserException jpe) {
|
||||
throw new ExtractionException("Could not parse json returned by url: "
|
||||
+ getLinkHandler().getUrl(), jpe);
|
||||
throw new ExtractionException("Could not parse json returned by url: " + videoUrl, jpe);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -250,21 +251,25 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
|
|||
return data.getString("frontend_link");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getHost() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getPrivacy() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getCategory() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public String getLicence() {
|
||||
return "";
|
||||
|
@ -277,7 +282,7 @@ public class MediaCCCStreamExtractor extends StreamExtractor {
|
|||
|
||||
@Nonnull
|
||||
@Override
|
||||
public List<String> getTags() throws ParsingException {
|
||||
public List<String> getTags() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,19 +7,23 @@ import org.schabi.newpipe.extractor.utils.Parser;
|
|||
import java.util.List;
|
||||
|
||||
public class MediaCCCConferenceLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
public static final String CONFERENCE_API_ENDPOINT = "https://api.media.ccc.de/public/conferences/";
|
||||
public static final String CONFERENCE_PATH = "https://media.ccc.de/c/";
|
||||
|
||||
@Override
|
||||
public String getUrl(final String id, final List<String> contentFilter, final String sortFilter)
|
||||
throws ParsingException {
|
||||
return "https://media.ccc.de/public/conferences/" + id;
|
||||
public String getUrl(final String id, final List<String> contentFilter,
|
||||
final String sortFilter) throws ParsingException {
|
||||
return CONFERENCE_PATH + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(final String url) throws ParsingException {
|
||||
if (url.startsWith("https://media.ccc.de/public/conferences/")
|
||||
|| url.startsWith("https://api.media.ccc.de/public/conferences/")) {
|
||||
return url.replaceFirst("https://(api\\.)?media\\.ccc\\.de/public/conferences/", "");
|
||||
} else if (url.startsWith("https://media.ccc.de/c/")) {
|
||||
return Parser.matchGroup1("https://media.ccc.de/c/([^?#]*)", url);
|
||||
if (url.startsWith(CONFERENCE_API_ENDPOINT)) {
|
||||
return url.replace(CONFERENCE_API_ENDPOINT, "");
|
||||
} else if (url.startsWith("https://media.ccc.de/public/conferences/")) {
|
||||
return url.replace("https://media.ccc.de/public/conferences/", "");
|
||||
} else if (url.startsWith(CONFERENCE_PATH)) {
|
||||
return Parser.matchGroup1(CONFERENCE_PATH + "([^?#]*)", url);
|
||||
} else if (url.startsWith("https://media.ccc.de/b/")) {
|
||||
return Parser.matchGroup1("https://media.ccc.de/b/([^?#]*)", url);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
|
||||
public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||
public static final String VIDEO_API_ENDPOINT = "https://api.media.ccc.de/public/events/";
|
||||
private static final String VIDEO_PATH = "https://media.ccc.de/v/";
|
||||
|
||||
@Override
|
||||
public String getId(final String urlString) throws ParsingException {
|
||||
if (urlString.startsWith("https://media.ccc.de/public/events/")
|
||||
|
@ -15,7 +18,7 @@ public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
return urlString.substring(35); //remove …/public/events part
|
||||
}
|
||||
|
||||
if (urlString.startsWith("https://api.media.ccc.de/public/events/")
|
||||
if (urlString.startsWith(VIDEO_API_ENDPOINT)
|
||||
&& !urlString.contains("?q=")) {
|
||||
return urlString.substring(39); //remove api…/public/events part
|
||||
}
|
||||
|
@ -42,7 +45,7 @@ public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
|
||||
@Override
|
||||
public String getUrl(final String id) throws ParsingException {
|
||||
return "https://media.ccc.de/public/events/" + id;
|
||||
return VIDEO_PATH + id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -31,7 +31,7 @@ public class MediaCCCConferenceExtractorTest {
|
|||
|
||||
@Test
|
||||
public void testGetUrl() throws Exception {
|
||||
assertEquals("https://media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
|
||||
assertEquals("https://media.ccc.de/c/froscon2017", extractor.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -67,7 +67,7 @@ public class MediaCCCConferenceExtractorTest {
|
|||
|
||||
@Test
|
||||
public void testGetUrl() throws Exception {
|
||||
assertEquals("https://media.ccc.de/public/conferences/oscal19", extractor.getUrl());
|
||||
assertEquals("https://media.ccc.de/c/oscal19", extractor.getUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue