Add PlaylistInfoItem.getDescription() and PlaylistInfoItemExtractor.getDescription()
[PeerTube] Implement the corresponding extractor method. TODO: add tests
This commit is contained in:
parent
b218bf69bd
commit
ca0ce00753
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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}.
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue