From fc465c8bf7b70d9052fc5bf1f524f1c97b330718 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 25 Feb 2020 22:54:37 +0100 Subject: [PATCH] Fix getUploadDate() for premiered videos with a given date Detect publishDate and uploadDate --- .../youtube/extractors/YoutubeStreamExtractor.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index 2408b5c02..b5d03edcc 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -134,7 +134,13 @@ public class YoutubeStreamExtractor extends StreamExtractor { } try { - // return playerResponse.getObject("microformat").getObject("playerMicroformatRenderer").getString("publishDate"); + JsonObject micro = playerResponse.getObject("microformat").getObject("playerMicroformatRenderer"); + if (micro.getString("uploadDate") != null && !micro.getString("uploadDate").isEmpty()) { + return micro.getString("uploadDate"); + } + if (micro.getString("publishDate") != null && !micro.getString("publishDate").isEmpty()) { + return micro.getString("publishDate"); + } } catch (Exception ignored) {} try { @@ -147,7 +153,7 @@ public class YoutubeStreamExtractor extends StreamExtractor { return new SimpleDateFormat("yyyy-MM-dd").format(parsedTime.getTime()); } catch (Exception ignored) {} - try { // Premiered Premiered Feb 21, 2020 + try { // 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) {}