[vlc-commits] youtube.lua: fix description parsing

Pierre Ynard git at videolan.org
Mon Jul 20 12:37:50 CEST 2020


vlc/vlc-3.0 | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Mon Jul 20 12:21:23 2020 +0200| [51712cbd31d73322b96c03e0d75424276c276acb] | committer: Pierre Ynard

youtube.lua: fix description parsing

(cherry picked from commit 6b1385f1332ce3457045e4d669ec57996be57c5a)
Signed-off-by: Pierre Ynard <linkfanel at yahoo.fr>

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

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

diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index 97515238ed..29e8bf8d56 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -325,9 +325,16 @@ function parse()
             end
 
             if not description then
-                description = string.match( line, "<p id=\"eow%-description\"[^>]*>(.-)</p>" )
+                -- FIXME: there is another version of this available,
+                -- without the double JSON string encoding, but we're
+                -- unlikely to access it due to #24957
+                description = string.match( line, '\\"shortDescription\\":\\"(.-[^\\])\\"')
                 if description then
-                    description = vlc.strings.resolve_xml_special_chars( description )
+                    -- FIXME: do this properly
+                    description = string.gsub( description, '\\(["\\/])', '%1' )
+                    description = string.gsub( description, '\\(["\\/])', '%1' )
+                    description = string.gsub( description, '\\n', '\n' )
+                    description = string.gsub( description, "\\u0026", "&" )
                 end
             end
 
@@ -478,6 +485,16 @@ function parse()
             -- FIXME: do this properly
             title = string.gsub( title, "\\u0026", "&" )
         end
+        -- FIXME: description gets truncated if it contains a double quote
+        local description = string.match( line, "%%22shortDescription%%22%%3A%%22(.-)%%22" )
+        if description then
+            description = string.gsub( description, "+", " " )
+            description = vlc.strings.decode_uri( description )
+            -- FIXME: do this properly
+            description = string.gsub( description, '\\(["\\/])', '%1' )
+            description = string.gsub( description, '\\n', '\n' )
+            description = string.gsub( description, "\\u0026", "&" )
+        end
         local artist = string.match( line, "%%22author%%22%%3A%%22(.-)%%22" )
         if artist then
             artist = string.gsub( artist, "+", " " )
@@ -490,7 +507,7 @@ function parse()
             arturl = vlc.strings.decode_uri( arturl )
         end
 
-        return { { path = path, title = title, artist = artist, arturl = arturl } }
+        return { { path = path, title = title, description = description, artist = artist, arturl = arturl } }
 
     else -- Other supported URL formats
         local video_id = string.match( vlc.path, "/[^/]+/([^?]*)" )



More information about the vlc-commits mailing list