From fe31a90cb349c98f2199b5bc5b55a9904bb56115 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 2 Nov 2020 09:14:52 +0530 Subject: [PATCH 1/3] Remove DateTimeFormatter.ISO_OFFSET_DATE_TIME usage. --- .../youtube/extractors/YoutubeFeedInfoItemExtractor.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeedInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeedInfoItemExtractor.java index cea385189..3945ff170 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeedInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeFeedInfoItemExtractor.java @@ -8,7 +8,6 @@ import org.schabi.newpipe.extractor.stream.StreamType; import javax.annotation.Nullable; import java.time.OffsetDateTime; -import java.time.format.DateTimeFormatter; import java.time.format.DateTimeParseException; public class YoutubeFeedInfoItemExtractor implements StreamInfoItemExtractor { @@ -61,7 +60,7 @@ public class YoutubeFeedInfoItemExtractor implements StreamInfoItemExtractor { @Override public DateWrapper getUploadDate() throws ParsingException { try { - return new DateWrapper(OffsetDateTime.parse(getTextualUploadDate(), DateTimeFormatter.ISO_OFFSET_DATE_TIME)); + return new DateWrapper(OffsetDateTime.parse(getTextualUploadDate())); } catch (DateTimeParseException e) { throw new ParsingException("Could not parse date (\"" + getTextualUploadDate() + "\")", e); } From 9cf9e7e98044ef85fb72737824e99b7000771423 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Mon, 2 Nov 2020 09:15:55 +0530 Subject: [PATCH 2/3] Call existing constructor in DateWrapper. --- .../org/schabi/newpipe/extractor/localization/DateWrapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java index 0390ee12e..f86efa9b9 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/localization/DateWrapper.java @@ -28,8 +28,7 @@ public class DateWrapper implements Serializable { */ @Deprecated public DateWrapper(@NonNull Calendar calendar, boolean isApproximation) { - offsetDateTime = OffsetDateTime.ofInstant(calendar.toInstant(), ZoneOffset.UTC); - this.isApproximation = isApproximation; + this(OffsetDateTime.ofInstant(calendar.toInstant(), ZoneOffset.UTC), isApproximation); } public DateWrapper(@NonNull OffsetDateTime offsetDateTime) { From 4fe28d7e3a3cf6ba18d4d74219fad22adcba4911 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 3 Nov 2020 16:24:46 +0530 Subject: [PATCH 3/3] Fix YouTube parse error when only a date is present. --- .../extractor/services/youtube/YoutubeParsingHelper.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 3fb279b8e..8b924cf93 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -21,7 +21,9 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; +import java.time.LocalDate; import java.time.OffsetDateTime; +import java.time.ZoneOffset; import java.time.format.DateTimeParseException; import java.util.Collections; import java.util.HashMap; @@ -184,7 +186,11 @@ public class YoutubeParsingHelper { try { return OffsetDateTime.parse(textualUploadDate); } catch (DateTimeParseException e) { - throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e); + try { + return LocalDate.parse(textualUploadDate).atStartOfDay().atOffset(ZoneOffset.UTC); + } catch (DateTimeParseException e1) { + throw new ParsingException("Could not parse date: \"" + textualUploadDate + "\"", e1); + } } }