[PeerTube] Support /w/ short video links
This commit is contained in:
parent
4f60225ddc
commit
599a91c88c
2 changed files with 29 additions and 13 deletions
|
@ -9,8 +9,12 @@ import org.schabi.newpipe.extractor.utils.Parser;
|
|||
public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
||||
|
||||
private static final PeertubeStreamLinkHandlerFactory instance = new PeertubeStreamLinkHandlerFactory();
|
||||
private static final String ID_PATTERN = "/videos/(watch/|embed/)?([^/?&#]*)";
|
||||
private static final String ID_PATTERN = "(/w/|(/videos/(watch/|embed/)?))([^/?&#]*)";
|
||||
public static final String VIDEO_API_ENDPOINT = "/api/v1/videos/";
|
||||
|
||||
// From PeerTube 3.3.0, the default path is /w/.
|
||||
// We still use /videos/watch/ for compatibility reasons:
|
||||
// /videos/watch/ is still accepted by >=3.3.0 but /w/ isn't by <3.3.0
|
||||
private static final String VIDEO_PATH = "/videos/watch/";
|
||||
|
||||
private PeertubeStreamLinkHandlerFactory() {
|
||||
|
@ -32,7 +36,7 @@ public class PeertubeStreamLinkHandlerFactory extends LinkHandlerFactory {
|
|||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException, IllegalArgumentException {
|
||||
return Parser.matchGroup(ID_PATTERN, url, 2);
|
||||
return Parser.matchGroup(ID_PATTERN, url, 4);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,7 +19,7 @@ public class PeertubeStreamLinkHandlerFactoryTest {
|
|||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host"));
|
||||
PeerTube.setInstance(new PeertubeInstance("https://framatube.org", "Framatube"));
|
||||
linkHandler = PeertubeStreamLinkHandlerFactory.getInstance();
|
||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||
}
|
||||
|
@ -30,22 +30,31 @@ public class PeertubeStreamLinkHandlerFactoryTest {
|
|||
linkHandler.fromUrl("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60").getId());
|
||||
assertEquals("986aac60-1263-4f73-9ce5-36b18225cb60",
|
||||
linkHandler.fromUrl("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60?fsdafs=fsafa").getId());
|
||||
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/videos/embed/9c9de5e8-0a1e-484a-b099-e80766180a6d").getId());
|
||||
assertEquals("986aac60-1263-4f73-9ce5-36b18225cb60",
|
||||
linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60").getId());
|
||||
assertEquals("986aac60-1263-4f73-9ce5-36b18225cb60",
|
||||
linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60?fsdafs=fsafa").getId());
|
||||
|
||||
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d").getId());
|
||||
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/videos/embed/9c9de5e8-0a1e-484a-b099-e80766180a6d").getId());
|
||||
assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d").getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
assertEquals("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60",
|
||||
linkHandler.fromId("986aac60-1263-4f73-9ce5-36b18225cb60").getUrl());
|
||||
assertEquals("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60",
|
||||
linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60").getUrl());
|
||||
assertEquals("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60",
|
||||
linkHandler.fromUrl("https://peertube.mastodon.host/videos/embed/986aac60-1263-4f73-9ce5-36b18225cb60").getUrl());
|
||||
assertEquals("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromId("9c9de5e8-0a1e-484a-b099-e80766180a6d").getUrl());
|
||||
assertEquals("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d").getUrl());
|
||||
assertEquals("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/videos/embed/9c9de5e8-0a1e-484a-b099-e80766180a6d").getUrl());
|
||||
assertEquals("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d").getUrl());
|
||||
assertEquals("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d",
|
||||
linkHandler.fromUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d").getUrl());
|
||||
}
|
||||
|
||||
|
||||
|
@ -53,7 +62,10 @@ public class PeertubeStreamLinkHandlerFactoryTest {
|
|||
public void testAcceptUrl() throws ParsingException {
|
||||
assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60"));
|
||||
assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60?fsdafs=fsafa"));
|
||||
|
||||
assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
|
||||
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/embed/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
|
||||
assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/api/v1/videos/watch/986aac60-1263-4f73-9ce5-36b18225cb60?fsdafs=fsafa"));
|
||||
assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
|
||||
assertTrue(linkHandler.acceptUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d"));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue