Fix localization and update client version

This commit is contained in:
TiA4f8R 2021-04-30 19:06:56 +02:00
parent f46cfb0f26
commit 4d682834c3
No known key found for this signature in database
GPG key ID: E6D3E7F5949450DD
5 changed files with 33 additions and 24 deletions

View file

@ -8,10 +8,10 @@ import com.grack.nanojson.JsonParserException;
import com.grack.nanojson.JsonWriter;
import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.Page;
import org.schabi.newpipe.extractor.downloader.Response;
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.stream.Description;
import org.schabi.newpipe.extractor.utils.JsonUtils;
@ -64,7 +64,7 @@ public class 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 YOUTUBEI_V1_URL = "https://youtubei.googleapis.com/youtubei/v1/";
private static String clientVersion;
@ -763,7 +763,8 @@ public class YoutubeParsingHelper {
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 {
// @formatter:off
return JsonObject.builder()
@ -771,8 +772,8 @@ public class YoutubeParsingHelper {
.object("client")
.value("clientName", "1")
.value("clientVersion", getClientVersion())
.value("hl", NewPipe.getPreferredLocalization().getLocalizationCode())
.value("gl", contentCountry)
.value("hl", localization.getLocalizationCode())
.value("gl", contentCountry.getCountryCode())
.end()
.end();
// @formatter:on

View file

@ -14,6 +14,7 @@ import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
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.services.youtube.YoutubeParsingHelper;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
@ -83,13 +84,13 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
ExtractionException {
final String channel_path = super.getId();
final String[] channelInfo = channel_path.split("/");
final String contentCountry = getExtractorContentCountry().getCountryCode();
String id = "";
// 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
// couldn't get information about the channel associated with this URL, if there is one.
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)
.done())
.getBytes(UTF_8);
@ -134,7 +135,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
int level = 0;
while (level < 3) {
final byte[] body = JsonWriter.string(prepareJsonBuilder(contentCountry)
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
getExtractorContentCountry())
.value("browseId", id)
.value("params", "EgZ2aWRlb3M%3D") // equals to videos
.done())
@ -375,8 +377,8 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
final String continuation = continuationEndpoint.getObject("continuationCommand")
.getString("token");
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
.getCountryCode())
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
getExtractorContentCountry())
.value("continuation", continuation)
.done())
.getBytes(UTF_8);

View file

@ -11,6 +11,7 @@ import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
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.playlist.PlaylistExtractor;
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
@ -45,14 +46,15 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException,
ExtractionException {
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
.getCountryCode())
final Localization localization = getExtractorLocalization();
final byte[] body = JsonWriter.string(prepareJsonBuilder(localization,
getExtractorContentCountry())
.value("browseId", "VL" + getId())
.value("params", "wgYCCAA%3D") // show unavailable videos
.done())
.getBytes(UTF_8);
initialData = getJsonPostResponse("browse", body, getExtractorLocalization());
initialData = getJsonPostResponse("browse", body, localization);
YoutubeParsingHelper.defaultAlertsCheck(initialData);
playlistInfo = getPlaylistInfo();
@ -251,8 +253,8 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
.getObject("continuationCommand")
.getString("token");
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
.getCountryCode())
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
getExtractorContentCountry())
.value("continuation", continuation)
.done())
.getBytes(UTF_8);

View file

@ -9,6 +9,8 @@ import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
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.search.InfoItemsSearchCollector;
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,
ExtractionException {
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
final List<String> contentFilters = super.getLinkHandler().getContentFilters();
@ -71,19 +74,19 @@ public class YoutubeSearchExtractor extends SearchExtractor {
final byte[] body;
if (!isNullOrEmpty(params)) {
body = JsonWriter.string(prepareJsonBuilder(contentCountry)
body = JsonWriter.string(prepareJsonBuilder(localization, contentCountry)
.value("query", query)
.value("params", params)
.done())
.getBytes(UTF_8);
} else {
body = JsonWriter.string(prepareJsonBuilder(contentCountry)
body = JsonWriter.string(prepareJsonBuilder(localization, contentCountry)
.value("query", query)
.done())
.getBytes(UTF_8);
}
initialData = getJsonPostResponse("search", body, getExtractorLocalization());
initialData = getJsonPostResponse("search", body, localization);
}
@Nonnull
@ -168,10 +171,11 @@ public class YoutubeSearchExtractor extends SearchExtractor {
throw new IllegalArgumentException("Page doesn't contain an URL");
}
final Localization localization = getExtractorLocalization();
final InfoItemsSearchCollector collector = new InfoItemsSearchCollector(getServiceId());
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")
.getObject("continuationContents").getObject("itemSectionContinuation");
@ -182,8 +186,8 @@ public class YoutubeSearchExtractor extends SearchExtractor {
return new InfoItemsPage<>(collector, getNextPageFrom(continuations));
} else {
// @formatter:off
final byte[] json = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
.getCountryCode())
final byte[] json = JsonWriter.string(prepareJsonBuilder(localization,
getExtractorContentCountry())
.value("continuation", page.getId())
.done())
.getBytes(UTF_8);

View file

@ -57,8 +57,8 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
@Override
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
// @formatter:off
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorContentCountry()
.getCountryCode())
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),
getExtractorContentCountry())
.value("browseId", "FEtrending")
.done())
.getBytes(UTF_8);