Add ytInitialData regex
This commit is contained in:
parent
a63371a2c5
commit
39bf1ff1eb
|
@ -49,6 +49,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000";
|
private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000";
|
||||||
|
|
||||||
private Document doc;
|
private Document doc;
|
||||||
|
private JsonObject ytInitialData;
|
||||||
|
|
||||||
public YoutubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
public YoutubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
|
||||||
super(service, linkHandler);
|
super(service, linkHandler);
|
||||||
|
@ -59,6 +60,16 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
String channelUrl = super.getUrl() + CHANNEL_URL_PARAMETERS;
|
String channelUrl = super.getUrl() + CHANNEL_URL_PARAMETERS;
|
||||||
final Response response = downloader.get(channelUrl, getExtractorLocalization());
|
final Response response = downloader.get(channelUrl, getExtractorLocalization());
|
||||||
doc = YoutubeParsingHelper.parseAndCheckPage(channelUrl, response);
|
doc = YoutubeParsingHelper.parseAndCheckPage(channelUrl, response);
|
||||||
|
ytInitialData = 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
|
||||||
|
|
|
@ -88,6 +88,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final Map<String, String> videoInfoPage = new HashMap<>();
|
private final Map<String, String> videoInfoPage = new HashMap<>();
|
||||||
private JsonObject playerResponse;
|
private JsonObject playerResponse;
|
||||||
|
private JsonObject ytInitialData;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
|
private List<SubtitlesInfo> subtitlesInfos = new ArrayList<>();
|
||||||
|
@ -736,6 +737,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
isAgeRestricted = false;
|
isAgeRestricted = false;
|
||||||
}
|
}
|
||||||
playerResponse = getPlayerResponse();
|
playerResponse = getPlayerResponse();
|
||||||
|
ytInitialData = getInitialData();
|
||||||
|
|
||||||
if (decryptionCode.isEmpty()) {
|
if (decryptionCode.isEmpty()) {
|
||||||
decryptionCode = loadDecryptionCode(playerUrl);
|
decryptionCode = loadDecryptionCode(playerUrl);
|
||||||
|
@ -809,6 +811,15 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaException {
|
private EmbeddedInfo getEmbeddedInfo() throws ParsingException, ReCaptchaException {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.util.Map;
|
||||||
|
|
||||||
public class DownloaderTestImpl extends Downloader {
|
public class DownloaderTestImpl extends Downloader {
|
||||||
|
|
||||||
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
|
private static final String USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/73.0";
|
||||||
private static final String DEFAULT_HTTP_ACCEPT_LANGUAGE = "en";
|
private static final String DEFAULT_HTTP_ACCEPT_LANGUAGE = "en";
|
||||||
|
|
||||||
private static DownloaderTestImpl instance = null;
|
private static DownloaderTestImpl instance = null;
|
||||||
|
|
Loading…
Reference in New Issue