From f4601564c4efdaffc319f726cc3145329a8e0c1b Mon Sep 17 00:00:00 2001 From: bopol Date: Sun, 21 Feb 2021 10:11:10 +0100 Subject: [PATCH] fix thumbnails --- .../invidious/InvidiousParsingHelper.java | 20 ++++++++++++++++--- .../youtube/invidious/InvidiousService.java | 6 ++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java index 41e22359da..63a71976fa 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousParsingHelper.java @@ -9,12 +9,14 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.localization.DateWrapper; -import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import javax.annotation.Nonnull; import java.util.Calendar; import java.util.Date; +import static org.schabi.newpipe.extractor.utils.Utils.HTTP; +import static org.schabi.newpipe.extractor.utils.Utils.HTTPS; + public class InvidiousParsingHelper { @@ -106,7 +108,7 @@ public static String getThumbnailUrl(final JsonArray thumbnails) { } else if (thumbnails.size() == 1) { url = thumbnails.getObject(0).getString("url"); } else { - url = thumbnails.getObject(1).getString("url"); + url = thumbnails.getObject(thumbnails.size() - 1).getString("url"); for (int i = 1; i < thumbnails.size(); i++) { JsonObject thumbnail = thumbnails.getObject(i); String quality = thumbnail.getString("quality"); @@ -116,6 +118,18 @@ public static String getThumbnailUrl(final JsonArray thumbnails) { } } } - return YoutubeParsingHelper.fixThumbnailUrl(url); + return fixThumbnailUrl(url); + } + + public static String fixThumbnailUrl(String thumbnailUrl) { + if (thumbnailUrl.startsWith(HTTP) || thumbnailUrl.startsWith(HTTPS)) { + return thumbnailUrl; + } + + if (thumbnailUrl.startsWith("//")) { + thumbnailUrl = thumbnailUrl.substring(2); + } + + return HTTPS + thumbnailUrl; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousService.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousService.java index 8725113de3..af095d6730 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousService.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/invidious/InvidiousService.java @@ -12,6 +12,8 @@ import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.playlist.PlaylistExtractor; import org.schabi.newpipe.extractor.search.SearchExtractor; +import org.schabi.newpipe.extractor.services.youtube.YoutubeService; +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSubscriptionExtractor; import org.schabi.newpipe.extractor.services.youtube.invidious.extractors.*; import org.schabi.newpipe.extractor.services.youtube.invidious.linkhandler.InvidiousSearchQueryHandlerFactory; import org.schabi.newpipe.extractor.services.youtube.linkHandler.*; @@ -23,6 +25,7 @@ import java.util.List; import static java.util.Arrays.asList; +import static org.schabi.newpipe.extractor.ServiceList.YouTube; import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.*; /** @@ -112,8 +115,7 @@ public KioskList getKioskList() throws ExtractionException { @Override public SubscriptionExtractor getSubscriptionExtractor() { - // see https://github.com/omarroth/invidious/issues/473 - return null; + return new YoutubeSubscriptionExtractor(YouTube); } @Nonnull