Skip to content

Commit 76d54ab

Browse files
wb9688TobiGr
authored andcommitted
Reimplement more methods in YoutubeStreamExtractor
1 parent f13c028 commit 76d54ab

1 file changed

Lines changed: 36 additions & 21 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public String getName() throws ParsingException {
113113
} catch (Exception ignored) {}
114114
if (title == null) {
115115
try {
116-
title = playerResponse.getObject("videoDetails").getString("title");
116+
title = playerResponse.getObject("videoDetails").getString("title");
117117
} catch (Exception ignored) {}
118118
}
119119
if (title != null) return title;
@@ -296,40 +296,36 @@ public long getDislikeCount() throws ParsingException {
296296
@Override
297297
public String getUploaderUrl() throws ParsingException {
298298
assertPageFetched();
299+
String uploaderId = null;
299300
try {
300-
return "https://www.youtube.com/channel/" +
301-
playerResponse.getObject("videoDetails").getString("channelId");
302-
} catch (Exception e) {
303-
String uploaderUrl = null;
301+
uploaderId = getVideoSecondaryInfoRenderer().getObject("owner").getObject("videoOwnerRenderer")
302+
.getObject("navigationEndpoint").getObject("browseEndpoint").getString("browseId");
303+
} catch (Exception ignored) {}
304+
if (uploaderId == null) {
304305
try {
305-
uploaderUrl = doc.select("div[class=\"yt-user-info\"]").first().children()
306-
.select("a").first().attr("abs:href");
306+
uploaderId = playerResponse.getObject("videoDetails").getString("channelId");
307307
} catch (Exception ignored) {}
308-
309-
if (uploaderUrl == null) {
310-
throw new ParsingException("Could not get channel link", e);
311-
}
312-
return uploaderUrl;
313308
}
309+
if (uploaderId != null) return "https://www.youtube.com/channel/" + uploaderId;
310+
throw new ParsingException("Could not get uploader url");
314311
}
315312

316313
@Nonnull
317314
@Override
318315
public String getUploaderName() throws ParsingException {
319316
assertPageFetched();
317+
String uploaderName = null;
320318
try {
321-
return playerResponse.getObject("videoDetails").getString("author");
322-
} catch (Exception e) {
323-
String name = null;
319+
uploaderName = getVideoSecondaryInfoRenderer().getObject("owner").getObject("videoOwnerRenderer")
320+
.getObject("title").getArray("runs").getObject(0).getString("text");
321+
} catch (Exception ignored) {}
322+
if (uploaderName == null) {
324323
try {
325-
name = doc.select("div.yt-user-info").first().text();
324+
uploaderName = playerResponse.getObject("videoDetails").getString("author");
326325
} catch (Exception ignored) {}
327-
328-
if (name == null) {
329-
throw new ParsingException("Could not get uploader name");
330-
}
331-
return name;
332326
}
327+
if (uploaderName != null) return uploaderName;
328+
throw new ParsingException("Could not get uploader name");
333329
}
334330

335331
@Nonnull
@@ -876,6 +872,25 @@ private JsonObject getVideoPrimaryInfoRenderer() throws ParsingException {
876872
return videoPrimaryInfoRenderer;
877873
}
878874

875+
private JsonObject getVideoSecondaryInfoRenderer() throws ParsingException {
876+
JsonArray contents = initialData.getObject("contents").getObject("twoColumnWatchNextResults")
877+
.getObject("results").getObject("results").getArray("contents");
878+
JsonObject videoSecondaryInfoRenderer = null;
879+
880+
for (Object content : contents) {
881+
if (((JsonObject) content).getObject("videoSecondaryInfoRenderer") != null) {
882+
videoSecondaryInfoRenderer = ((JsonObject) content).getObject("videoSecondaryInfoRenderer");
883+
break;
884+
}
885+
}
886+
887+
if (videoSecondaryInfoRenderer == null) {
888+
throw new ParsingException("Could not find videoSecondaryInfoRenderer");
889+
}
890+
891+
return videoSecondaryInfoRenderer;
892+
}
893+
879894
@Nonnull
880895
private static String getVideoInfoUrl(final String id, final String sts) {
881896
return "https://www.youtube.com/get_video_info?" + "video_id=" + id +

0 commit comments

Comments
 (0)