From 5a35300a5e3fc0221a6349351306a964e74adfb7 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Tue, 25 Feb 2020 21:19:53 +0100 Subject: [PATCH] Fix parsing upload date for premiered streams --- .../youtube/extractors/YoutubeStreamExtractor.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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 b95ab08c1..91c088fad 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 @@ -20,7 +20,9 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.exceptions.ReCaptchaException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.localization.DateWrapper; +import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.TimeAgoParser; +import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager; import org.schabi.newpipe.extractor.services.youtube.ItagItem; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper; import org.schabi.newpipe.extractor.stream.AudioStream; @@ -42,6 +44,7 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -134,6 +137,15 @@ public class YoutubeStreamExtractor extends StreamExtractor { //return playerResponse.getObject("microformat").getObject("playerMicroformatRenderer").getString("publishDate"); } catch (Exception ignored) {} + try { + if (getVideoPrimaryInfoRenderer().getObject("dateText").getString("simpleText").startsWith("Premiered")) { + String timeAgo = getVideoPrimaryInfoRenderer().getObject("dateText").getString("simpleText").substring(10); + TimeAgoParser timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor(Localization.fromLocalizationCode("en")); + Calendar parsedTimeAgo = timeAgoParser.parse(timeAgo).date(); + return new SimpleDateFormat("yyyy-MM-dd").format(parsedTimeAgo.getTime()); + } + } catch (Exception ignored) {} + try { // TODO this parses English formatted dates only, we need a better approach to parse the textual date Date d = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH).parse(