2022-02-02 20:23:11 +01:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
|
|
|
|
2022-02-17 17:39:49 +01:00
|
|
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.extractPlaylistTypeFromPlaylistUrl;
|
2022-02-02 20:23:11 +01:00
|
|
|
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 {
|
2022-02-17 17:39:49 +01:00
|
|
|
return extractPlaylistTypeFromPlaylistUrl(getUrl());
|
2022-02-02 20:23:11 +01:00
|
|
|
}
|
|
|
|
}
|