diff --git a/build.gradle b/build.gradle index 26caca7cf3..f8291abd17 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ allprojects { ext { nanojsonVersion = "1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751" - spotbugsVersion = "4.4.2" + spotbugsVersion = "4.5.0" junitVersion = "4.13.2" } } diff --git a/extractor/build.gradle b/extractor/build.gradle index 8cd1298981..a714b5a47e 100644 --- a/extractor/build.gradle +++ b/extractor/build.gradle @@ -16,5 +16,5 @@ dependencies { testImplementation "junit:junit:$junitVersion" testImplementation "com.squareup.okhttp3:okhttp:3.12.13" - testImplementation 'com.google.code.gson:gson:2.8.8' + testImplementation 'com.google.code.gson:gson:2.8.9' } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java index 506bee5363..439ade4316 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/comments/CommentsInfo.java @@ -24,9 +24,9 @@ public static CommentsInfo getInfo(final String url) throws IOException, Extract return getInfo(NewPipe.getServiceByUrl(url), url); } - public static CommentsInfo getInfo(final StreamingService serviceByUrl, final String url) + public static CommentsInfo getInfo(final StreamingService service, final String url) throws ExtractionException, IOException { - return getInfo(serviceByUrl.getCommentsExtractor(url)); + return getInfo(service.getCommentsExtractor(url)); } public static CommentsInfo getInfo(final CommentsExtractor commentsExtractor) @@ -63,7 +63,7 @@ public static InfoItemsPage getMoreItems( final StreamingService service, final CommentsInfo commentsInfo, final Page page) throws IOException, ExtractionException { - if (null == commentsInfo.getCommentsExtractor()) { + if (commentsInfo.getCommentsExtractor() == null) { commentsInfo.setCommentsExtractor(service.getCommentsExtractor(commentsInfo.getUrl())); commentsInfo.getCommentsExtractor().fetchPage(); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java index 9134c14e5e..950514b0e6 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeChannelLinkHandlerFactory.java @@ -10,7 +10,7 @@ public class PeertubeChannelLinkHandlerFactory extends ListLinkHandlerFactory { private static final PeertubeChannelLinkHandlerFactory instance = new PeertubeChannelLinkHandlerFactory(); - private static final String ID_PATTERN = "(accounts|video-channels)/([^/?&#]*)"; + private static final String ID_PATTERN = "((accounts|a)|(video-channels|c))/([^/?&#]*)"; public static final String API_ENDPOINT = "/api/v1/"; public static PeertubeChannelLinkHandlerFactory getInstance() { @@ -19,7 +19,7 @@ public static PeertubeChannelLinkHandlerFactory getInstance() { @Override public String getId(String url) throws ParsingException { - return Parser.matchGroup(ID_PATTERN, url, 0); + return fixId(Parser.matchGroup(ID_PATTERN, url, 0)); } @Override @@ -31,7 +31,7 @@ public String getUrl(String id, List contentFilters, String searchFilter public String getUrl(String id, List contentFilter, String sortFilter, String baseUrl) throws ParsingException { if (id.matches(ID_PATTERN)) { - return baseUrl + "/" + id; + return baseUrl + "/" + fixId(id); } else { // This is needed for compatibility with older versions were we didn't support video channels yet return baseUrl + "/accounts/" + id; @@ -40,6 +40,28 @@ public String getUrl(String id, List contentFilter, String sortFilter, S @Override public boolean onAcceptUrl(String url) { - return url.contains("/accounts/") || url.contains("/video-channels/"); + return url.contains("/accounts/") || url.contains("/a/") + || url.contains("/video-channels/") || url.contains("/c/"); + } + + /** + * Fix id + * + *

+ * a/:accountName and c/:channelName ids are supported + * by the PeerTube web client (>= v3.3.0) + * but not by the API. + *

+ * + * @param id the id to fix + * @return the fixed id + */ + private String fixId(String id) { + if (id.startsWith("a/")) { + id = "accounts" + id.substring(1); + } else if (id.startsWith("c/")) { + id = "video-channels" + id.substring(1); + } + return id; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java index 9c8337507b..3bf531a8d0 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeCommentsLinkHandlerFactory.java @@ -11,7 +11,6 @@ public class PeertubeCommentsLinkHandlerFactory extends ListLinkHandlerFactory { private static final PeertubeCommentsLinkHandlerFactory instance = new PeertubeCommentsLinkHandlerFactory(); - private static final String ID_PATTERN = "/videos/(watch/)?([^/?&#]*)"; private static final String COMMENTS_ENDPOINT = "/api/v1/videos/%s/comment-threads"; public static PeertubeCommentsLinkHandlerFactory getInstance() { @@ -20,12 +19,12 @@ public static PeertubeCommentsLinkHandlerFactory getInstance() { @Override public String getId(String url) throws ParsingException, IllegalArgumentException { - return Parser.matchGroup(ID_PATTERN, url, 2); + return PeertubeStreamLinkHandlerFactory.getInstance().getId(url); // the same id is needed } @Override public boolean onAcceptUrl(final String url) throws FoundAdException { - return url.contains("/videos/"); + return url.contains("/videos/") || url.contains("/w/"); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java index 72b1d87fdf..f27e55eb1a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubePlaylistLinkHandlerFactory.java @@ -11,7 +11,7 @@ public class PeertubePlaylistLinkHandlerFactory extends ListLinkHandlerFactory { private static final PeertubePlaylistLinkHandlerFactory instance = new PeertubePlaylistLinkHandlerFactory(); - private static final String ID_PATTERN = "/videos/watch/playlist/([^/?&#]*)"; + private static final String ID_PATTERN = "(/videos/watch/playlist/|/w/p/)([^/?&#]*)"; public static PeertubePlaylistLinkHandlerFactory getInstance() { return instance; @@ -30,7 +30,7 @@ public String getUrl(String id, List contentFilters, String sortFilter, @Override public String getId(String url) throws ParsingException { - return Parser.matchGroup1(ID_PATTERN, url); + return Parser.matchGroup(ID_PATTERN, url, 2); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java index 16b3fed3f8..fdd69afb98 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeStreamLinkHandlerFactory.java @@ -9,8 +9,13 @@ 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/)?))(?!p/)([^/?&#]*)"; + // we exclude p/ because /w/p/ is playlist, not video 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 +37,7 @@ public String getUrl(String id, String baseUrl) { @Override public String getId(String url) throws ParsingException, IllegalArgumentException { - return Parser.matchGroup(ID_PATTERN, url, 2); + return Parser.matchGroup(ID_PATTERN, url, 4); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java index aa7c8783da..0a1fcee943 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudParsingHelper.java @@ -41,7 +41,7 @@ public class SoundcloudParsingHelper { private static final String HARDCODED_CLIENT_ID = - "yoxLvaFlJ3V5LbNCt53Cwvw5KXKKxWfn"; // Updated on 01/10/21 + "nGKlrpy2IotLQ0QGwBOmIgSFayis6H4e"; // Updated on 04/11/21 private static String clientId; public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/"; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 210f7a8c2c..6f36bb30b8 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -162,6 +162,10 @@ public static boolean isInvidioURL(@Nonnull final URL url) { || host.equalsIgnoreCase("y.com.cm"); } + public static boolean isY2ubeURL(@Nonnull final URL url) { + return url.getHost().equalsIgnoreCase("y2u.be"); + } + /** * Parses the duration string of the video expecting ":" or "." as separators * diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 43d765c855..cd15eea374 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -337,19 +337,33 @@ public long getViewCount() throws ParsingException { @Override public long getLikeCount() throws ParsingException { assertPageFetched(); - String likesString = ""; + String likesString = null; try { - try { - likesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar") - .getObject("sentimentBarRenderer").getString("tooltip").split("/")[0]; - } catch (final NullPointerException e) { + likesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar") + .getObject("sentimentBarRenderer").getString("tooltip"); + if (likesString != null && likesString.contains("/")) { + likesString = likesString.split("/")[0]; + } else { + likesString = getVideoPrimaryInfoRenderer() + .getObject("videoActions") + .getObject("menuRenderer") + .getArray("topLevelButtons") + .getObject(0) + .getObject("toggleButtonRenderer") + .getObject("defaultText") + .getObject("accessibility") + .getObject("accessibilityData") + .getString("label"); + } + + if (likesString == null) { // If this kicks in our button has no content and therefore ratings must be disabled if (playerResponse.getObject("videoDetails").getBoolean("allowRatings")) { - throw new ParsingException( - "Ratings are enabled even though the like button is missing", e); + throw new ParsingException("Ratings are enabled even though the like button is missing"); } return -1; } + return Integer.parseInt(Utils.removeNonDigitCharacters(likesString)); } catch (final NumberFormatException nfe) { throw new ParsingException("Could not parse \"" + likesString + "\" as an Integer", @@ -366,29 +380,28 @@ public long getLikeCount() throws ParsingException { public long getDislikeCount() throws ParsingException { assertPageFetched(); - String dislikesString = ""; try { - try { - dislikesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar") - .getObject("sentimentBarRenderer").getString("tooltip").split("/")[1]; - } catch (final NullPointerException e) { - // If this kicks in our button has no content and therefore ratings must be disabled - if (playerResponse.getObject("videoDetails").getBoolean("allowRatings")) { - throw new ParsingException( - "Ratings are enabled even though the dislike button is missing", e); + String dislikesString = getVideoPrimaryInfoRenderer().getObject("sentimentBar") + .getObject("sentimentBarRenderer").getString("tooltip"); + if (dislikesString != null && dislikesString.contains("/")) { + dislikesString = dislikesString.split("/")[1]; + return Integer.parseInt(Utils.removeNonDigitCharacters(dislikesString)); + } else { + // Calculate dislike with average rating and like count + long likes = getLikeCount(); + double averageRating = playerResponse.getObject("videoDetails").getDouble("averageRating"); + + if (likes != -1 && averageRating > 1) { + // If averageRating can't be gathered, it will be 0, + // but we also can't divide by 0 so we need > 1 + return Math.round(likes * ((5 - averageRating) / (averageRating - 1))); } - return -1; } - return Integer.parseInt(Utils.removeNonDigitCharacters(dislikesString)); - } catch (final NumberFormatException nfe) { - throw new ParsingException("Could not parse \"" + dislikesString + "\" as an Integer", - nfe); } catch (final Exception e) { - if (getAgeLimit() == NO_AGE_LIMIT) { - throw new ParsingException("Could not get dislike count", e); - } - return -1; } + // Silently fail as YouTube is "gradually rolling out" removing dislike count + // https://blog.youtube/news-and-events/update-to-youtube/ + return -1; } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java index 65f06dba33..dcdea8736a 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/linkHandler/YoutubeStreamLinkHandlerFactory.java @@ -110,7 +110,7 @@ public String getId(String urlString) throws ParsingException, IllegalArgumentEx if (!Utils.isHTTP(url) || !(YoutubeParsingHelper.isYoutubeURL(url) || YoutubeParsingHelper.isYoutubeServiceURL(url) || YoutubeParsingHelper.isHooktubeURL(url) || - YoutubeParsingHelper.isInvidioURL(url))) { + YoutubeParsingHelper.isInvidioURL(url) || YoutubeParsingHelper.isY2ubeURL(url))) { if (host.equalsIgnoreCase("googleads.g.doubleclick.net")) { throw new FoundAdException("Error found ad: " + urlString); } @@ -160,6 +160,7 @@ public String getId(String urlString) throws ParsingException, IllegalArgumentEx return assertIsId(viewQueryValue); } + case "Y2U.BE": case "YOUTU.BE": { String viewQueryValue = Utils.getQueryValue(url, "v"); if (viewQueryValue != null) { diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java index 4668dfdb9f..8d72429af3 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeChannelLinkHandlerFactoryTest.java @@ -20,44 +20,55 @@ public class PeertubeChannelLinkHandlerFactoryTest { @BeforeClass public static void setUp() { - PeerTube.setInstance(new PeertubeInstance("https://peertube.mastodon.host", "PeerTube on Mastodon.host")); + PeerTube.setInstance(new PeertubeInstance("https://peertube.stream", "PeerTube on peertube.stream")); linkHandler = PeertubeChannelLinkHandlerFactory.getInstance(); NewPipe.init(DownloaderTestImpl.getInstance()); } @Test public void acceptUrlTest() throws ParsingException { - assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/accounts/kranti@videos.squat.net")); - assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa/videos")); - assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/api/v1/accounts/kranti@videos.squat.net/videos")); - assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa")); + assertTrue(linkHandler.acceptUrl("https://peertube.stream/accounts/kranti@videos.squat.net")); + assertTrue(linkHandler.acceptUrl("https://peertube.stream/a/kranti@videos.squat.net")); + assertTrue(linkHandler.acceptUrl("https://peertube.stream/api/v1/accounts/kranti@videos.squat.net/videos")); + assertTrue(linkHandler.acceptUrl("https://peertube.stream/video-channels/kranti_channel@videos.squat.net/videos")); + assertTrue(linkHandler.acceptUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/videos")); + assertTrue(linkHandler.acceptUrl("https://peertube.stream/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa")); } @Test public void getId() throws ParsingException { assertEquals("accounts/kranti@videos.squat.net", - linkHandler.fromUrl("https://peertube.mastodon.host/accounts/kranti@videos.squat.net").getId()); + linkHandler.fromUrl("https://peertube.stream/accounts/kranti@videos.squat.net").getId()); assertEquals("accounts/kranti@videos.squat.net", - linkHandler.fromUrl("https://peertube.mastodon.host/accounts/kranti@videos.squat.net/videos").getId()); - assertEquals("video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", - linkHandler.fromUrl("https://peertube.mastodon.host/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa/videos").getId()); + linkHandler.fromUrl("https://peertube.stream/a/kranti@videos.squat.net").getId()); assertEquals("accounts/kranti@videos.squat.net", - linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/accounts/kranti@videos.squat.net").getId()); + linkHandler.fromUrl("https://peertube.stream/accounts/kranti@videos.squat.net/videos").getId()); assertEquals("accounts/kranti@videos.squat.net", - linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/accounts/kranti@videos.squat.net/videos").getId()); - assertEquals("video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", - linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa").getId()); + linkHandler.fromUrl("https://peertube.stream/a/kranti@videos.squat.net/videos").getId()); + assertEquals("accounts/kranti@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/api/v1/accounts/kranti@videos.squat.net").getId()); + assertEquals("accounts/kranti@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/api/v1/accounts/kranti@videos.squat.net/videos").getId()); + + assertEquals("video-channels/kranti_channel@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/video-channels/kranti_channel@videos.squat.net/videos").getId()); + assertEquals("video-channels/kranti_channel@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/videos").getId()); + assertEquals("video-channels/kranti_channel@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/c/kranti_channel@videos.squat.net/video-playlists").getId()); + assertEquals("video-channels/kranti_channel@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/api/v1/video-channels/kranti_channel@videos.squat.net").getId()); } @Test public void getUrl() throws ParsingException { - assertEquals("https://peertube.mastodon.host/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", - linkHandler.fromId("video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa").getUrl()); - assertEquals("https://peertube.mastodon.host/accounts/kranti@videos.squat.net", + assertEquals("https://peertube.stream/video-channels/kranti_channel@videos.squat.net", + linkHandler.fromId("video-channels/kranti_channel@videos.squat.net").getUrl()); + assertEquals("https://peertube.stream/accounts/kranti@videos.squat.net", linkHandler.fromId("accounts/kranti@videos.squat.net").getUrl()); - assertEquals("https://peertube.mastodon.host/accounts/kranti@videos.squat.net", + assertEquals("https://peertube.stream/accounts/kranti@videos.squat.net", linkHandler.fromId("kranti@videos.squat.net").getUrl()); - assertEquals("https://peertube.mastodon.host/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa", - linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/video-channels/7682d9f2-07be-4622-862e-93ec812e2ffa").getUrl()); + assertEquals("https://peertube.stream/video-channels/kranti_channel@videos.squat.net", + linkHandler.fromUrl("https://peertube.stream/api/v1/video-channels/kranti_channel@videos.squat.net").getUrl()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java index 1ed551eba4..28074866bb 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeCommentsLinkHandlerFactoryTest.java @@ -25,12 +25,32 @@ public static void setUp() { @Test public void acceptUrlTest() throws ParsingException { - assertTrue(linkHandler.acceptUrl("https://peertube.mastodon.host/api/v1/videos/19319/comment-threads?start=0&count=10&sort=-createdAt")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/kkGMgK9ZtnKfYAgnEtQxbv")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/kkGMgK9ZtnKfYAgnEtQxbv/comment-threads?start=0&count=10&sort=-createdAt")); + 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")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads?start=0&count=10&sort=-createdAt")); } @Test public void getIdFromUrl() throws ParsingException { - assertEquals("19319", linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/19319/comment-threads").getId()); - assertEquals("19319", linkHandler.fromUrl("https://peertube.mastodon.host/api/v1/videos/19319/comment-threads?start=0&count=10&sort=-createdAt").getId()); + assertEquals("kkGMgK9ZtnKfYAgnEtQxbv", + linkHandler.fromUrl("https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv").getId()); + assertEquals("kkGMgK9ZtnKfYAgnEtQxbv", + linkHandler.fromUrl("https://framatube.org/videos/watch/kkGMgK9ZtnKfYAgnEtQxbv").getId()); + assertEquals("kkGMgK9ZtnKfYAgnEtQxbv", + linkHandler.fromUrl("https://framatube.org/api/v1/videos/kkGMgK9ZtnKfYAgnEtQxbv/comment-threads").getId()); + assertEquals("kkGMgK9ZtnKfYAgnEtQxbv", + linkHandler.fromUrl("https://framatube.org/api/v1/videos/kkGMgK9ZtnKfYAgnEtQxbv/comment-threads?start=0&count=10&sort=-createdAt").getId()); + + assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d", + linkHandler.fromUrl("https://framatube.org/w/9c9de5e8-0a1e-484a-b099-e80766180a6d").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/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads").getId()); + assertEquals("9c9de5e8-0a1e-484a-b099-e80766180a6d", + linkHandler.fromUrl("https://framatube.org/api/v1/videos/9c9de5e8-0a1e-484a-b099-e80766180a6d/comment-threads?start=0&count=10&sort=-createdAt").getId()); } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java index 4297256fef..f2d761e93a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistLinkHandlerFactoryTest.java @@ -26,16 +26,30 @@ public static void setUp() { @Test public void acceptUrlTest() throws ParsingException { assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/d8ca79f9-e4c7-4269-8183-d78ed269c909")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/d8ca79f9-e4c7-4269-8183-d78ed269c909")); assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/d8ca79f9-e4c7-4269-8183-d78ed269c909/videos")); assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/dacdc4ef-5160-4846-9b70-a655880da667")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667")); assertTrue(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7")); + assertTrue(linkHandler.acceptUrl("https://framatube.org/w/p/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7")); } @Test public void getIdFromUrl() throws ParsingException { assertEquals("d8ca79f9-e4c7-4269-8183-d78ed269c909", linkHandler.getId("https://framatube.org/videos/watch/playlist/d8ca79f9-e4c7-4269-8183-d78ed269c909")); + assertEquals("d8ca79f9-e4c7-4269-8183-d78ed269c909", linkHandler.getId("https://framatube.org/w/p/d8ca79f9-e4c7-4269-8183-d78ed269c909")); assertEquals("dacdc4ef-5160-4846-9b70-a655880da667", linkHandler.getId("https://framatube.org/videos/watch/playlist/dacdc4ef-5160-4846-9b70-a655880da667")); + assertEquals("dacdc4ef-5160-4846-9b70-a655880da667", linkHandler.getId("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667")); assertEquals("bfc145f5-1be7-48a6-9b9e-4f1967199dad", linkHandler.getId("https://framatube.org/videos/watch/playlist/bfc145f5-1be7-48a6-9b9e-4f1967199dad")); + assertEquals("bfc145f5-1be7-48a6-9b9e-4f1967199dad", linkHandler.getId("https://framatube.org/w/p/bfc145f5-1be7-48a6-9b9e-4f1967199dad")); assertEquals("96b0ee2b-a5a7-4794-8769-58d8ccb79ab7", linkHandler.getId("https://framatube.org/videos/watch/playlist/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7")); + assertEquals("96b0ee2b-a5a7-4794-8769-58d8ccb79ab7", linkHandler.getId("https://framatube.org/w/p/96b0ee2b-a5a7-4794-8769-58d8ccb79ab7")); + } + + @Test + public void getUrl() throws ParsingException { + System.out.println(linkHandler.fromUrl("https://framatube.org/videos/watch/playlist/d8ca79f9-e4c7-4269-8183-d78ed269c909").getUrl());; + System.out.println(linkHandler.fromUrl("https://framatube.org/w/p/d8ca79f9-e4c7-4269-8183-d78ed269c909").getUrl());; + System.out.println(linkHandler.fromUrl("https://framatube.org/w/p/sLFbqXsw7sPR3AfvqQSBZB").getUrl());; } } diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java index 853893cec2..71304a2330 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeStreamLinkHandlerFactoryTest.java @@ -7,19 +7,19 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.schabi.newpipe.extractor.ServiceList.PeerTube; /** * Test for {@link PeertubeStreamLinkHandlerFactory} */ public class PeertubeStreamLinkHandlerFactoryTest { + private static PeertubeStreamLinkHandlerFactory linkHandler; @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 void getId() throws Exception { 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,14 @@ public void getUrl() throws Exception { 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")); + + // make sure playlists aren't accepted + assertFalse(linkHandler.acceptUrl("https://framatube.org/w/p/dacdc4ef-5160-4846-9b70-a655880da667")); + assertFalse(linkHandler.acceptUrl("https://framatube.org/videos/watch/playlist/dacdc4ef-5160-4846-9b70-a655880da667")); } -} \ No newline at end of file +} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java index 7aba0baa5d..0fcaa1c7cd 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeCommentsLinkHandlerFactoryTest.java @@ -61,4 +61,10 @@ public void getIdFromInvidious() throws ParsingException { assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://invidio.us/VM_6n762j6M&t=20").getId()); } + @Test + public void getIdFromY2ube() throws ParsingException { + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://y2u.be/VM_6n762j6M").getId()); + assertEquals("VM_6n762j6M", linkHandler.fromUrl("https://Y2U.Be/VM_6n762j6M").getId()); + } + }