Reimplement more methods in YoutubeStreamExtractor
This commit is contained in:
parent
f13c0288cc
commit
76d54abdbf
|
@ -296,41 +296,37 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderUrl() throws ParsingException {
|
public String getUploaderUrl() throws ParsingException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
|
String uploaderId = null;
|
||||||
try {
|
try {
|
||||||
return "https://www.youtube.com/channel/" +
|
uploaderId = getVideoSecondaryInfoRenderer().getObject("owner").getObject("videoOwnerRenderer")
|
||||||
playerResponse.getObject("videoDetails").getString("channelId");
|
.getObject("navigationEndpoint").getObject("browseEndpoint").getString("browseId");
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {}
|
||||||
String uploaderUrl = null;
|
if (uploaderId == null) {
|
||||||
try {
|
try {
|
||||||
uploaderUrl = doc.select("div[class=\"yt-user-info\"]").first().children()
|
uploaderId = playerResponse.getObject("videoDetails").getString("channelId");
|
||||||
.select("a").first().attr("abs:href");
|
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
|
|
||||||
if (uploaderUrl == null) {
|
|
||||||
throw new ParsingException("Could not get channel link", e);
|
|
||||||
}
|
|
||||||
return uploaderUrl;
|
|
||||||
}
|
}
|
||||||
|
if (uploaderId != null) return "https://www.youtube.com/channel/" + uploaderId;
|
||||||
|
throw new ParsingException("Could not get uploader url");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getUploaderName() throws ParsingException {
|
public String getUploaderName() throws ParsingException {
|
||||||
assertPageFetched();
|
assertPageFetched();
|
||||||
|
String uploaderName = null;
|
||||||
try {
|
try {
|
||||||
return playerResponse.getObject("videoDetails").getString("author");
|
uploaderName = getVideoSecondaryInfoRenderer().getObject("owner").getObject("videoOwnerRenderer")
|
||||||
} catch (Exception e) {
|
.getObject("title").getArray("runs").getObject(0).getString("text");
|
||||||
String name = null;
|
|
||||||
try {
|
|
||||||
name = doc.select("div.yt-user-info").first().text();
|
|
||||||
} catch (Exception ignored) {}
|
} catch (Exception ignored) {}
|
||||||
|
if (uploaderName == null) {
|
||||||
if (name == null) {
|
try {
|
||||||
|
uploaderName = playerResponse.getObject("videoDetails").getString("author");
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
if (uploaderName != null) return uploaderName;
|
||||||
throw new ParsingException("Could not get uploader name");
|
throw new ParsingException("Could not get uploader name");
|
||||||
}
|
}
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
|
@ -876,6 +872,25 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
return videoPrimaryInfoRenderer;
|
return videoPrimaryInfoRenderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JsonObject getVideoSecondaryInfoRenderer() throws ParsingException {
|
||||||
|
JsonArray contents = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
|
||||||
|
.getObject("results").getObject("results").getArray("contents");
|
||||||
|
JsonObject videoSecondaryInfoRenderer = null;
|
||||||
|
|
||||||
|
for (Object content : contents) {
|
||||||
|
if (((JsonObject) content).getObject("videoSecondaryInfoRenderer") != null) {
|
||||||
|
videoSecondaryInfoRenderer = ((JsonObject) content).getObject("videoSecondaryInfoRenderer");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (videoSecondaryInfoRenderer == null) {
|
||||||
|
throw new ParsingException("Could not find videoSecondaryInfoRenderer");
|
||||||
|
}
|
||||||
|
|
||||||
|
return videoSecondaryInfoRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private static String getVideoInfoUrl(final String id, final String sts) {
|
private static String getVideoInfoUrl(final String id, final String sts) {
|
||||||
return "https://www.youtube.com/get_video_info?" + "video_id=" + id +
|
return "https://www.youtube.com/get_video_info?" + "video_id=" + id +
|
||||||
|
|
Loading…
Reference in New Issue