Fix thumbnail URLs starting with //
This commit is contained in:
parent
838d834ce2
commit
94a2d5be46
|
@ -128,10 +128,6 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||
String url = initialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("avatar")
|
||||
.getArray("thumbnails").getObject(0).getString("url");
|
||||
|
||||
// the first characters of the avatar URLs are different for each channel and some are not even valid URLs
|
||||
if (url.startsWith("//")) {
|
||||
url = url.substring(2);
|
||||
}
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
|
@ -155,10 +151,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||
if (url == null || url.contains("s.ytimg.com") || url.contains("default_banner")) {
|
||||
return null;
|
||||
}
|
||||
// the first characters of the banner URLs are different for each channel and some are not even valid URLs
|
||||
if (url.startsWith("//")) {
|
||||
url = url.substring(2);
|
||||
}
|
||||
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
|
|
|
@ -42,14 +42,13 @@ public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor
|
|||
public String getThumbnailUrl() throws ParsingException {
|
||||
try {
|
||||
String url = channelInfoItem.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
||||
if (url.startsWith("//")) {
|
||||
url = url.substring(2);
|
||||
}
|
||||
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
url = HTTPS + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
throw new ParsingException("Could not get thumbnail url", e);
|
||||
|
|
|
@ -121,16 +121,30 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||
|
||||
@Override
|
||||
public String getThumbnailUrl() throws ParsingException {
|
||||
String url = null;
|
||||
|
||||
try {
|
||||
return playlistInfo.getObject("thumbnailRenderer").getObject("playlistVideoThumbnailRenderer")
|
||||
url = playlistInfo.getObject("thumbnailRenderer").getObject("playlistVideoThumbnailRenderer")
|
||||
.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
return initialData.getObject("microformat").getObject("microformatDataRenderer").getObject("thumbnail")
|
||||
.getArray("thumbnails").getObject(0).getString("url");
|
||||
} catch (Exception e) {
|
||||
throw new ParsingException("Could not get playlist thumbnail", e);
|
||||
|
||||
if (url == null) {
|
||||
try {
|
||||
return initialData.getObject("microformat").getObject("microformatDataRenderer").getObject("thumbnail")
|
||||
.getArray("thumbnails").getObject(0).getString("url");
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
if (url != null && !url.isEmpty()) {
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
url = HTTPS + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
throw new ParsingException("Could not get playlist thumbnail");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -162,10 +176,6 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||
try {
|
||||
String url = getUploaderInfo().getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
||||
|
||||
// the first characters of the avatar URLs are different for each channel and some are not even valid URLs
|
||||
if (url.startsWith("//")) {
|
||||
url = url.substring(2);
|
||||
}
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
|
|
|
@ -8,6 +8,8 @@ import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylist
|
|||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.HTTP;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
|
||||
|
||||
public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
|
||||
private JsonObject playlistInfoItem;
|
||||
|
@ -19,8 +21,16 @@ public class YoutubePlaylistInfoItemExtractor implements PlaylistInfoItemExtract
|
|||
@Override
|
||||
public String getThumbnailUrl() throws ParsingException {
|
||||
try {
|
||||
return playlistInfoItem.getArray("thumbnails").getObject(0).getArray("thumbnails")
|
||||
.getObject(0).getString("url");
|
||||
String url = playlistInfoItem.getArray("thumbnails").getObject(0)
|
||||
.getArray("thumbnails").getObject(0).getString("url");
|
||||
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
url = HTTPS + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
throw new ParsingException("Could not get thumbnail url", e);
|
||||
}
|
||||
|
|
|
@ -187,8 +187,15 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||
try {
|
||||
JsonArray thumbnails = playerResponse.getObject("videoDetails").getObject("thumbnail").getArray("thumbnails");
|
||||
// the last thumbnail is the one with the highest resolution
|
||||
return thumbnails.getObject(thumbnails.size() - 1).getString("url");
|
||||
String url = thumbnails.getObject(thumbnails.size() - 1).getString("url");
|
||||
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
url = HTTPS + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
throw new ParsingException("Could not get thumbnail url");
|
||||
}
|
||||
|
@ -362,10 +369,6 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||
String url = getVideoSecondaryInfoRenderer().getObject("owner").getObject("videoOwnerRenderer")
|
||||
.getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
|
||||
|
||||
// the first characters of the avatar URLs are different for each channel and some are not even valid URLs
|
||||
if (url.startsWith("//")) {
|
||||
url = url.substring(2);
|
||||
}
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
|
|
|
@ -16,6 +16,8 @@ import javax.annotation.Nullable;
|
|||
|
||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getUrlFromNavigationEndpoint;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.HTTP;
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
|
||||
|
||||
/*
|
||||
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
|
||||
|
@ -196,8 +198,16 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
|||
public String getThumbnailUrl() throws ParsingException {
|
||||
try {
|
||||
// TODO: Don't simply get the first item, but look at all thumbnails and their resolution
|
||||
return videoInfo.getObject("thumbnail").getArray("thumbnails")
|
||||
String url = videoInfo.getObject("thumbnail").getArray("thumbnails")
|
||||
.getObject(0).getString("url");
|
||||
|
||||
if (url.startsWith(HTTP)) {
|
||||
url = Utils.replaceHttpWithHttps(url);
|
||||
} else if (!url.startsWith(HTTPS)) {
|
||||
url = HTTPS + url;
|
||||
}
|
||||
|
||||
return url;
|
||||
} catch (Exception e) {
|
||||
throw new ParsingException("Could not get thumbnail url", e);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue