Skip to content

Commit ca0ce00

Browse files
committed
Add PlaylistInfoItem.getDescription() and PlaylistInfoItemExtractor.getDescription()
[PeerTube] Implement the corresponding extractor method. TODO: add tests
1 parent b218bf6 commit ca0ce00

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItem.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.schabi.newpipe.extractor.playlist;
22

33
import org.schabi.newpipe.extractor.InfoItem;
4+
import org.schabi.newpipe.extractor.stream.Description;
45

56
import javax.annotation.Nullable;
67

@@ -13,6 +14,7 @@ public class PlaylistInfoItem extends InfoItem {
1314
* How many streams this playlist have
1415
*/
1516
private long streamCount = 0;
17+
private Description description;
1618
private PlaylistInfo.PlaylistType playlistType;
1719

1820
public PlaylistInfoItem(final int serviceId, final String url, final String name) {
@@ -52,6 +54,14 @@ public void setStreamCount(final long streamCount) {
5254
this.streamCount = streamCount;
5355
}
5456

57+
public Description getDescription() {
58+
return description;
59+
}
60+
61+
public void setDescription(final Description description) {
62+
this.description = description;
63+
}
64+
5565
public PlaylistInfo.PlaylistType getPlaylistType() {
5666
return playlistType;
5767
}

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemExtractor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.schabi.newpipe.extractor.InfoItemExtractor;
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
5+
import org.schabi.newpipe.extractor.stream.Description;
56

67
import javax.annotation.Nonnull;
78

@@ -31,6 +32,16 @@ public interface PlaylistInfoItemExtractor extends InfoItemExtractor {
3132
*/
3233
long getStreamCount() throws ParsingException;
3334

35+
/**
36+
* Get the description of the playlist if there is any.
37+
* Otherwise, an {@link Description#EMPTY_DESCRIPTION EMPTY_DESCRIPTION} is returned.
38+
* @return the playlist's description
39+
*/
40+
@Nonnull
41+
default Description getDescription() throws ParsingException {
42+
return Description.EMPTY_DESCRIPTION;
43+
}
44+
3445
/**
3546
* @return the type of this playlist, see {@link PlaylistInfo.PlaylistType} for a description
3647
* of types. If not overridden always returns {@link PlaylistInfo.PlaylistType#NORMAL}.

extractor/src/main/java/org/schabi/newpipe/extractor/playlist/PlaylistInfoItemsCollector.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ public PlaylistInfoItem extract(final PlaylistInfoItemExtractor extractor)
4141
} catch (final Exception e) {
4242
addError(e);
4343
}
44+
try {
45+
resultItem.setDescription(extractor.getDescription());
46+
} catch (final Exception e) {
47+
addError(e);
48+
}
4449
try {
4550
resultItem.setPlaylistType(extractor.getPlaylistType());
4651
} catch (final Exception e) {

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubePlaylistInfoItemExtractor.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
import org.schabi.newpipe.extractor.exceptions.ParsingException;
66
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
7+
import org.schabi.newpipe.extractor.stream.Description;
78

89
import javax.annotation.Nonnull;
910

11+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
12+
1013
public class PeertubePlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
1114

1215
final JsonObject item;
@@ -54,4 +57,14 @@ public boolean isUploaderVerified() throws ParsingException {
5457
public long getStreamCount() throws ParsingException {
5558
return item.getInt("videosLength");
5659
}
60+
61+
@Nonnull
62+
@Override
63+
public Description getDescription() throws ParsingException {
64+
final String description = item.getString("description");
65+
if (isNullOrEmpty(description)) {
66+
return Description.EMPTY_DESCRIPTION;
67+
}
68+
return new Description(description, Description.PLAIN_TEXT);
69+
}
5770
}

0 commit comments

Comments
 (0)