From b218bf69bd9172481f2ae06ef834e5916e83780a Mon Sep 17 00:00:00 2001 From: TobiGr Date: Fri, 12 May 2023 00:44:10 +0200 Subject: [PATCH] Implement PlaylistInfo.getDescription() Implement PlaylistExtractor.getDescription() for PeerTube and SoundCloud. Anotate PlaylistExtractor.getDescription() as Nonnull --- .../extractor/playlist/PlaylistExtractor.java | 1 + .../newpipe/extractor/playlist/PlaylistInfo.java | 15 +++++++++++++++ .../extractors/BandcampPlaylistExtractor.java | 1 + .../extractors/PeertubePlaylistExtractor.java | 7 ++++++- .../extractors/SoundcloudPlaylistExtractor.java | 7 ++++++- .../extractors/YoutubeMixPlaylistExtractor.java | 1 + .../extractors/YoutubePlaylistExtractor.java | 1 + .../peertube/PeertubePlaylistExtractorTest.java | 5 +++++ 8 files changed, 36 insertions(+), 2 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java index c60738c91..bc4eee467 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistExtractor.java @@ -22,6 +22,7 @@ public abstract class PlaylistExtractor extends ListExtractor { public abstract long getStreamCount() throws ParsingException; + @Nonnull public abstract Description getDescription() throws ParsingException; @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java index aea33304c..97a0d530d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfo.java @@ -8,6 +8,7 @@ import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler; +import org.schabi.newpipe.extractor.stream.Description; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.utils.ExtractorHelper; @@ -102,6 +103,11 @@ public final class PlaylistInfo extends ListInfo { } catch (final Exception e) { info.addError(e); } + try { + info.setDescription(extractor.getDescription()); + } catch (final Exception e) { + info.addError(e); + } try { info.setThumbnailUrl(extractor.getThumbnailUrl()); } catch (final Exception e) { @@ -174,6 +180,7 @@ public final class PlaylistInfo extends ListInfo { private String subChannelName; private String subChannelAvatarUrl; private long streamCount = 0; + private Description description; private PlaylistType playlistType; public String getThumbnailUrl() { @@ -248,6 +255,14 @@ public final class PlaylistInfo extends ListInfo { this.streamCount = streamCount; } + public Description getDescription() { + return description; + } + + public void setDescription(final Description description) { + this.description = description; + } + public PlaylistType getPlaylistType() { return playlistType; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java index a99c9c48d..0a0d25507 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/bandcamp/extractors/BandcampPlaylistExtractor.java @@ -109,6 +109,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor { return trackInfo.size(); } + @Nonnull @Override public Description getDescription() throws ParsingException { return Description.EMPTY_DESCRIPTION; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java index e20b396fb..3d4ff9d19 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistExtractor.java @@ -66,9 +66,14 @@ public class PeertubePlaylistExtractor extends PlaylistExtractor { return playlistInfo.getLong("videosLength"); } + @Nonnull @Override public Description getDescription() throws ParsingException { - return Description.EMPTY_DESCRIPTION; + final String description = playlistInfo.getString("description"); + if (isNullOrEmpty(description)) { + return Description.EMPTY_DESCRIPTION; + } + return new Description(description, Description.PLAIN_TEXT); } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java index 34469a7cc..88f38b1e1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistExtractor.java @@ -119,9 +119,14 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor { return playlist.getLong("track_count"); } + @Nonnull @Override public Description getDescription() throws ParsingException { - return Description.EMPTY_DESCRIPTION; + final String description = playlist.getString("description"); + if (isNullOrEmpty(description)) { + return Description.EMPTY_DESCRIPTION; + } + return new Description(description, Description.PLAIN_TEXT); } @Nonnull diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java index 5b6b1eeca..eefc10a94 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistExtractor.java @@ -170,6 +170,7 @@ public class YoutubeMixPlaylistExtractor extends PlaylistExtractor { return ListExtractor.ITEM_COUNT_INFINITE; } + @Nonnull @Override public Description getDescription() throws ParsingException { return Description.EMPTY_DESCRIPTION; diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java index 1523fc923..06f055f14 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java @@ -295,6 +295,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor { return ITEM_COUNT_UNKNOWN; } + @Nonnull @Override public Description getDescription() throws ParsingException { final String description = getTextFromObject( diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistExtractorTest.java index 5bd47de4a..37853305a 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubePlaylistExtractorTest.java @@ -60,6 +60,11 @@ public class PeertubePlaylistExtractorTest { ExtractorAsserts.assertGreaterOrEqual(39, extractor.getStreamCount()); } + @Test + void testGetDescription() throws ParsingException { + ExtractorAsserts.assertContains("épisodes de Shocking", extractor.getDescription().getContent()); + } + @Test void testGetSubChannelUrl() { assertEquals("https://skeptikon.fr/video-channels/metadechoc_channel", extractor.getSubChannelUrl());