Handle 100+ items in playlist

This commit is contained in:
wb9688 2020-03-20 11:17:12 +01:00
parent fb9b9691b7
commit 2b9b2a78e8
2 changed files with 13 additions and 2 deletions

View File

@ -7,6 +7,9 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {
public final static long UNKNOWN_ITEMS = -1;
public final static long INFINITE_ITEMS = -2;
public final static long MORE_THAN_100_ITEMS = -3;
public PlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, linkHandler);

View File

@ -30,6 +30,8 @@ import java.util.Map;
import javax.annotation.Nonnull;
import static org.schabi.newpipe.extractor.playlist.PlaylistExtractor.MORE_THAN_100_ITEMS;
import static org.schabi.newpipe.extractor.playlist.PlaylistExtractor.UNKNOWN_ITEMS;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.fixThumbnailUrl;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
@ -494,10 +496,16 @@ public class YoutubeSearchExtractor extends SearchExtractor {
@Override
public long getStreamCount() throws ParsingException {
if (searchType.equals(MUSIC_ALBUMS)) return -1;
if (searchType.equals(MUSIC_ALBUMS)) return UNKNOWN_ITEMS;
String count = getTextFromObject(info.getArray("flexColumns").getObject(2)
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
if (count != null && !count.isEmpty()) return Long.parseLong(Utils.removeNonDigitCharacters(count));
if (count != null && !count.isEmpty()) {
if (count.contains("100+")) {
return MORE_THAN_100_ITEMS;
} else {
return Long.parseLong(Utils.removeNonDigitCharacters(count));
}
}
throw new ParsingException("Could not get count");
}
});