[vlc-commits] youtube.lua: disable cookies if redirected to consent page

Pierre Ynard git at videolan.org
Sat Apr 3 10:17:42 UTC 2021


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Sat Apr  3 12:02:34 2021 +0200| [f21c063ea3b8050541e5c8f4430378dfec85f4a5] | committer: Pierre Ynard

youtube.lua: disable cookies if redirected to consent page

In the past few days, YouTube has started redirecting requests for video
pages to a cookie consent and preference prompt, on a whole separate
page and domain; which prevents playback. We are not interested in
YouTube cookies, nor in consenting to them on behalf of our users, so
this just retries with cookies disabled. YouTube gets the hint and
simply redirects back to the original video page.

Fixes #25616

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f21c063ea3b8050541e5c8f4430378dfec85f4a5
---

 share/lua/playlist/youtube.lua | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index f8a8937387..65c81514d1 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -303,8 +303,8 @@ end
 
 -- Probe function.
 function probe()
-    return ( ( vlc.access == "http" or vlc.access == "https" )
-             and (
+    return ( ( vlc.access == "http" or vlc.access == "https" ) and (
+            ((
                string.match( vlc.path, "^www%.youtube%.com/" )
             or string.match( vlc.path, "^music%.youtube%.com/" )
             or string.match( vlc.path, "^gaming%.youtube%.com/" ) -- out of use
@@ -315,14 +315,27 @@ function probe()
             or string.match( vlc.path, "/get_video_info%?" ) -- info API
             or string.match( vlc.path, "/v/" ) -- video in swf player
             or string.match( vlc.path, "/embed/" ) -- embedded player iframe
-             ) )
+             )) or
+               string.match( vlc.path, "^consent%.youtube%.com/" )
+         ) )
 end
 
 -- Parse function.
 function parse()
-    if not string.match( vlc.path, "^www%.youtube%.com/" ) then
+    if string.match( vlc.path, "^consent%.youtube%.com/" ) then
+        -- Cookie consent redirection
+        -- Location: https://consent.youtube.com/m?continue=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DXXXXXXXXXXX&gl=FR&m=0&pc=yt&uxe=23983172&hl=fr&src=1
+        -- Set-Cookie: CONSENT=PENDING+355; expires=Fri, 01-Jan-2038 00:00:00 GMT; path=/; domain=.youtube.com
+        local url = get_url_param( vlc.path, "continue" )
+        if not url then
+            vlc.msg.err( "Couldn't handle YouTube cookie consent redirection, please check for updates to this script or try disabling HTTP cookie forwarding" )
+            return { }
+        end
+        return { { path = vlc.strings.decode_uri( url ), options = { ":no-http-forward-cookies" } } }
+    elseif not string.match( vlc.path, "^www%.youtube%.com/" ) then
         -- Skin subdomain
         return { { path = vlc.access.."://"..string.gsub( vlc.path, "^([^/]*)/", "www.youtube.com/" ) } }
+
     elseif string.match( vlc.path, "/watch%?" )
         or string.match( vlc.path, "/live$" )
         or string.match( vlc.path, "/live%?" )



More information about the vlc-commits mailing list