Skip to content

Commit ff8ed72

Browse files
committed
[YouTube] Switch to new consent cookie
Also move the documentation of the consent in its setter method in order to be accessible publicly and improve it.
1 parent ec838d7 commit ff8ed72

1 file changed

Lines changed: 25 additions & 24 deletions

File tree

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,6 @@ private YoutubeParsingHelper() {
260260
private static final Set<String> YOUTUBE_URLS = Set.of("youtube.com", "www.youtube.com",
261261
"m.youtube.com", "music.youtube.com");
262262

263-
/**
264-
* Determines how the consent cookie (that is required for YouTube) will be generated.
265-
*
266-
* <p>
267-
* {@code false} (default) will use {@code PENDING+}.
268-
* {@code true} will use {@code YES+}.
269-
* </p>
270-
*
271-
* <p>
272-
* Setting this value to <code>true</code> is currently needed if you want to watch
273-
* Mix Playlists in some countries (EU).
274-
* </p>
275-
*
276-
* @see #generateConsentCookie()
277-
*/
278263
private static boolean consentAccepted = false;
279264

280265
private static boolean isGoogleURL(final String url) {
@@ -1583,13 +1568,15 @@ public static Map<String, List<String>> getCookieHeader() {
15831568

15841569
@Nonnull
15851570
public static String generateConsentCookie() {
1586-
return "CONSENT=" + (isConsentAccepted()
1587-
// YES+ means that the user did submit their choices and allows tracking.
1588-
? "YES+"
1589-
// PENDING+ means that the user did not yet submit their choices.
1590-
// YT & Google should not track the user, because they did not give consent.
1591-
// The three digits at the end can be random, but are required.
1592-
: "PENDING+" + (100 + numberGenerator.nextInt(900)));
1571+
return "SOCS=" + (isConsentAccepted()
1572+
// CAISAiAD means that the user configured manually cookies YouTube, regardless of
1573+
// the consent values
1574+
// This value surprisingly allows to extract mixes and some YouTube Music playlists
1575+
// in the same way when a user allows all cookies
1576+
? "CAISAiAD"
1577+
// CAE= means that the user rejected all non-necessary cookies with the "Reject
1578+
// all" button on the consent page
1579+
: "CAE=");
15931580
}
15941581

15951582
public static String extractCookieValue(final String cookieName,
@@ -1881,14 +1868,28 @@ public static boolean isIosStreamingUrl(@Nonnull final String url) {
18811868
}
18821869

18831870
/**
1884-
* @see #consentAccepted
1871+
* Determines how the consent cookie that is required for YouTube, {@code SOCS}, will be
1872+
* generated.
1873+
*
1874+
* <ul>
1875+
* <li>{@code false} (the default value) will use {@code CAE=};</li>
1876+
* <li>{@code true} will use {@code CAISAiAD}.</li>
1877+
* </ul>
1878+
*
1879+
* <p>
1880+
* Setting this value to {@code true} is needed to extract mixes and some YouTube Music
1881+
* playlists in some countries such as the EU ones.
1882+
* </p>
18851883
*/
18861884
public static void setConsentAccepted(final boolean accepted) {
18871885
consentAccepted = accepted;
18881886
}
18891887

18901888
/**
1891-
* @see #consentAccepted
1889+
* Get the value of the consent's acceptance.
1890+
*
1891+
* @see #setConsentAccepted(boolean)
1892+
* @return the consent's acceptance value
18921893
*/
18931894
public static boolean isConsentAccepted() {
18941895
return consentAccepted;

0 commit comments

Comments
 (0)