Playing YouTube videos with VLC - mystery error [SOLVED]

For questions and discussion that is NOT (I repeat NOT) specific to a certain Operating System.
psl
New Cone
New Cone
Posts: 3
Joined: 05 Mar 2013 12:17

Re: Playing YouTube videos with VLC - mystery error [SOLVED]

Postby psl » 05 Mar 2013 12:39

Since my account was deleted(?), no posts regarding the youtube.lua survived...
I altered some code of the youtube.lua script recently to make youtube-vids working again so.. I want to share those findings with y'all :mrgreen:

works with any VLC from 1.1.11 and youtube (at least from the Netherlands)

the patch I applied works for me so I hope it works in other countries too
just replace the PARSE FUNCTION in the existing youtube.lua with the altered one to get it working again

Code: Select all

-- Parse function. function parse() if string.match( vlc.path, "/watch%?" ) then -- This is the HTML page's URL -- fmt is the format of the video -- (cf. http://en.wikipedia.org/wiki/YouTube#Quality_and_codecs) fmt = get_url_param( vlc.path, "fmt" ) while true do -- Try to find the video's title line = vlc.readline() if not line then break end if string.match( line, "<meta name=\"title\"" ) then _,_,name = string.find( line, "content=\"(.-)\"" ) name = vlc.strings.resolve_xml_special_chars( name ) name = vlc.strings.resolve_xml_special_chars( name ) end if string.match( line, "<meta name=\"description\"" ) then -- Don't ask me why they double encode ... _,_,description = string.find( line, "content=\"(.-)\"" ) description = vlc.strings.resolve_xml_special_chars( description ) description = vlc.strings.resolve_xml_special_chars( description ) end if string.match( line, "<meta property=\"og:image\"" ) then _,_,arturl = string.find( line, "content=\"(.-)\"" ) end if string.match( line, " rel=\"author\"" ) then _,_,artist = string.find( line, "href=\"/user/([^\"]*)\"" ) end -- JSON parameters, also formerly known as "swfConfig", -- "SWF_ARGS", "swfArgs", "PLAYER_CONFIG" ... if string.match( line, "playerConfig" ) then if not fmt then prefres = get_prefres() if prefres >= 0 then fmt_list = string.match( line, "\"fmt_list\": \"(.-)\"" ) if fmt_list then for itag,height in string.gmatch( fmt_list, "(%d+)\\/%d+x(%d+)\\/[^,]+" ) do -- Apparently formats are listed in quality -- order, so we take the first one that works, -- or fallback to the lowest quality fmt = itag if tonumber(height) <= prefres then break end end end end end url_map = string.match( line, "\"url_encoded_fmt_stream_map\": \"(.-)\"" ) if url_map then -- FIXME: do this properly url_map = string.gsub( url_map, "\\u0026", "&" ) -- for url,itag in string.gmatch( url_map, "url=([^&,]+)[^,]*&itag=(%d+)" ) do for itag,url,sig in string.gmatch( url_map, "itag=(%d+)&url=([^&,]+)[^,]*&sig=([^&,]+)" ) do -- Apparently formats are listed in quality order, -- so we can afford to simply take the first one if not fmt or tonumber( itag ) == tonumber( fmt ) then url = vlc.strings.decode_uri( url ).."&signature="..sig -- PATCHED BY PSL -- url = vlc.strings.decode_uri( url ) path = url break end end end -- There is also another version of the parameters, encoded -- differently, as an HTML attribute of an <object> or <embed> -- tag; but we don't need it now end end -- No path? Try again using YouTube's get_video_info page if not path then video_id = get_url_param( vlc.path, "v" ) local fd, msg = vlc.stream( string.format('http://www.youtube.com/get_video_info?&video_id=%s', video_id) ) if not fd then vlc.msg.warn(msg) else local line = fd:readline() while line ~= nil do -- PATCHED BY PSL for itag,url,sig in string.gmatch( vlc.strings.decode_uri(line), "itag=(%d+)&url=([^&,]+)[^,]*&sig=([^&,]+)" ) do url = vlc.strings.decode_uri( url ).."&signature="..sig path = url break end line = fd:readline() end end end if not path then vlc.msg.err( "Couldn't extract youtube video URL, please check for updates to this script" ) return { } end if not arturl then arturl = get_arturl() end return { { path = path; name = name; description = description; artist = artist; arturl = arturl } } else -- This is the flash player's URL video_id = get_url_param( vlc.path, "video_id" ) if not video_id then _,_,video_id = string.find( vlc.path, "/v/([^?]*)" ) end if not video_id then 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 = "http://www.youtube.com/watch?v="..video_id..format } } end end

johnniecraig
New Cone
New Cone
Posts: 1
Joined: 08 Apr 2013 18:29

Re: Playing YouTube videos with VLC - mystery error [SOLVED]

Postby johnniecraig » 08 Apr 2013 18:40

thanks for sharing the knowledge guys....!!

xyam
New Cone
New Cone
Posts: 2
Joined: 08 Oct 2016 10:48

Re: Playing YouTube videos with VLC - mystery error [SOLVED]

Postby xyam » 08 Oct 2016 11:23

there are many YT videos that don't work

for example:

https://www.youtube.com/watch?v=oFiDcazicdk

https://www.youtube.com/watch?v=ZeKaHBMKows

do you know why?

davebravemave
New Cone
New Cone
Posts: 1
Joined: 28 Jul 2017 11:25

Re: Playing YouTube videos with VLC - mystery error

Postby davebravemave » 28 Jul 2017 11:57

YouTube seems to have changed their page format and broke compatibility with VLC. You'll need to wait until the YouTube script is updated.
It probably wont be ever fixed by youtube, I think they dont want that people download their video contents. Anyway, I'll keep trying.


Return to “General VLC media player Troubleshooting”

Who is online

Users browsing this forum: No registered users and 33 guests