mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2024-12-15 06:40:33 +05:30
Adapt most channel changes
This commit is contained in:
parent
39bf1ff1eb
commit
be3e20e263
@ -23,6 +23,9 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.HTTP;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 25.07.16.
|
* Created by Christian Schabesberger on 25.07.16.
|
||||||
*
|
*
|
||||||
@ -91,7 +94,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public String getId() throws ParsingException {
|
public String getId() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return doc.select("meta[itemprop=\"channelId\"]").first().attr("content");
|
return doc.select("meta[property=\"og:url\"]").first().attr("content").replace(CHANNEL_URL_BASE, "");
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
try {
|
||||||
|
return ytInitialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("navigationEndpoint").getObject("browseEndpoint").getString("browseId");
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
// fallback method; does not work with channels that have no "Subscribe" button (e.g. EminemVEVO)
|
// fallback method; does not work with channels that have no "Subscribe" button (e.g. EminemVEVO)
|
||||||
@ -118,7 +124,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public String getAvatarUrl() throws ParsingException {
|
public String getAvatarUrl() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return doc.select("img[class=\"channel-header-profile-image\"]").first().attr("abs:src");
|
return ytInitialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("avatar").getArray("thumbnails").getObject(0).getString("url");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException("Could not get avatar", e);
|
throw new ParsingException("Could not get avatar", e);
|
||||||
}
|
}
|
||||||
@ -127,11 +133,21 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public String getBannerUrl() throws ParsingException {
|
public String getBannerUrl() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
Element el = doc.select("div[id=\"gh-banner\"]").first().select("style").first();
|
String url = ytInitialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("banner").getArray("thumbnails").getObject(0).getString("url");
|
||||||
String cssContent = el.html();
|
if (url.contains("s.ytimg.com") || url.contains("default_banner")) {
|
||||||
String url = "https:" + Parser.matchGroup1("url\\(([^)]+)\\)", cssContent);
|
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)) {
|
||||||
|
url = HTTPS + url;
|
||||||
|
}
|
||||||
|
|
||||||
return url.contains("s.ytimg.com") || url.contains("default_banner") ? null : url;
|
return url;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException("Could not get Banner", e);
|
throw new ParsingException("Could not get Banner", e);
|
||||||
}
|
}
|
||||||
@ -149,11 +165,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public long getSubscriberCount() throws ParsingException {
|
public long getSubscriberCount() throws ParsingException {
|
||||||
|
|
||||||
final Element el = doc.select("span[class*=\"yt-subscription-button-subscriber-count\"]").first();
|
final String simpleText = ytInitialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText").getArray("runs").getObject(0).getString("text");
|
||||||
if (el != null) {
|
if (simpleText != null) {
|
||||||
String elTitle = el.attr("title");
|
|
||||||
try {
|
try {
|
||||||
return Utils.mixedNumberWordToLong(elTitle);
|
return Utils.mixedNumberWordToLong(simpleText);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new ParsingException("Could not get subscriber count", e);
|
throw new ParsingException("Could not get subscriber count", e);
|
||||||
}
|
}
|
||||||
@ -166,7 +181,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
@Override
|
@Override
|
||||||
public String getDescription() throws ParsingException {
|
public String getDescription() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return doc.select("meta[name=\"description\"]").first().attr("content");
|
return ytInitialData.getObject("metadata").getObject("channelMetadataRenderer").getString("description");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException("Could not get channel description", e);
|
throw new ParsingException("Could not get channel description", e);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
|
|
||||||
|
public static final String HTTP = "http://";
|
||||||
|
public static final String HTTPS = "https://";
|
||||||
|
|
||||||
private Utils() {
|
private Utils() {
|
||||||
//no instance
|
//no instance
|
||||||
}
|
}
|
||||||
@ -83,9 +86,6 @@ public class Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String HTTP = "http://";
|
|
||||||
private static final String HTTPS = "https://";
|
|
||||||
|
|
||||||
public static String replaceHttpWithHttps(final String url) {
|
public static String replaceHttpWithHttps(final String url) {
|
||||||
if (url == null) return null;
|
if (url == null) return null;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user