[vlc-commits] youtube.lua: support new HTML code layout

Pierre Ynard git at videolan.org
Tue Nov 3 01:34:39 CET 2020


vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Tue Nov  3 01:20:21 2020 +0100| [671afe05eb6109117a57d7ec9871caf9cdace382] | committer: Pierre Ynard

youtube.lua: support new HTML code layout

This new layout is apparently getting phased in. As major differences,
line splitting is more erratic (with overall 10 times fewer lines for a
slightly bigger HTML document), and the main stream configuration isn't
subjected to double JSON string encoding anymore.

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

 share/lua/playlist/youtube.lua | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index f45ea82edc..7d5f31ef3d 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -351,14 +351,19 @@ function parse()
                 -- unlikely to access it due to #24957
                 description = string.match( line, '\\"shortDescription\\":\\"(.-[^\\])\\"')
                 if description then
-                    if string.match( description, '^\\"' ) then
+                    -- FIXME: do this properly (see #24958)
+                    description = string.gsub( description, '\\(["\\/])', '%1' )
+                else
+                    description = string.match( line, '"shortDescription":"(.-[^\\])"')
+                end
+                if description then
+                    if string.match( description, '^"' ) then
                         description = ""
                     end
                     -- FIXME: do this properly (see #24958)
                     -- This way of unescaping is technically wrong
                     -- so as little as possible of it should be done
                     description = string.gsub( description, '\\(["\\/])', '%1' )
-                    description = string.gsub( description, '\\(["\\/])', '%1' )
                     description = string.gsub( description, '\\n', '\n' )
                     description = string.gsub( description, '\\r', '\r' )
                     description = string.gsub( description, "\\u0026", "&" )
@@ -380,10 +385,22 @@ function parse()
                 if artist then
                     -- FIXME: do this properly (see #24958)
                     artist = string.gsub( artist, '\\(["\\/])', '%1' )
+                else
+                    artist = string.match( line, '"author":"(.-)"' )
+                end
+                if artist then
+                    -- FIXME: do this properly (see #24958)
                     artist = string.gsub( artist, "\\u0026", "&" )
                 end
             end
 
+            if not nonce then
+                if string.match( line, '<script nonce="' ) then
+                    vlc.msg.dbg( "Detected new YouTube HTML code layout" )
+                    nonce = true
+                end
+            end
+
             -- JSON parameters, also formerly known as "swfConfig",
             -- "SWF_ARGS", "swfArgs", "PLAYER_CONFIG", "playerConfig" ...
             if string.match( line, "ytplayer%.config" ) then
@@ -421,9 +438,14 @@ function parse()
                 if not path then
                     local stream_map = string.match( line, '\\"formats\\":%[(.-)%]' )
                     if stream_map then
-                        vlc.msg.dbg( "Found new-style parameters for youtube video stream, parsing..." )
                         -- FIXME: do this properly (see #24958)
                         stream_map = string.gsub( stream_map, '\\(["\\/])', '%1' )
+                    else
+                        stream_map = string.match( line, '"formats":%[(.-)%]' )
+                    end
+                    if stream_map then
+                        vlc.msg.dbg( "Found new-style parameters for youtube video stream, parsing..." )
+                        -- FIXME: do this properly (see #24958)
                         stream_map = string.gsub( stream_map, "\\u0026", "&" )
                         path = pick_stream( stream_map, js_url )
                     end
@@ -433,6 +455,7 @@ function parse()
                     -- If this is a live stream, the URL map will be empty
                     -- and we get the URL from this field instead
                     local hlsvp = string.match( line, '\\"hlsManifestUrl\\": *\\"(.-)\\"' )
+                        or string.match( line, '"hlsManifestUrl":"(.-)"' )
                     if hlsvp then
                         hlsvp = string.gsub( hlsvp, "\\/", "/" )
                         path = hlsvp



More information about the vlc-commits mailing list