Implement PlaylistInfo.getDescription()

Implement PlaylistExtractor.getDescription() for PeerTube and SoundCloud.
Anotate   PlaylistExtractor.getDescription() as Nonnull
This commit is contained in:
TobiGr 2023-05-12 00:44:10 +02:00
parent 81f29116ba
commit b218bf69bd
8 changed files with 36 additions and 2 deletions

View File

@ -22,6 +22,7 @@ public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {
public abstract long getStreamCount() throws ParsingException;
@Nonnull
public abstract Description getDescription() throws ParsingException;
@Nonnull

View File

@ -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<StreamInfoItem> {
} 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<StreamInfoItem> {
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<StreamInfoItem> {
this.streamCount = streamCount;
}
public Description getDescription() {
return description;
}
public void setDescription(final Description description) {
this.description = description;
}
public PlaylistType getPlaylistType() {
return playlistType;
}

View File

@ -109,6 +109,7 @@ public class BandcampPlaylistExtractor extends PlaylistExtractor {
return trackInfo.size();
}
@Nonnull
@Override
public Description getDescription() throws ParsingException {
return Description.EMPTY_DESCRIPTION;

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -295,6 +295,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
return ITEM_COUNT_UNKNOWN;
}
@Nonnull
@Override
public Description getDescription() throws ParsingException {
final String description = getTextFromObject(

View File

@ -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());