From ba8c1401bf09fadcdc63c280c3fdd59f41230f99 Mon Sep 17 00:00:00 2001 From: Pierre Ynard Date: Mon, 24 Oct 2016 08:01:08 +0200 Subject: [PATCH] youtube.lua: add small URL parameter helper --- 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 310775f16f01..0bbf97c46931 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