Skip to content

Commit 65a7eda

Browse files
authored
Merge pull request #256 from B0pol/mediaccc
Support for non-api mediaccc links, invidious shortened links, refactor mediaccc tests
2 parents 40b3bc1 + 66518ec commit 65a7eda

6 files changed

Lines changed: 301 additions & 120 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import javax.annotation.Nonnull;
1717
import java.io.IOException;
1818
import java.util.ArrayList;
19+
import java.util.Collections;
1920
import java.util.List;
2021
import java.util.Locale;
2122

@@ -104,13 +105,13 @@ public String getUploaderAvatarUrl() throws ParsingException {
104105
@Nonnull
105106
@Override
106107
public String getDashMpdUrl() throws ParsingException {
107-
return null;
108+
return "";
108109
}
109110

110111
@Nonnull
111112
@Override
112113
public String getHlsUrl() throws ParsingException {
113-
return null;
114+
return "";
114115
}
115116

116117
@Override
@@ -173,13 +174,13 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
173174
@Nonnull
174175
@Override
175176
public List<SubtitlesStream> getSubtitlesDefault() throws IOException, ExtractionException {
176-
return null;
177+
return Collections.emptyList();
177178
}
178179

179180
@Nonnull
180181
@Override
181-
public List<SubtitlesStream> getSubtitles(MediaFormat format) throws IOException, ExtractionException {
182-
return null;
182+
public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws IOException, ExtractionException {
183+
return Collections.emptyList();
183184
}
184185

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

218218
@Nonnull

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCConferenceLinkHandlerFactory.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ public String getId(String url) throws ParsingException {
1919
return url.replace("https://api.media.ccc.de/public/conferences/", "");
2020
} else if (url.startsWith("https://media.ccc.de/c/")) {
2121
return Parser.matchGroup1("https://media.ccc.de/c/([^?#]*)", url);
22-
} else {
23-
throw new ParsingException("Could not get id from url: " + url);
22+
} else if (url.startsWith("https://media.ccc.de/b/")) {
23+
return Parser.matchGroup1("https://media.ccc.de/b/([^?#]*)", url);
2424
}
25+
throw new ParsingException("Could not get id from url: " + url);
2526
}
2627

2728
@Override
2829
public boolean onAcceptUrl(String url) throws ParsingException {
29-
return url.startsWith("https://api.media.ccc.de/public/conferences/")
30-
|| url.startsWith("https://media.ccc.de/c/");
30+
try {
31+
getId(url);
32+
return true;
33+
} catch (ParsingException e) {
34+
return false;
35+
}
3136
}
3237
}
Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;
22

3+
import org.schabi.newpipe.extractor.exceptions.FoundAdException;
34
import org.schabi.newpipe.extractor.exceptions.ParsingException;
45
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
6+
import org.schabi.newpipe.extractor.utils.Utils;
7+
8+
import java.net.MalformedURLException;
9+
import java.net.URL;
510

611
public class MediaCCCStreamLinkHandlerFactory extends LinkHandlerFactory {
712

813
@Override
9-
public String getId(String url) throws ParsingException {
10-
if (url.startsWith("https://api.media.ccc.de/public/events/") &&
11-
!url.contains("?q=")) {
12-
return url.replace("https://api.media.ccc.de/public/events/", "");
14+
public String getId(String urlString) throws ParsingException {
15+
if (urlString.startsWith("https://api.media.ccc.de/public/events/") &&
16+
!urlString.contains("?q=")) {
17+
return urlString.substring(39); //remove api…/public/events part
18+
}
19+
20+
URL url;
21+
try {
22+
url = Utils.stringToURL(urlString);
23+
} catch (MalformedURLException e) {
24+
throw new IllegalArgumentException("The given URL is not valid");
25+
}
26+
27+
String path = url.getPath();
28+
// remove leading "/" of URL-path if URL-path is given
29+
if (!path.isEmpty()) {
30+
path = path.substring(1);
1331
}
32+
33+
if (path.startsWith("v/")) {
34+
return path.substring(2);
35+
}
36+
1437
throw new ParsingException("Could not get id from url: " + url);
1538
}
1639

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

2245
@Override
2346
public boolean onAcceptUrl(String url) throws ParsingException {
24-
return url.startsWith("https://api.media.ccc.de/public/events/") &&
25-
!url.contains("?q=");
47+
try {
48+
getId(url);
49+
return true;
50+
} catch (ParsingException e) {
51+
return false;
52+
}
2653
}
2754
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,12 @@ public String getId(String urlString) throws ParsingException, IllegalArgumentEx
202202
return assertIsID(id);
203203
}
204204

205-
break;
205+
String viewQueryValue = Utils.getQueryValue(url, "v");
206+
if (viewQueryValue != null) {
207+
return assertIsID(viewQueryValue);
208+
}
209+
210+
return assertIsID(path);
206211
}
207212
}
208213

