[vlc-commits] youtube.lua: add small URL parameter helper
Pierre Ynard
git at videolan.org
Mon Oct 24 08:19:49 CEST 2016
vlc | branch: master | Pierre Ynard <linkfanel at yahoo.fr> | Mon Oct 24 08:01:08 2016 +0200| [ba8c1401bf09fadcdc63c280c3fdd59f41230f99] | committer: Pierre Ynard
youtube.lua: add small URL parameter helper
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ba8c1401bf09fadcdc63c280c3fdd59f41230f99
---
share/lua/playlist/youtube.lua | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/share/lua/playlist/youtube.lua b/share/lua/playlist/youtube.lua
index 310775f..0bbf97c 100644
--- a/share/lua/playlist/youtube.lua
+++ b/share/lua/playlist/youtube.lua
@@ -24,6 +24,12 @@ function get_url_param( url, name )
return res
end
+-- Helper function to copy a parameter when building a new URL
+function copy_url_param( url, name )
+ local value = get_url_param( url, name )
+ return ( value and "&"..name.."="..value or "" ) -- Ternary operator
+end
+
function get_arturl()
local iurl = get_url_param( vlc.path, "iurl" )
if iurl then
@@ -314,15 +320,10 @@ function parse()
if not path then
local video_id = get_url_param( vlc.path, "v" )
if video_id then
- if fmt then
- format = "&fmt=" .. fmt
- else
- format = ""
- end
-- Without "el=detailpage", /get_video_info fails for many
-- music videos with errors about copyrighted content being
-- "restricted from playback on certain sites"
- path = vlc.access.."://www.youtube.com/get_video_info?video_id="..video_id..format.."&el=detailpage"
+ path = vlc.access.."://www.youtube.com/get_video_info?video_id="..video_id.."&el=detailpage"..copy_url_param( vlc.path, "fmt" )
vlc.msg.warn( "Couldn't extract video URL, falling back to alternate youtube API" )
end
end
@@ -394,12 +395,6 @@ function parse()
vlc.msg.err( "Couldn't extract youtube video URL" )
return { }
end
- fmt = get_url_param( vlc.path, "fmt" )
- if fmt then
- format = "&fmt=" .. fmt
- else
- format = ""
- end
- return { { path = vlc.access.."://www.youtube.com/watch?v="..video_id..format } }
+ return { { path = vlc.access.."://www.youtube.com/watch?v="..video_id..copy_url_param( vlc.path, "fmt" ) } }
end
end
More information about the vlc-commits
mailing list