Skip to content

Commit 743a400

Browse files
authored
Merge pull request #1207 from TeamNewPipe/fix/peertube-certain-domains
[PeerTube] Fix parsing ID for instances whose domain ends with a or c
2 parents eb30316 + bcacfc5 commit 743a400

3 files changed

Lines changed: 128 additions & 7 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
66
import org.schabi.newpipe.extractor.utils.Parser;
77

8+
import javax.annotation.Nonnull;
89
import java.net.MalformedURLException;
910
import java.net.URL;
1011
import java.util.List;
@@ -14,6 +15,7 @@ public final class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFact
1415
private static final PeertubeChannelLinkHandlerFactory INSTANCE
1516
= new PeertubeChannelLinkHandlerFactory();
1617
private static final String ID_PATTERN = "((accounts|a)|(video-channels|c))/([^/?&#]*)";
18+
private static final String ID_URL_PATTERN = "/((accounts|a)|(video-channels|c))/([^/?&#]*)";
1719
public static final String API_ENDPOINT = "/api/v1/";
1820

1921
private PeertubeChannelLinkHandlerFactory() {
@@ -25,7 +27,7 @@ public static PeertubeChannelLinkHandlerFactory getInstance() {
2527

2628
@Override
2729
public String getId(final String url) throws ParsingException, UnsupportedOperationException {
28-
return fixId(Parser.matchGroup(ID_PATTERN, url, 0));
30+
return fixId(Parser.matchGroup(ID_URL_PATTERN, url, 0));
2931
}
3032

3133
@Override
@@ -74,12 +76,13 @@ public boolean onAcceptUrl(final String url) {
7476
* @param id the id to fix
7577
* @return the fixed id
7678
*/
77-
private String fixId(final String id) {
78-
if (id.startsWith("a/")) {
79-
return "accounts" + id.substring(1);
80-
} else if (id.startsWith("c/")) {
81-
return "video-channels" + id.substring(1);
79+
private String fixId(@Nonnull final String id) {
80+
final String cleanedId = id.startsWith("/") ? id.substring(1) : id;
81+
if (cleanedId.startsWith("a/")) {
82+
return "accounts" + cleanedId.substring(1);
83+
} else if (cleanedId.startsWith("c/")) {
84+
return "video-channels" + cleanedId.substring(1);
8285
}
83-
return id;
86+
return cleanedId;
8487
}
8588
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelExtractorTest.java

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,111 @@ public void testTags() throws Exception {
234234
assertTrue(extractor.getTags().isEmpty());
235235
}
236236
}
237+
238+
public static class DocumentaryChannel implements BaseChannelExtractorTest {
239+
// https://github.com/TeamNewPipe/NewPipe/issues/11369
240+
241+
private static PeertubeChannelExtractor extractor;
242+
243+
@BeforeAll
244+
public static void setUp() throws Exception {
245+
NewPipe.init(DownloaderTestImpl.getInstance());
246+
// setting instance might break test when running in parallel
247+
PeerTube.setInstance(new PeertubeInstance("https://kolektiva.media", "kolektiva.media"));
248+
extractor = (PeertubeChannelExtractor) PeerTube
249+
.getChannelExtractor("https://kolektiva.media/video-channels/documentary_channel");
250+
extractor.fetchPage();
251+
}
252+
253+
/*//////////////////////////////////////////////////////////////////////////
254+
// Extractor
255+
//////////////////////////////////////////////////////////////////////////*/
256+
257+
@Test
258+
public void testServiceId() {
259+
assertEquals(PeerTube.getServiceId(), extractor.getServiceId());
260+
}
261+
262+
@Test
263+
public void testName() throws ParsingException {
264+
assertEquals("Documentary Channel", extractor.getName());
265+
}
266+
267+
@Test
268+
public void testId() throws ParsingException {
269+
assertEquals("video-channels/documentary_channel", extractor.getId());
270+
}
271+
272+
@Test
273+
public void testUrl() throws ParsingException {
274+
assertEquals("https://kolektiva.media/video-channels/documentary_channel", extractor.getUrl());
275+
}
276+
277+
@Test
278+
public void testOriginalUrl() throws ParsingException {
279+
assertEquals("https://kolektiva.media/video-channels/documentary_channel", extractor.getOriginalUrl());
280+
}
281+
282+
/*//////////////////////////////////////////////////////////////////////////
283+
// ChannelExtractor
284+
//////////////////////////////////////////////////////////////////////////*/
285+
286+
@Test
287+
public void testDescription() {
288+
assertNotNull(extractor.getDescription());
289+
}
290+
291+
@Test
292+
void testParentChannelName() throws ParsingException {
293+
assertEquals("consumedmind", extractor.getParentChannelName());
294+
}
295+
296+
@Test
297+
void testParentChannelUrl() throws ParsingException {
298+
assertEquals("https://kolektiva.media/accounts/consumedmind", extractor.getParentChannelUrl());
299+
}
300+
301+
@Test
302+
void testParentChannelAvatars() {
303+
defaultTestImageCollection(extractor.getParentChannelAvatars());
304+
}
305+
306+
@Test
307+
public void testAvatars() {
308+
defaultTestImageCollection(extractor.getAvatars());
309+
}
310+
311+
@Test
312+
public void testBanners() throws ParsingException {
313+
assertGreaterOrEqual(1, extractor.getBanners().size());
314+
}
315+
316+
@Test
317+
public void testFeedUrl() throws ParsingException {
318+
assertEquals("https://kolektiva.media/feeds/videos.xml?videoChannelId=2994", extractor.getFeedUrl());
319+
}
320+
321+
@Test
322+
public void testSubscriberCount() {
323+
assertGreaterOrEqual(25, extractor.getSubscriberCount());
324+
}
325+
326+
@Test
327+
@Override
328+
public void testVerified() throws Exception {
329+
assertFalse(extractor.isVerified());
330+
}
331+
332+
@Test
333+
@Override
334+
public void testTabs() throws Exception {
335+
assertTabsContain(extractor.getTabs(), ChannelTabs.VIDEOS, ChannelTabs.PLAYLISTS);
336+
}
337+
338+
@Test
339+
@Override
340+
public void testTags() throws Exception {
341+
assertTrue(extractor.getTags().isEmpty());
342+
}
343+
}
237344
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public void acceptUrlTest() throws ParsingException {
3333
assertTrue(linkHandler.acceptUrl("https://peertube.stream/video-channels/kranti_channel@videos.squat.net/videos"));
3434
assertTrue(linkHandler.acceptUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/videos"));
3535
assertTrue(linkHandler.acceptUrl("https://peertube.stream/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa"));
36+
assertTrue(linkHandler.acceptUrl("https://kolektiva.media/video-channels/documentary_channel"));
3637

3738
assertDoNotAcceptNonURLs(linkHandler);
3839
}
@@ -60,6 +61,16 @@ public void getId() throws ParsingException {
6061
linkHandler.fromUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/video-playlists").getId());
6162
assertEquals("video-channels/kranti_channel@videos.squat.net",
6263
linkHandler.fromUrl("https://peertube.stream/api/v1/video-channels/kranti_channel@videos.squat.net").getId());
64+
65+
// instance URL ending with an "a": https://kolektiva.media
66+
assertEquals("video-channels/documentary_channel",
67+
linkHandler.fromUrl("https://kolektiva.media/video-channels/documentary_channel/videos").getId());
68+
assertEquals("video-channels/documentary_channel",
69+
linkHandler.fromUrl("https://kolektiva.media/c/documentary_channel/videos").getId());
70+
assertEquals("video-channels/documentary_channel",
71+
linkHandler.fromUrl("https://kolektiva.media/c/documentary_channel/video-playlists").getId());
72+
assertEquals("video-channels/documentary_channel",
73+
linkHandler.fromUrl("https://kolektiva.media/api/v1/video-channels/documentary_channel").getId());
6374
}
6475

6576
@Test

0 commit comments

Comments
 (0)