extractor/src/test/java/org/schabi/newpipe/extractor/services/media_ccc/MediaCCCConferenceExtractorTest.java

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,86 @@
44
import org.junit.Test;
55
import org.schabi.newpipe.DownloaderTestImpl;
66
import org.schabi.newpipe.extractor.NewPipe;
7-
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
87
import org.schabi.newpipe.extractor.services.media_ccc.extractors.MediaCCCConferenceExtractor;
98

109
import static junit.framework.TestCase.assertEquals;
10+
import static org.junit.Assert.assertTrue;
1111
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
1212

1313
/**
1414
* Test {@link MediaCCCConferenceExtractor}
1515
*/
1616
public class MediaCCCConferenceExtractorTest {
17-
private static ChannelExtractor extractor;
1817

19-
@BeforeClass
20-
public static void setUpClass() throws Exception {
21-
NewPipe.init(DownloaderTestImpl.getInstance());
22-
extractor = MediaCCC.getChannelExtractor("https://api.media.ccc.de/public/conferences/froscon2017");
23-
extractor.fetchPage();
24-
}
18+
public static class FrOSCon2017 {
19+
private static MediaCCCConferenceExtractor extractor;
2520

26-
@Test
27-
public void testName() throws Exception {
28-
assertEquals("FrOSCon 2017", extractor.getName());
29-
}
21+
@BeforeClass
22+
public static void setUpClass() throws Exception {
23+
NewPipe.init(DownloaderTestImpl.getInstance());
24+
extractor = (MediaCCCConferenceExtractor) MediaCCC.getChannelExtractor("https://media.ccc.de/c/froscon2017");
25+
extractor.fetchPage();
26+
}
3027

31-
@Test
32-
public void testGetUrl() throws Exception {
33-
assertEquals("https://api.media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
34-
}
28+
@Test
29+
public void testName() throws Exception {
30+
assertEquals("FrOSCon 2017", extractor.getName());
31+
}
3532

36-
@Test
37-
public void testGetOriginalUrl() throws Exception {
38-
assertEquals("https://media.ccc.de/c/froscon2017", extractor.getOriginalUrl());
39-
}
33+
@Test
34+
public void testGetUrl() throws Exception {
35+
assertEquals("https://api.media.ccc.de/public/conferences/froscon2017", extractor.getUrl());
36+
}
37+
38+
@Test
39+
public void testGetOriginalUrl() throws Exception {
40+
assertEquals("https://media.ccc.de/c/froscon2017", extractor.getOriginalUrl());
41+
}
42+
43+
@Test
44+
public void testGetThumbnailUrl() throws Exception {
45+
assertEquals("https://static.media.ccc.de/media/events/froscon/2017/logo.png", extractor.getAvatarUrl());
46+
}
4047

41-
@Test
42-
public void testGetThumbnailUrl() throws Exception {
43-
assertEquals("https://static.media.ccc.de/media/events/froscon/2017/logo.png", extractor.getAvatarUrl());
48+
@Test
49+
public void testGetInitalPage() throws Exception {
50+
assertEquals(97, extractor.getInitialPage().getItems().size());
51+
}
4452
}
4553

46-
@Test
47-
public void testGetInitalPage() throws Exception {
48-
assertEquals(97, extractor.getInitialPage().getItems().size());
54+
public static class Oscal2019 {
55+
private static MediaCCCConferenceExtractor extractor;
56+
57+
@BeforeClass
58+
public static void setUpClass() throws Exception {
59+
NewPipe.init(DownloaderTestImpl.getInstance());
60+
extractor = (MediaCCCConferenceExtractor) MediaCCC.getChannelExtractor("https://media.ccc.de/c/oscal19");
61+
extractor.fetchPage();
62+
}
63+
64+
@Test
65+
public void testName() throws Exception {
66+
assertEquals("Open Source Conference Albania 2019", extractor.getName());
67+
}
68+
69+
@Test
70+
public void testGetUrl() throws Exception {
71+
assertEquals("https://api.media.ccc.de/public/conferences/oscal19", extractor.getUrl());
72+
}
73+
74+
@Test
75+
public void testGetOriginalUrl() throws Exception {
76+
assertEquals("https://media.ccc.de/c/oscal19", extractor.getOriginalUrl());
77+
}
78+
79+
@Test
80+
public void testGetThumbnailUrl() throws Exception {
81+
assertEquals("https://static.media.ccc.de/media/events/oscal/2019/oscal-19.png", extractor.getAvatarUrl());
82+
}
83+
84+
@Test
85+
public void testGetInitalPage() throws Exception {
86+
assertTrue(extractor.getInitialPage().getItems().size() >= 21);
87+
}
4988
}
5089
}

0 commit comments

Comments
 (0)