Fix getUploadDate() for premiered videos with a given date

This commit is contained in:
TobiGr 2020-02-25 21:50:11 +01:00
parent 5a35300a5e
commit 96285e0815
1 changed files with 13 additions and 5 deletions

View File

@ -134,15 +134,23 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
try { try {
//return playerResponse.getObject("microformat").getObject("playerMicroformatRenderer").getString("publishDate"); // return playerResponse.getObject("microformat").getObject("playerMicroformatRenderer").getString("publishDate");
} catch (Exception ignored) {} } catch (Exception ignored) {}
try { try {
if (getVideoPrimaryInfoRenderer().getObject("dateText").getString("simpleText").startsWith("Premiered")) { if (getVideoPrimaryInfoRenderer().getObject("dateText").getString("simpleText").startsWith("Premiered")) {
String timeAgo = getVideoPrimaryInfoRenderer().getObject("dateText").getString("simpleText").substring(10); String time = getVideoPrimaryInfoRenderer().getObject("dateText").getString("simpleText").substring(10);
try { // Premiered 20 hours ago
TimeAgoParser timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(Localization.fromLocalizationCode("en")); TimeAgoParser timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(Localization.fromLocalizationCode("en"));
Calendar parsedTimeAgo = timeAgoParser.parse(timeAgo).date(); Calendar parsedTime = timeAgoParser.parse(time).date();
return new SimpleDateFormat("yyyy-MM-dd").format(parsedTimeAgo.getTime()); return new SimpleDateFormat("yyyy-MM-dd").format(parsedTime.getTime());
} catch (Exception ignored) {}
try { // Premiered Premiered Feb 21, 2020
Date d = new SimpleDateFormat("MMM dd, YYYY", Locale.ENGLISH).parse(time);
return new SimpleDateFormat("yyyy-MM-dd").format(d.getTime());
} catch (Exception ignored) {}
} }
} catch (Exception ignored) {} } catch (Exception ignored) {}