Detect disabled subriber count correctly
Fix parsing of kiosk name
This commit is contained in:
parent
7dcc9f159b
commit
655c999795
|
@ -165,10 +165,11 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
@Override
|
@Override
|
||||||
public long getSubscriberCount() throws ParsingException {
|
public long getSubscriberCount() throws ParsingException {
|
||||||
|
|
||||||
final String simpleText = ytInitialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText").getArray("runs").getObject(0).getString("text");
|
final JsonObject subscriberInfo = ytInitialData.getObject("header").getObject("c4TabbedHeaderRenderer").getObject("subscriberCountText");
|
||||||
if (simpleText != null) {
|
if (subscriberInfo != null) {
|
||||||
try {
|
try {
|
||||||
return Utils.mixedNumberWordToLong(simpleText);
|
|
||||||
|
return Utils.mixedNumberWordToLong(subscriberInfo.getArray("runs").getObject(0).getString("text"));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new ParsingException("Could not get subscriber count", e);
|
throw new ParsingException("Could not get subscriber count", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ package org.schabi.newpipe.extractor.services.youtube.extractors;
|
||||||
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.grack.nanojson.JsonObject;
|
||||||
|
import com.grack.nanojson.JsonParser;
|
||||||
|
import com.grack.nanojson.JsonParserException;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
@ -34,6 +37,7 @@ import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
|
import org.schabi.newpipe.extractor.utils.Parser;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -41,6 +45,7 @@ import java.io.IOException;
|
||||||
public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
|
|
||||||
private Document doc;
|
private Document doc;
|
||||||
|
private JsonObject initialData;
|
||||||
|
|
||||||
public YoutubeTrendingExtractor(StreamingService service,
|
public YoutubeTrendingExtractor(StreamingService service,
|
||||||
ListLinkHandler linkHandler,
|
ListLinkHandler linkHandler,
|
||||||
|
@ -55,6 +60,16 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
|
|
||||||
final Response response = downloader.get(url, getExtractorLocalization());
|
final Response response = downloader.get(url, getExtractorLocalization());
|
||||||
doc = YoutubeParsingHelper.parseAndCheckPage(url, response);
|
doc = YoutubeParsingHelper.parseAndCheckPage(url, response);
|
||||||
|
initialData = getInitialData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private JsonObject getInitialData() throws ParsingException {
|
||||||
|
try {
|
||||||
|
String initialData = Parser.matchGroup1("window\\[\"ytInitialData\"\\]\\s*=\\s*(\\{.*?\\});", doc.toString());
|
||||||
|
return JsonParser.object().from(initialData);
|
||||||
|
} catch (JsonParserException | Parser.RegexException e) {
|
||||||
|
throw new ParsingException("Could not get ytInitialData", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -70,14 +85,17 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public String getName() throws ParsingException {
|
public String getName() throws ParsingException {
|
||||||
|
String name;
|
||||||
try {
|
try {
|
||||||
Element a = doc.select("a[href*=\"/feed/trending\"]").first();
|
name = initialData.getObject("header").getObject("feedTabbedHeaderRenderer").getObject("title")
|
||||||
Element span = a.select("span[class*=\"display-name\"]").first();
|
.getArray("runs").getObject(0).getString("text");
|
||||||
Element nameSpan = span.select("span").first();
|
|
||||||
return nameSpan.text();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ParsingException("Could not get Trending name", e);
|
throw new ParsingException("Could not get Trending name", e);
|
||||||
}
|
}
|
||||||
|
if (name != null && !name.isEmpty()) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
throw new ParsingException("Could not get Trending name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
Loading…
Reference in New Issue