mirror of
https://github.com/TeamNewPipe/NewPipeExtractor.git
synced 2025-04-29 00:10:35 +05:30
Use Localization in getJsonResponse()
This commit is contained in:
parent
157055fbfd
commit
45df8248bf
@ -57,7 +57,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
final String url = super.getUrl() + "/videos?pbj=1&view=0&flow=grid";
|
final String url = super.getUrl() + "/videos?pbj=1&view=0&flow=grid";
|
||||||
|
|
||||||
final JsonArray ajaxJson = getJsonResponse(url);
|
final JsonArray ajaxJson = getJsonResponse(url, getExtractorLocalization());
|
||||||
|
|
||||||
initialData = ajaxJson.getObject(1).getObject("response");
|
initialData = ajaxJson.getObject(1).getObject("response");
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
|||||||
fetchPage();
|
fetchPage();
|
||||||
|
|
||||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||||
final JsonArray ajaxJson = getJsonResponse(pageUrl);
|
final JsonArray ajaxJson = getJsonResponse(pageUrl, getExtractorLocalization());
|
||||||
|
|
||||||
JsonObject sectionListContinuation = ajaxJson.getObject(1).getObject("response")
|
JsonObject sectionListContinuation = ajaxJson.getObject(1).getObject("response")
|
||||||
.getObject("continuationContents").getObject("gridContinuation");
|
.getObject("continuationContents").getObject("gridContinuation");
|
||||||
|
@ -36,7 +36,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
final String url = getUrl() + "&pbj=1";
|
final String url = getUrl() + "&pbj=1";
|
||||||
|
|
||||||
final JsonArray ajaxJson = getJsonResponse(url);
|
final JsonArray ajaxJson = getJsonResponse(url, getExtractorLocalization());
|
||||||
|
|
||||||
initialData = ajaxJson.getObject(1).getObject("response");
|
initialData = ajaxJson.getObject(1).getObject("response");
|
||||||
playlistInfo = getPlaylistInfo();
|
playlistInfo = getPlaylistInfo();
|
||||||
@ -186,7 +186,7 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
|
||||||
final JsonArray ajaxJson = getJsonResponse(pageUrl);
|
final JsonArray ajaxJson = getJsonResponse(pageUrl, getExtractorLocalization());
|
||||||
|
|
||||||
JsonObject sectionListContinuation = ajaxJson.getObject(1).getObject("response")
|
JsonObject sectionListContinuation = ajaxJson.getObject(1).getObject("response")
|
||||||
.getObject("continuationContents").getObject("playlistVideoListContinuation");
|
.getObject("continuationContents").getObject("playlistVideoListContinuation");
|
||||||
|
@ -51,7 +51,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
final String url = getUrl() + "&pbj=1";
|
final String url = getUrl() + "&pbj=1";
|
||||||
|
|
||||||
final JsonArray ajaxJson = getJsonResponse(url);
|
final JsonArray ajaxJson = getJsonResponse(url, getExtractorLocalization());
|
||||||
|
|
||||||
initialData = ajaxJson.getObject(1).getObject("response");
|
initialData = ajaxJson.getObject(1).getObject("response");
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InfoItemsSearchCollector collector = getInfoItemSearchCollector();
|
InfoItemsSearchCollector collector = getInfoItemSearchCollector();
|
||||||
final JsonArray ajaxJson = getJsonResponse(pageUrl);
|
final JsonArray ajaxJson = getJsonResponse(pageUrl, getExtractorLocalization());
|
||||||
|
|
||||||
JsonObject itemSectionRenderer = ajaxJson.getObject(1).getObject("response")
|
JsonObject itemSectionRenderer = ajaxJson.getObject(1).getObject("response")
|
||||||
.getObject("continuationContents").getObject("itemSectionContinuation");
|
.getObject("continuationContents").getObject("itemSectionContinuation");
|
||||||
|
@ -580,7 +580,7 @@ public class YoutubeStreamExtractor extends StreamExtractor {
|
|||||||
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException {
|
||||||
final String url = getUrl() + "&pbj=1";
|
final String url = getUrl() + "&pbj=1";
|
||||||
|
|
||||||
initialAjaxJson = getJsonResponse(url);
|
initialAjaxJson = getJsonResponse(url, getExtractorLocalization());
|
||||||
|
|
||||||
final String playerUrl;
|
final String playerUrl;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
|||||||
final String url = getUrl() + "?pbj=1&gl="
|
final String url = getUrl() + "?pbj=1&gl="
|
||||||
+ getExtractorContentCountry().getCountryCode();
|
+ getExtractorContentCountry().getCountryCode();
|
||||||
|
|
||||||
final JsonArray ajaxJson = getJsonResponse(url);
|
final JsonArray ajaxJson = getJsonResponse(url, getExtractorLocalization());
|
||||||
|
|
||||||
initialData = ajaxJson.getObject(1).getObject("response");
|
initialData = ajaxJson.getObject(1).getObject("response");
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import org.schabi.newpipe.extractor.downloader.Response;
|
|||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.utils.Parser;
|
import org.schabi.newpipe.extractor.utils.Parser;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
@ -346,12 +347,12 @@ public class YoutubeParsingHelper {
|
|||||||
return thumbnailUrl;
|
return thumbnailUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonArray getJsonResponse(String url) throws IOException, ExtractionException {
|
public static JsonArray getJsonResponse(String url, Localization localization) throws IOException, ExtractionException {
|
||||||
Map<String, List<String>> headers = new HashMap<>();
|
Map<String, List<String>> headers = new HashMap<>();
|
||||||
headers.put("X-YouTube-Client-Name", Collections.singletonList("1"));
|
headers.put("X-YouTube-Client-Name", Collections.singletonList("1"));
|
||||||
headers.put("X-YouTube-Client-Version",
|
headers.put("X-YouTube-Client-Version",
|
||||||
Collections.singletonList(YoutubeParsingHelper.getClientVersion()));
|
Collections.singletonList(YoutubeParsingHelper.getClientVersion()));
|
||||||
final String response = getDownloader().get(url, headers).responseBody();
|
final String response = getDownloader().get(url, headers, localization).responseBody();
|
||||||
|
|
||||||
if (response.length() < 50) { // ensure to have a valid response
|
if (response.length() < 50) { // ensure to have a valid response
|
||||||
throw new ParsingException("JSON response is too short");
|
throw new ParsingException("JSON response is too short");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user