Fix localization and update client version
This commit is contained in:
parent
f46cfb0f26
commit
4d682834c3
5 changed files with 33 additions and 24 deletions
|
@ -8,10 +8,10 @@ import com.grack.nanojson.JsonParserException;
|
||||||
import com.grack.nanojson.JsonWriter;
|
import com.grack.nanojson.JsonWriter;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.MetaInfo;
|
import org.schabi.newpipe.extractor.MetaInfo;
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.downloader.Response;
|
import org.schabi.newpipe.extractor.downloader.Response;
|
||||||
import org.schabi.newpipe.extractor.exceptions.*;
|
import org.schabi.newpipe.extractor.exceptions.*;
|
||||||
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||||
import org.schabi.newpipe.extractor.localization.Localization;
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.stream.Description;
|
import org.schabi.newpipe.extractor.stream.Description;
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
|
@ -64,7 +64,7 @@ public class YoutubeParsingHelper {
|
||||||
private YoutubeParsingHelper() {
|
private YoutubeParsingHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String HARDCODED_CLIENT_VERSION = "2.20210420.07.00";
|
private static final String HARDCODED_CLIENT_VERSION = "2.20210429.07.00";
|
||||||
private static final String HARDCODED_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
|
private static final String HARDCODED_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
|
||||||
private static final String YOUTUBEI_V1_URL = "https://youtubei.googleapis.com/youtubei/v1/";
|
private static final String YOUTUBEI_V1_URL = "https://youtubei.googleapis.com/youtubei/v1/";
|
||||||
private static String clientVersion;
|
private static String clientVersion;
|
||||||
|
@ -763,7 +763,8 @@ public class YoutubeParsingHelper {
|
||||||
return JsonUtils.toJsonArray(getValidJsonResponseBody(response));
|
return JsonUtils.toJsonArray(getValidJsonResponseBody(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonBuilder<JsonObject> prepareJsonBuilder(final String contentCountry)
|
public static JsonBuilder<JsonObject> prepareJsonBuilder(final Localization localization,
|
||||||
|
final ContentCountry contentCountry)
|
||||||
throws IOException, ExtractionException {
|
throws IOException, ExtractionException {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
return JsonObject.builder()
|
return JsonObject.builder()
|
||||||
|
@ -771,8 +772,8 @@ public class YoutubeParsingHelper {
|
||||||
.object("client")
|
.object("client")
|
||||||
.value("clientName", "1")
|
.value("clientName", "1")
|
||||||
.value("clientVersion", getClientVersion())
|
.value("clientVersion", getClientVersion())
|
||||||
.value("hl", NewPipe.getPreferredLocalization().getLocalizationCode())
|
.value("hl", localization.getLocalizationCode())
|
||||||
.value("gl", contentCountry)
|
.value("gl", contentCountry.getCountryCode())
|
||||||
.end()
|
.end()
|
||||||
.end();
|
.end();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
|
||||||
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.linkhandler.ListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
|
||||||
|
@ -83,13 +84,13 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
ExtractionException {
|
ExtractionException {
|
||||||
final String channel_path = super.getId();
|
final String channel_path = super.getId();
|
||||||
final String[] channelInfo = channel_path.split("/");
|
final String[] channelInfo = channel_path.split("/");
|
||||||
final String contentCountry = getExtractorContentCountry().getCountryCode();
|
|
||||||
String id = "";
|
String id = "";
|
||||||
// If the url is an URL which is not a /channel URL, we need to use the
|
// If the url is an URL which is not a /channel URL, we need to use the
|
||||||
// navigation/resolve_url endpoint of the youtubei API to get the channel id. Otherwise, we
|
// navigation/resolve_url endpoint of the youtubei API to get the channel id. Otherwise, we
|
||||||
// couldn't get information about the channel associated with this URL, if there is one.
|
// couldn't get information about the channel associated with this URL, if there is one.
|
||||||
if (!channelInfo[0].equals("channel")) {
|
if (!channelInfo[0].equals("channel")) {
|
||||||
final byte[] body = JsonWriter.string(prepareJsonBuilder(contentCountry)
|
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
|
||||||
|
getExtractorContentCountry())
|
||||||
.value("url", "https://www.youtube.com/" + channel_path)
|
.value("url", "https://www.youtube.com/" + channel_path)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
@ -134,7 +135,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
|
|
||||||
int level = 0;
|
int level = 0;
|
||||||
while (level < 3) {
|
while (level < 3) {
|
||||||
final byte[] body = JsonWriter.string(prepareJsonBuilder(contentCountry)
|
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
|
||||||
|
getExtractorContentCountry())
|
||||||
.value("browseId", id)
|
.value("browseId", id)
|
||||||
.value("params", "EgZ2aWRlb3M%3D") // equals to videos
|
.value("params", "EgZ2aWRlb3M%3D") // equals to videos
|
||||||
.done())
|
.done())
|
||||||
|
@ -375,8 +377,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
final String continuation = continuationEndpoint.getObject("continuationCommand")
|
final String continuation = continuationEndpoint.getObject("continuationCommand")
|
||||||
.getString("token");
|
.getString("token");
|
||||||
|
|
||||||
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
|
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
|
||||||
.getCountryCode())
|
getExtractorContentCountry())
|
||||||
.value("continuation", continuation)
|
.value("continuation", continuation)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
|
@ -11,6 +11,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.linkhandler.ListLinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||||
|
@ -45,14 +46,15 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
|
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
|
||||||
ExtractionException {
|
ExtractionException {
|
||||||
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
|
final Localization localization = getExtractorLocalization();
|
||||||
.getCountryCode())
|
final byte[] body = JsonWriter.string(prepareJsonBuilder(localization,
|
||||||
|
getExtractorContentCountry())
|
||||||
.value("browseId", "VL" + getId())
|
.value("browseId", "VL" + getId())
|
||||||
.value("params", "wgYCCAA%3D") // show unavailable videos
|
.value("params", "wgYCCAA%3D") // show unavailable videos
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
||||||
initialData = getJsonPostResponse("browse", body, getExtractorLocalization());
|
initialData = getJsonPostResponse("browse", body, localization);
|
||||||
YoutubeParsingHelper.defaultAlertsCheck(initialData);
|
YoutubeParsingHelper.defaultAlertsCheck(initialData);
|
||||||
|
|
||||||
playlistInfo = getPlaylistInfo();
|
playlistInfo = getPlaylistInfo();
|
||||||
|
@ -251,8 +253,8 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
|
||||||
.getObject("continuationCommand")
|
.getObject("continuationCommand")
|
||||||
.getString("token");
|
.getString("token");
|
||||||
|
|
||||||
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
|
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
|
||||||
.getCountryCode())
|
getExtractorContentCountry())
|
||||||
.value("continuation", continuation)
|
.value("continuation", continuation)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
|
@ -9,6 +9,8 @@ import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
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.linkhandler.SearchQueryHandler;
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
|
||||||
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||||
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
|
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
|
||||||
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
||||||
|
@ -57,7 +59,8 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
|
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
|
||||||
ExtractionException {
|
ExtractionException {
|
||||||
final String query = super.getSearchString();
|
final String query = super.getSearchString();
|
||||||
final String contentCountry = getExtractorContentCountry().getCountryCode();
|
final Localization localization = getExtractorLocalization();
|
||||||
|
final ContentCountry contentCountry = getExtractorContentCountry();
|
||||||
|
|
||||||
// Get the search parameter of the request
|
// Get the search parameter of the request
|
||||||
final List<String> contentFilters = super.getLinkHandler().getContentFilters();
|
final List<String> contentFilters = super.getLinkHandler().getContentFilters();
|
||||||
|
@ -71,19 +74,19 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
|
|
||||||
final byte[] body;
|
final byte[] body;
|
||||||
if (!isNullOrEmpty(params)) {
|
if (!isNullOrEmpty(params)) {
|
||||||
body = JsonWriter.string(prepareJsonBuilder(contentCountry)
|
body = JsonWriter.string(prepareJsonBuilder(localization, contentCountry)
|
||||||
.value("query", query)
|
.value("query", query)
|
||||||
.value("params", params)
|
.value("params", params)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
} else {
|
} else {
|
||||||
body = JsonWriter.string(prepareJsonBuilder(contentCountry)
|
body = JsonWriter.string(prepareJsonBuilder(localization, contentCountry)
|
||||||
.value("query", query)
|
.value("query", query)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialData = getJsonPostResponse("search", body, getExtractorLocalization());
|
initialData = getJsonPostResponse("search", body, localization);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
@ -168,10 +171,11 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
throw new IllegalArgumentException("Page doesn't contain an URL");
|
throw new IllegalArgumentException("Page doesn't contain an URL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Localization localization = getExtractorLocalization();
|
||||||
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
|
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
|
||||||
|
|
||||||
if (page.getId() == null) {
|
if (page.getId() == null) {
|
||||||
final JsonArray ajaxJson = getJsonResponse(page.getUrl(), getExtractorLocalization());
|
final JsonArray ajaxJson = getJsonResponse(page.getUrl(), localization);
|
||||||
|
|
||||||
final JsonObject itemSectionContinuation = ajaxJson.getObject(1).getObject("response")
|
final JsonObject itemSectionContinuation = ajaxJson.getObject(1).getObject("response")
|
||||||
.getObject("continuationContents").getObject("itemSectionContinuation");
|
.getObject("continuationContents").getObject("itemSectionContinuation");
|
||||||
|
@ -182,8 +186,8 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
return new InfoItemsPage<>(collector, getNextPageFrom(continuations));
|
return new InfoItemsPage<>(collector, getNextPageFrom(continuations));
|
||||||
} else {
|
} else {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
final byte[] json = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
|
final byte[] json = JsonWriter.string(prepareJsonBuilder(localization,
|
||||||
.getCountryCode())
|
getExtractorContentCountry())
|
||||||
.value("continuation", page.getId())
|
.value("continuation", page.getId())
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
|
@ -57,8 +57,8 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
@Override
|
@Override
|
||||||
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
|
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
|
||||||
.getCountryCode())
|
getExtractorContentCountry())
|
||||||
.value("browseId", "FEtrending")
|
.value("browseId", "FEtrending")
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(UTF_8);
|
||||||
|
|
Loading…
Reference in a new issue