Skip to content

Commit 609919d

Browse files
committed
Adress again reviews, fix some rebase issues
1 parent 4299d80 commit 609919d

8 files changed

Lines changed: 13 additions & 13 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ private YoutubeParsingHelper() {
6666

6767
public static final String YOUTUBEI_V1_URL = "https://www.youtube.com/youtubei/v1/";
6868

69-
private static final String HARDCODED_CLIENT_VERSION = "2.20210622.10.00";
69+
private static final String HARDCODED_CLIENT_VERSION = "2.20210623.00.00";
7070
private static final String HARDCODED_KEY = "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8";
7171
private static final String MOBILE_YOUTUBE_KEY = "AIzaSyA8eiZmM1FaDVjRy-df2KTyQ_vz_yYM39w";
7272
private static final String MOBILE_YOUTUBE_CLIENT_VERSION = "16.23.36";
@@ -324,8 +324,6 @@ public static boolean areHardcodedClientVersionAndKeyValid()
324324
.value("clientVersion", HARDCODED_CLIENT_VERSION)
325325
.end()
326326
.object("user")
327-
// TO DO: provide a way to enable restricted mode with:
328-
// .value("enableSafetyMode", boolean)
329327
.value("lockedSafetyMode", false)
330328
.end()
331329
.value("fetchLiveState", true)
@@ -353,7 +351,7 @@ private static void extractClientVersionAndKey() throws IOException, ExtractionE
353351
// Don't extract the client version and the innertube key if it has been already extracted
354352
if (keyAndVersionExtracted) return;
355353
// Don't provide a search term in order to have a smaller response
356-
final String url = "https://www.youtube.com/results?search_query=";
354+
final String url = "https://www.youtube.com/results?search_query=&ucbcb=1";
357355
final Map<String, List<String>> headers = new HashMap<>();
358356
addCookieHeader(headers);
359357
final String html = getDownloader().get(url, headers).responseBody();
@@ -472,7 +470,7 @@ public static void resetClientVersionAndKey() {
472470
* <b>Only use in tests.</b>
473471
* </p>
474472
*/
475-
public static void setNumberGenerator(Random random) {
473+
public static void setNumberGenerator(final Random random) {
476474
numberGenerator = random;
477475
}
478476

@@ -749,6 +747,7 @@ public static JsonObject getJsonPostResponse(final String endpoint,
749747
throws IOException, ExtractionException {
750748
final Map<String, List<String>> headers = new HashMap<>();
751749
addClientInfoHeaders(headers);
750+
headers.put("Content-Type", Collections.singletonList("application/json"));
752751

753752
final Response response = getDownloader().post(YOUTUBEI_V1_URL + endpoint + "?key="
754753
+ getKey(), headers, body, localization);
@@ -814,6 +813,8 @@ public static JsonBuilder<JsonObject> prepareJsonBuilder(@Nonnull final Localiza
814813
.value("clientVersion", getClientVersion())
815814
.end()
816815
.object("user")
816+
// TO DO: provide a way to enable restricted mode with:
817+
// .value("enableSafetyMode", boolean)
817818
.value("lockedSafetyMode", false)
818819
.end()
819820
.end();
@@ -877,7 +878,7 @@ public static void addClientInfoHeaders(@Nonnull final Map<String, List<String>>
877878
* @see #CONSENT_COOKIE
878879
* @param headers the headers which should be completed
879880
*/
880-
public static void addCookieHeader(final Map<String, List<String>> headers) {
881+
public static void addCookieHeader(@Nonnull final Map<String, List<String>> headers) {
881882
if (headers.get("Cookie") == null) {
882883
headers.put("Cookie", Arrays.asList(generateConsentCookie()));
883884
} else {

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeChannelExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
8585
final String[] channelInfo = channel_path.split("/");
8686
String id = "";
8787
// If the url is an URL which is not a /channel URL, we need to use the
88-
// navigation/resolve_url endpoint of the internal API to get the channel id. Otherwise, we
88+
// navigation/resolve_url endpoint of the youtubei API to get the channel id. Otherwise, we
8989
// couldn't get information about the channel associated with this URL, if there is one.
9090
if (!channelInfo[0].equals("channel")) {
9191
final byte[] body = JsonWriter.string(prepareJsonBuilder(getExtractorLocalization(),

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeCommentsExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private void collectCommentsFrom(final CommentsInfoItemsCollector collector, fin
189189
public void onFetchPage(@Nonnull final Downloader downloader) throws IOException, ExtractionException {
190190
final Map<String, List<String>> requestHeaders = new HashMap<>();
191191
requestHeaders.put("User-Agent", singletonList(USER_AGENT));
192-
final Response response = downloader.get(getUrl(), requestHeaders, getExtractorLocalization());
192+
final Response response = downloader.get(getUrl() + "&ucbcb=1", requestHeaders, getExtractorLocalization());
193193
responseBody = YoutubeParsingHelper.unescapeDocument(response.responseBody());
194194
ytClientVersion = findValue(responseBody, "INNERTUBE_CONTEXT_CLIENT_VERSION\":\"", "\"");
195195
ytClientName = Parser.matchGroup1(YT_CLIENT_NAME_PATTERN, responseBody);

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ public List<SubtitlesStream> getSubtitles(final MediaFormat format) throws Parsi
645645
public StreamType getStreamType() {
646646
assertPageFetched();
647647

648-
if (playerResponse.getObject("videoDetails").getBoolean("isLiveContent", false)) {
648+
if (playerResponse.getObject("playabilityStatus").has("liveStreamability")
649+
|| playerResponse.getObject("videoDetails").getBoolean("isPostLiveDvr", false)) {
649650
return StreamType.LIVE_STREAM;
650651
}
651652
return StreamType.VIDEO_STREAM;

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeFeedExtractorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,5 @@ public void AccountTerminatedFetch() throws Exception {
9393
.getFeedExtractor("https://www.youtube.com/channel/UCTGjY2I-ZUGnwVoWAGRd7XQ");
9494
extractor.fetchPage();
9595
}
96-
9796
}
9897
}

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeMixPlaylistExtractorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.grack.nanojson.JsonWriter;
44
import org.hamcrest.MatcherAssert;
55
import org.junit.BeforeClass;
6+
import org.junit.Ignore;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
89
import org.junit.runners.Suite;
@@ -132,7 +133,7 @@ public void getStreamCount() {
132133
}
133134
}
134135

135-
@Ignore
136+
@Ignore("Test broken, video was removed by the uploader")
136137
public static class MixWithIndex {
137138

138139
private static final int INDEX = 13;

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorControversialTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.extractor.services.youtube.stream;
22

33
import org.junit.BeforeClass;
4-
import org.junit.Ignore;
54
import org.schabi.newpipe.downloader.DownloaderFactory;
65
import org.schabi.newpipe.extractor.NewPipe;
76
import org.schabi.newpipe.extractor.StreamingService;

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/stream/YoutubeStreamExtractorLivestreamTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.extractor.services.youtube.stream;
22

33
import org.junit.BeforeClass;
4-
import org.junit.Ignore;
54
import org.junit.Test;
65
import org.schabi.newpipe.downloader.DownloaderFactory;
76
import org.schabi.newpipe.extractor.NewPipe;

0 commit comments

Comments
 (0)