Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for non-api mediaccc links, invidious shortened links, refactor mediaccc tests #256

Merged
merged 5 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -104,13 +105,13 @@ public String getUploaderAvatarUrl() throws ParsingException {
@Nonnull
@Override
public String getDashMpdUrl() throws ParsingException {
return null;
return "";
}

@Nonnull
@Override
public String getHlsUrl() throws ParsingException {
return null;
return "";
}

@Override
Expand Down Expand Up @@ -173,13 +174,13 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
@Nonnull
@Override
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
return null;
return Collections.emptyList();
}

@Nonnull
@Override
public List<SubtitlesStream> getSubtitles(MediaFormat format) throws IOException, ExtractionException {
return null;
public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
return Collections.emptyList();
}

@Override
Expand Down Expand Up @@ -212,7 +213,6 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
} catch (JsonParserException jpe) {
throw new ExtractionException("Could not parse json returned by url: " + getLinkHandler().getUrl(), jpe);
}

}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ public String getId(String url) throws ParsingException {
return url.replace("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);
} else {
throw new ParsingException("Could not get id from url: " + url);
} else if (url.startsWith("https://media.ccc.de/b/")) {
return Parser.matchGroup1("https://media.ccc.de/b/([^?#]*)", url);
}
throw new ParsingException("Could not get id from url: " + url);
}

@Override
public boolean onAcceptUrl(String url) throws ParsingException {
return url.startsWith("https://api.media.ccc.de/public/conferences/")
|| url.startsWith("https://media.ccc.de/c/");
try {
getId(url);
return true;
} catch (ParsingException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,39 @@
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;

import org.schabi.newpipe.extractor.exceptions.FoundAdException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
import org.schabi.newpipe.extractor.utils.Utils;

import java.net.MalformedURLException;
import java.net.URL;

public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {

@Override
public String getId(String url) throws ParsingException {
if (url.startsWith("https://api.media.ccc.de/public/events/") &&
!url.contains("?q=")) {
return url.replace("https://api.media.ccc.de/public/events/", "");
public String getId(String urlString) throws ParsingException {
if (urlString.startsWith("https://api.media.ccc.de/public/events/") &&
!urlString.contains("?q=")) {
return urlString.substring(39); //remove api…/public/events part
}

URL url;
try {
url = Utils.stringToURL(urlString);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("The given URL is not valid");
}

String path = url.getPath();
// remove leading "/" of URL-path if URL-path is given
if (!path.isEmpty()) {
path = path.substring(1);
}

if (path.startsWith("v/")) {
return path.substring(2);
}

throw new ParsingException("Could not get id from url: " + url);
}

Expand All @@ -21,7 +44,11 @@ public String getUrl(String id) throws ParsingException {

@Override
public boolean onAcceptUrl(String url) throws ParsingException {
return url.startsWith("https://api.media.ccc.de/public/events/") &&
!url.contains("?q=");
try {
getId(url);
return true;
} catch (ParsingException e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,12 @@ public String getId(String urlString) throws ParsingException, IllegalArgumentEx
return assertIsID(id);
}

break;
String viewQueryValue = Utils.getQueryValue(url, "v");
if (viewQueryValue != null) {
return assertIsID(viewQueryValue);
}

return assertIsID(path);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,86 @@
import org.junit.Test;
import org.schabi.newpipe.DownloaderTestImpl;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceExtractor;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;

/**
* Test {@link MediaCCCConferenceExtractor}
*/
public class MediaCCCConferenceExtractorTest {
private static ChannelExtractor extractor;

@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = MediaCCC.getChannelExtractor("https://api.media.ccc.de/public/conferences/froscon2017");
extractor.fetchPage();
}
public static class FrOSCon2017 {
private static MediaCCCConferenceExtractor extractor;

@Test
public void testName() throws Exception {
assertEquals("FrOSCon 2017", extractor.getName());
}
@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (MediaCCCConferenceExtractor) MediaCCC.getChannelExtractor("https://media.ccc.de/c/froscon2017");
extractor.fetchPage();
}

@Test
public void testGetUrl() throws Exception {
assertEquals("https://api.media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
}
@Test
public void testName() throws Exception {
assertEquals("FrOSCon 2017", extractor.getName());
}

@Test
public void testGetOriginalUrl() throws Exception {
assertEquals("https://media.ccc.de/c/froscon2017", extractor.getOriginalUrl());
}
@Test
public void testGetUrl() throws Exception {
assertEquals("https://api.media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
}

@Test
public void testGetOriginalUrl() throws Exception {
assertEquals("https://media.ccc.de/c/froscon2017", extractor.getOriginalUrl());
}

@Test
public void testGetThumbnailUrl() throws Exception {
assertEquals("https://static.media.ccc.de/media/events/froscon/2017/logo.png", extractor.getAvatarUrl());
}

@Test
public void testGetThumbnailUrl() throws Exception {
assertEquals("https://static.media.ccc.de/media/events/froscon/2017/logo.png", extractor.getAvatarUrl());
@Test
public void testGetInitalPage() throws Exception {
assertEquals(97, extractor.getInitialPage().getItems().size());
}
}

@Test
public void testGetInitalPage() throws Exception {
assertEquals(97, extractor.getInitialPage().getItems().size());
public static class Oscal2019 {
private static MediaCCCConferenceExtractor extractor;

@BeforeClass
public static void setUpClass() throws Exception {
NewPipe.init(DownloaderTestImpl.getInstance());
extractor = (MediaCCCConferenceExtractor) MediaCCC.getChannelExtractor("https://media.ccc.de/c/oscal19");
extractor.fetchPage();
}

@Test
public void testName() throws Exception {
assertEquals("Open Source Conference Albania 2019", extractor.getName());
}

@Test
public void testGetUrl() throws Exception {
assertEquals("https://api.media.ccc.de/public/conferences/oscal19", extractor.getUrl());
}

@Test
public void testGetOriginalUrl() throws Exception {
assertEquals("https://media.ccc.de/c/oscal19", extractor.getOriginalUrl());
}

@Test
public void testGetThumbnailUrl() throws Exception {
assertEquals("https://static.media.ccc.de/media/events/oscal/2019/oscal-19.png", extractor.getAvatarUrl());
}

@Test
public void testGetInitalPage() throws Exception {
assertTrue(extractor.getInitialPage().getItems().size() >= 21);
}
}
}
Loading