Skip to content

Commit

Permalink
fix thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
B0pol committed Feb 21, 2021
1 parent 1bc8703 commit f460156
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {


Expand Down Expand Up @@ -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");
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand All @@ -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.*;

/**
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f460156

Please sign in to comment.