From 2168f48a29b1a78ea1cdfd6d397c5a46a4c489e1 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Mon, 1 May 2023 00:04:00 +0200 Subject: [PATCH] Add uploadDate to the playlist info --- .../extractor/playlist/PlaylistInfoItem.java | 21 +++++++++++++++++++ .../playlist/PlaylistInfoItemExtractor.java | 9 ++++++++ .../playlist/PlaylistInfoItemsCollector.java | 10 +++++++++ .../GridPlaylistRendererExtractor.java | 20 ++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java index 10ff126835..ad8b37f104 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java @@ -2,6 +2,7 @@ import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.stream.Description; +import org.schabi.newpipe.extractor.localization.DateWrapper; import javax.annotation.Nullable; @@ -16,6 +17,10 @@ public class PlaylistInfoItem extends InfoItem { private long streamCount = 0; private Description description; private PlaylistInfo.PlaylistType playlistType; + @Nullable + private String textualUploadDate; + @Nullable + private DateWrapper uploadDate; public PlaylistInfoItem(final int serviceId, final String url, final String name) { super(InfoType.PLAYLIST, serviceId, url, name); @@ -69,4 +74,20 @@ public PlaylistInfo.PlaylistType getPlaylistType() { public void setPlaylistType(final PlaylistInfo.PlaylistType playlistType) { this.playlistType = playlistType; } + + public String getTextualUploadDate() { + return textualUploadDate; + } + + public void setTextualUploadDate(final String textualUploadDate) { + this.textualUploadDate = textualUploadDate; + } + + public DateWrapper getUploadDate() { + return uploadDate; + } + + public void setUploadDate(final DateWrapper uploadDate) { + this.uploadDate = uploadDate; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java index e9c8231069..51a67343cf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java @@ -2,6 +2,7 @@ import org.schabi.newpipe.extractor.InfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.stream.Description; import javax.annotation.Nonnull; @@ -50,4 +51,12 @@ default Description getDescription() throws ParsingException { default PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException { return PlaylistInfo.PlaylistType.NORMAL; } + + default String getTextualUploadDate() throws ParsingException { + return null; + } + + default DateWrapper getUploadDate() throws ParsingException { + return null; + } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java index 4fe35e40e8..56bd849b9c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java @@ -51,6 +51,16 @@ public PlaylistInfoItem extract(final PlaylistInfoItemExtractor extractor) } catch (final Exception e) { addError(e); } + try { + resultItem.setTextualUploadDate(extractor.getTextualUploadDate()); + } catch (final Exception e) { + addError(e); + } + try { + resultItem.setUploadDate(extractor.getUploadDate()); + } catch (final Exception e) { + addError(e); + } return resultItem; } } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/GridPlaylistRendererExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/GridPlaylistRendererExtractor.java index 13006ba3be..48f11bd234 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/GridPlaylistRendererExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/GridPlaylistRendererExtractor.java @@ -1,6 +1,10 @@ package org.schabi.newpipe.extractor.services.youtube.extractors; import org.schabi.newpipe.extractor.exceptions.ParsingException; +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.playlist.PlaylistInfoItemExtractor; import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory; @@ -60,5 +64,21 @@ public long getStreamCount() throws ParsingException { return Long.parseLong( playlistInfoItem.getObject("videoCountShortText").getString("simpleText")); } + @Override + public String getTextualUploadDate() throws ParsingException { + return playlistInfoItem.getObject("publishedTimeText").getString("simpleText"); + } + @Override + public DateWrapper getUploadDate() throws ParsingException { + final String uploadDate = getTextualUploadDate(); + if (uploadDate != null) { + if (uploadDate.startsWith("Updated ")) { + final TimeAgoParser timeAgoParser = TimeAgoPatternsManager.getTimeAgoParserFor( + Localization.fromLocalizationCode("en")); + return timeAgoParser.parse(uploadDate.substring(8)); + } + } + return null; + } }