Skip to content

Commit

Permalink
Add uploadDate to the playlist info
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor committed Jul 3, 2023
1 parent 2652861 commit 2168f48
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

}

0 comments on commit 2168f48

Please sign in to comment.