Handle premium videos
This commit is contained in:
parent
7442f91aa6
commit
3187116a63
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
||||||
|
|
||||||
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
@ -60,7 +61,7 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAd() {
|
public boolean isAd() {
|
||||||
return false;
|
return isPremium();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -169,6 +170,9 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
@Override
|
@Override
|
||||||
public long getViewCount() throws ParsingException {
|
public long getViewCount() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
|
if (videoInfo.getObject("topStandaloneBadge") != null || isPremium()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
String viewCount;
|
String viewCount;
|
||||||
if (getStreamType() == StreamType.LIVE_STREAM) {
|
if (getStreamType() == StreamType.LIVE_STREAM) {
|
||||||
viewCount = videoInfo.getObject("viewCountText")
|
viewCount = videoInfo.getObject("viewCountText")
|
||||||
|
@ -193,4 +197,16 @@ public class YoutubeStreamInfoItemExtractor implements StreamInfoItemExtractor {
|
||||||
throw new ParsingException("Could not get thumbnail url", e);
|
throw new ParsingException("Could not get thumbnail url", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPremium() {
|
||||||
|
try {
|
||||||
|
JsonArray badges = videoInfo.getArray("badges");
|
||||||
|
for (Object badge : badges) {
|
||||||
|
if (((JsonObject) badge).getObject("metadataBadgeRenderer").getString("label").equals("Premium")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue