NewPipeExtractor/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeMixPlaylistInfoItemE...

65 lines
2.2 KiB
Java
Raw Normal View History

package org.schabi.newpipe.extractor.services.youtube.extractors;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.extractPlaylistTypeFromPlaylistUrl;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getThumbnailUrlFromInfoItem;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
import com.grack.nanojson.JsonObject;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfo;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
import javax.annotation.Nonnull;
public class YoutubeMixPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
private final JsonObject mixInfoItem;
public YoutubeMixPlaylistInfoItemExtractor(final JsonObject mixInfoItem) {
this.mixInfoItem = mixInfoItem;
}
@Override
public String getName() throws ParsingException {
final String name = getTextFromObject(mixInfoItem.getObject("title"));
if (isNullOrEmpty(name)) {
throw new ParsingException("Could not get name");
}
return name;
}
@Override
public String getUrl() throws ParsingException {
final String url = mixInfoItem.getString("shareUrl");
if (isNullOrEmpty(url)) {
throw new ParsingException("Could not get url");
}
return url;
}
@Override
public String getThumbnailUrl() throws ParsingException {
return getThumbnailUrlFromInfoItem(mixInfoItem);
}
@Override
public String getUploaderName() throws ParsingException {
// YouTube mixes are auto-generated by YouTube
return "YouTube";
}
@Override
public long getStreamCount() throws ParsingException {
// Auto-generated playlists always start with 25 videos and are endless
return ListExtractor.ITEM_COUNT_INFINITE;
}
@Nonnull
@Override
public PlaylistInfo.PlaylistType getPlaylistType() throws ParsingException {
return extractPlaylistTypeFromPlaylistUrl(getUrl());
}
}