Use getVideo(Primary|Secondary)InfoRenderer()

This commit is contained in:
wb9688 2020-02-25 17:40:23 +01:00 committed by TobiGr
parent 8e6be880d7
commit bbe1a3cd62
1 changed files with 9 additions and 24 deletions

View File

@ -126,22 +126,11 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} catch (Exception ignored) {} } catch (Exception ignored) {}
try { try {
JsonArray contents = initialData.getObject("contents").getObject("twoColumnWatchNextResults").getObject("results") // TODO this parses English formatted dates only, we need a better approach to parse the textual date
.getObject("results").getArray("contents"); Date d = new SimpleDateFormat("dd MMM yyy").parse(getVideoPrimaryInfoRenderer()
for (Object c: contents) { .getObject("dateText").getString("simpleText"));
String unformattedDate = "";
try {
JsonObject o = (JsonObject) c;
unformattedDate = o.getObject("videoPrimaryInfoRenderer").getObject("dateText").getString("simpleText");
} catch (Exception ignored) {/* we got the wrong element form the array */}
// TODO this parses English formatted dates only, we need a better approach to parse teh textual date
Date d = new SimpleDateFormat("dd MMM yyy").parse(unformattedDate);
return new SimpleDateFormat("yyyy-MM-dd").format(d); return new SimpleDateFormat("yyyy-MM-dd").format(d);
} } catch (Exception ignored) {}
} catch (Exception e) {
throw new ParsingException("Could not get upload date", e);
}
throw new ParsingException("Could not get upload date"); throw new ParsingException("Could not get upload date");
} }
@ -351,7 +340,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
public String getUploaderAvatarUrl() throws ParsingException { public String getUploaderAvatarUrl() throws ParsingException {
assertPageFetched(); assertPageFetched();
String uploaderAvatarUrl; String uploaderAvatarUrl = null;
try { try {
uploaderAvatarUrl = initialData.getObject("contents").getObject("twoColumnWatchNextResults").getObject("secondaryResults") uploaderAvatarUrl = initialData.getObject("contents").getObject("twoColumnWatchNextResults").getObject("secondaryResults")
.getObject("secondaryResults").getArray("results").getObject(0).getObject("compactAutoplayRenderer") .getObject("secondaryResults").getArray("results").getObject(0).getObject("compactAutoplayRenderer")
@ -363,13 +352,9 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} catch (Exception ignored) {} } catch (Exception ignored) {}
try { try {
uploaderAvatarUrl = initialData.getObject("contents").getObject("twoColumnWatchNextResults").getObject("results") uploaderAvatarUrl = getVideoSecondaryInfoRenderer().getObject("owner").getObject("videoOwnerRenderer")
.getObject("results").getArray("contents").getObject(1).getObject("videoSecondaryInfoRenderer") .getObject("thumbnail").getArray("thumbnails").getObject(0).getString("url");
.getObject("owner").getObject("videoOwnerRenderer").getObject("thumbnail").getArray("thumbnails") } catch (Exception ignored) {}
.getObject(0).getString("url");
} catch (Exception e) {
throw new ParsingException("Could not get uploader avatar url", e);
}
if (uploaderAvatarUrl == null) { if (uploaderAvatarUrl == null) {
throw new ParsingException("Could not get uploader avatar url"); throw new ParsingException("Could not get uploader avatar url");