Adress again reviews, fix some rebase issues

This commit is contained in:
TiA4f8R 2021-06-26 20:04:55 +02:00
parent 4299d806a2
commit 609919db59
No known key found for this signature in database
GPG Key ID: E6D3E7F5949450DD
8 changed files with 13 additions and 13 deletions

View File

@ -66,7 +66,7 @@ public class YoutubeParsingHelper {
public static final String YOUTUBEI_V1_URL = "https://www.youtube.com/youtubei/v1/"; public static final String YOUTUBEI_V1_URL = "https://www.youtube.com/youtubei/v1/";
private static final String HARDCODED_CLIENT_VERSION = "2.20210622.10.00"; private static final String HARDCODED_CLIENT_VERSION = "2.20210623.00.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 MOBILE_YOUTUBE_KEY = "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w"; private static final String MOBILE_YOUTUBE_KEY = "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w";
private static final String MOBILE_YOUTUBE_CLIENT_VERSION = "16.23.36"; private static final String MOBILE_YOUTUBE_CLIENT_VERSION = "16.23.36";
@ -324,8 +324,6 @@ public class YoutubeParsingHelper {
.value("clientVersion", HARDCODED_CLIENT_VERSION) .value("clientVersion", HARDCODED_CLIENT_VERSION)
.end() .end()
.object("user") .object("user")
// TO DO: provide a way to enable restricted mode with:
// .value("enableSafetyMode", boolean)
.value("lockedSafetyMode", false) .value("lockedSafetyMode", false)
.end() .end()
.value("fetchLiveState", true) .value("fetchLiveState", true)
@ -353,7 +351,7 @@ public class YoutubeParsingHelper {
// Don't extract the client version and the innertube key if it has been already extracted // Don't extract the client version and the innertube key if it has been already extracted
if (keyAndVersionExtracted) return; if (keyAndVersionExtracted) return;
// Don't provide a search term in order to have a smaller response // Don't provide a search term in order to have a smaller response
final String url = "https://www.youtube.com/results?search_query="; final String url = "https://www.youtube.com/results?search_query=&ucbcb=1";
final Map<String, List<String>> headers = new HashMap<>(); final Map<String, List<String>> headers = new HashMap<>();
addCookieHeader(headers); addCookieHeader(headers);
final String html = getDownloader().get(url, headers).responseBody(); final String html = getDownloader().get(url, headers).responseBody();
@ -472,7 +470,7 @@ public class YoutubeParsingHelper {
* <b>Only use in tests.</b> * <b>Only use in tests.</b>
* </p> * </p>
*/ */
public static void setNumberGenerator(Random random) { public static void setNumberGenerator(final Random random) {
numberGenerator = random; numberGenerator = random;
} }
@ -749,6 +747,7 @@ public class YoutubeParsingHelper {
throws IOException, ExtractionException { throws IOException, ExtractionException {
final Map<String, List<String>> headers = new HashMap<>(); final Map<String, List<String>> headers = new HashMap<>();
addClientInfoHeaders(headers); addClientInfoHeaders(headers);
headers.put("Content-Type", Collections.singletonList("application/json"));
final Response response = getDownloader().post(YOUTUBEI_V1_URL + endpoint + "?key=" final Response response = getDownloader().post(YOUTUBEI_V1_URL + endpoint + "?key="
+ getKey(), headers, body, localization); + getKey(), headers, body, localization);
@ -814,6 +813,8 @@ public class YoutubeParsingHelper {
.value("clientVersion", getClientVersion()) .value("clientVersion", getClientVersion())
.end() .end()
.object("user") .object("user")
// TO DO: provide a way to enable restricted mode with:
// .value("enableSafetyMode", boolean)
.value("lockedSafetyMode", false) .value("lockedSafetyMode", false)
.end() .end()
.end(); .end();
@ -877,7 +878,7 @@ public class YoutubeParsingHelper {
* @see #CONSENT_COOKIE * @see #CONSENT_COOKIE
* @param headers the headers which should be completed * @param headers the headers which should be completed
*/ */
public static void addCookieHeader(final Map<String, List<String>> headers) { public static void addCookieHeader(@Nonnull final Map<String, List<String>> headers) {
if (headers.get("Cookie") == null) { if (headers.get("Cookie") == null) {
headers.put("Cookie", Arrays.asList(generateConsentCookie())); headers.put("Cookie", Arrays.asList(generateConsentCookie()));
} else { } else {

View File

@ -85,7 +85,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
final String[] channelInfo = channel_path.split("/"); final String[] channelInfo = channel_path.split("/");
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 internal 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(getExtractorLocalization(), final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),

View File

@ -189,7 +189,7 @@ public class YoutubeCommentsExtractor extends CommentsExtractor {
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException { public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
final Map<String, List<String>> requestHeaders = new HashMap<>(); final Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put("User-Agent", singletonList(USER_AGENT)); requestHeaders.put("User-Agent", singletonList(USER_AGENT));
final Response response = downloader.get(getUrl(), requestHeaders, getExtractorLocalization()); final Response response = downloader.get(getUrl() + "&ucbcb=1", requestHeaders, getExtractorLocalization());
responseBody = YoutubeParsingHelper.unescapeDocument(response.responseBody()); responseBody = YoutubeParsingHelper.unescapeDocument(response.responseBody());
ytClientVersion = findValue(responseBody, "INNERTUBE_CONTEXT_CLIENT_VERSION\":\"", "\""); ytClientVersion = findValue(responseBody, "INNERTUBE_CONTEXT_CLIENT_VERSION\":\"", "\"");
ytClientName = Parser.matchGroup1(YT_CLIENT_NAME_PATTERN, responseBody); ytClientName = Parser.matchGroup1(YT_CLIENT_NAME_PATTERN, responseBody);

View File

@ -645,7 +645,8 @@ public class YoutubeStreamExtractor extends StreamExtractor {
public StreamType getStreamType() { public StreamType getStreamType() {
assertPageFetched(); assertPageFetched();
if (playerResponse.getObject("videoDetails").getBoolean("isLiveContent", false)) { if (playerResponse.getObject("playabilityStatus").has("liveStreamability")
|| playerResponse.getObject("videoDetails").getBoolean("isPostLiveDvr", false)) {
return StreamType.LIVE_STREAM; return StreamType.LIVE_STREAM;
} }
return StreamType.VIDEO_STREAM; return StreamType.VIDEO_STREAM;

View File

@ -93,6 +93,5 @@ public class YoutubeFeedExtractorTest {
.getFeedExtractor("https://www.youtube.com/channel/UCTGjY2I-ZUGnwVoWAGRd7XQ"); .getFeedExtractor("https://www.youtube.com/channel/UCTGjY2I-ZUGnwVoWAGRd7XQ");
extractor.fetchPage(); extractor.fetchPage();
} }
} }
} }

View File

@ -3,6 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube;
import com.grack.nanojson.JsonWriter; import com.grack.nanojson.JsonWriter;
import org.hamcrest.MatcherAssert; import org.hamcrest.MatcherAssert;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Suite; import org.junit.runners.Suite;
@ -132,7 +133,7 @@ public class YoutubeMixPlaylistExtractorTest {
} }
} }
@Ignore @Ignore("Test broken, video was removed by the uploader")
public static class MixWithIndex { public static class MixWithIndex {
private static final int INDEX = 13; private static final int INDEX = 13;

View File

@ -1,7 +1,6 @@
package org.schabi.newpipe.extractor.services.youtube.stream; package org.schabi.newpipe.extractor.services.youtube.stream;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;

View File

@ -1,7 +1,6 @@
package org.schabi.newpipe.extractor.services.youtube.stream; package org.schabi.newpipe.extractor.services.youtube.stream;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.schabi.newpipe.downloader.DownloaderFactory; import org.schabi.newpipe.downloader.DownloaderFactory;
import org.schabi.newpipe.extractor.NewPipe; import org.schabi.newpipe.extractor.NewPipe;