From ca0ce00753581360867590a298d2a6d6b0283afc Mon Sep 17 00:00:00 2001 From: TobiGr Date: Fri, 12 May 2023 01:43:48 +0200 Subject: [PATCH] Add PlaylistInfoItem.getDescription() and PlaylistInfoItemExtractor.getDescription() [PeerTube] Implement the corresponding extractor method. TODO: add tests --- .../extractor/playlist/PlaylistInfoItem.java | 10 ++++++++++ .../playlist/PlaylistInfoItemExtractor.java | 11 +++++++++++ .../playlist/PlaylistInfoItemsCollector.java | 5 +++++ .../PeertubePlaylistInfoItemExtractor.java | 13 +++++++++++++ 4 files changed, 39 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 852a1819b..10ff12683 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 @@ -1,6 +1,7 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.InfoItem; +import org.schabi.newpipe.extractor.stream.Description; import javax.annotation.Nullable; @@ -13,6 +14,7 @@ public class PlaylistInfoItem extends InfoItem { * How many streams this playlist have */ private long streamCount = 0; + private Description description; private PlaylistInfo.PlaylistType playlistType; public PlaylistInfoItem(final int serviceId, final String url, final String name) { @@ -52,6 +54,14 @@ public class PlaylistInfoItem extends InfoItem { this.streamCount = streamCount; } + public Description getDescription() { + return description; + } + + public void setDescription(final Description description) { + this.description = description; + } + public PlaylistInfo.PlaylistType getPlaylistType() { return playlistType; } 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 ccb3c2c7d..e9c823106 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 @@ package org.schabi.newpipe.extractor.playlist; import org.schabi.newpipe.extractor.InfoItemExtractor; import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.stream.Description; import javax.annotation.Nonnull; @@ -31,6 +32,16 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor { */ long getStreamCount() throws ParsingException; + /** + * Get the description of the playlist if there is any. + * Otherwise, an {@link Description#EMPTY_DESCRIPTION EMPTY_DESCRIPTION} is returned. + * @return the playlist's description + */ + @Nonnull + default Description getDescription() throws ParsingException { + return Description.EMPTY_DESCRIPTION; + } + /** * @return the type of this playlist, see {@link PlaylistInfo.PlaylistType} for a description * of types. If not overridden always returns {@link PlaylistInfo.PlaylistType#NORMAL}. 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 3184c67dc..4fe35e40e 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 @@ -41,6 +41,11 @@ public class PlaylistInfoItemsCollector } catch (final Exception e) { addError(e); } + try { + resultItem.setDescription(extractor.getDescription()); + } catch (final Exception e) { + addError(e); + } try { resultItem.setPlaylistType(extractor.getPlaylistType()); } catch (final Exception e) { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistInfoItemExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistInfoItemExtractor.java index 219113da7..168872e15 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistInfoItemExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistInfoItemExtractor.java @@ -4,9 +4,12 @@ import com.grack.nanojson.JsonObject; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor; +import org.schabi.newpipe.extractor.stream.Description; import javax.annotation.Nonnull; +import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty; + public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor { final JsonObject item; @@ -54,4 +57,14 @@ public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtrac public long getStreamCount() throws ParsingException { return item.getInt("videosLength"); } + + @Nonnull + @Override + public Description getDescription() throws ParsingException { + final String description = item.getString("description"); + if (isNullOrEmpty(description)) { + return Description.EMPTY_DESCRIPTION; + } + return new Description(description, Description.PLAIN_TEXT); + } }