Use new way of specifying stream count
This commit is contained in:
parent
d58c0f230d
commit
5a775a4bbe
|
@ -3,16 +3,33 @@ package org.schabi.newpipe.extractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class to extractors that have a list (e.g. playlists, users).
|
* Base class to extractors that have a list (e.g. playlists, users).
|
||||||
*/
|
*/
|
||||||
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
public abstract class ListExtractor<R extends InfoItem> extends Extractor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constant that should be returned whenever
|
||||||
|
* a list has an unknown number of items.
|
||||||
|
*/
|
||||||
|
public static final long ITEM_COUNT_UNKNOWN = -1;
|
||||||
|
/**
|
||||||
|
* Constant that should be returned whenever a list has an
|
||||||
|
* infinite number of items. For example a YouTube mix.
|
||||||
|
*/
|
||||||
|
public static final long ITEM_COUNT_INFINITE = -2;
|
||||||
|
/**
|
||||||
|
* Constant that should be returned whenever a list
|
||||||
|
* has an unknown number of items bigger than 100.
|
||||||
|
*/
|
||||||
|
public static final long ITEM_COUNT_MORE_THAN_100 = -3;
|
||||||
|
|
||||||
public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
public ListExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,6 @@ import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
|
|
||||||
public abstract class PlaylistExtractor extends ListExtractor<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) {
|
public PlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
|
|
|
@ -30,8 +30,6 @@ import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
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.fixThumbnailUrl;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getJsonResponse;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper.getTextFromObject;
|
||||||
|
@ -531,12 +529,12 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getStreamCount() throws ParsingException {
|
public long getStreamCount() throws ParsingException {
|
||||||
if (searchType.equals(MUSIC_ALBUMS)) return UNKNOWN_ITEMS;
|
if (searchType.equals(MUSIC_ALBUMS)) return ITEM_COUNT_UNKNOWN;
|
||||||
String count = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
String count = getTextFromObject(info.getArray("flexColumns").getObject(2)
|
||||||
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
.getObject("musicResponsiveListItemFlexColumnRenderer").getObject("text"));
|
||||||
if (count != null && !count.isEmpty()) {
|
if (count != null && !count.isEmpty()) {
|
||||||
if (count.contains("100+")) {
|
if (count.contains("100+")) {
|
||||||
return MORE_THAN_100_ITEMS;
|
return ITEM_COUNT_MORE_THAN_100;
|
||||||
} else {
|
} else {
|
||||||
return Long.parseLong(Utils.removeNonDigitCharacters(count));
|
return Long.parseLong(Utils.removeNonDigitCharacters(count));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue