class Getvideo::Youtube
Public Instance Methods
cover()
click to toggle source
# File lib/getvideo/youtube.rb, line 22 def cover CGI::unescape(response.scan(/thumbnail_url=([^&]+)/)[0][0]).gsub("default.jpg","")+"0.jpg" end
flash()
click to toggle source
# File lib/getvideo/youtube.rb, line 26 def flash "http://www.youtube.com/v/#{id}" end
html_url()
click to toggle source
# File lib/getvideo/youtube.rb, line 6 def html_url if url =~ /(?:v=|youtu\.be\/)/ url else "http://www.youtube.com/watch?v=" + id end end
id()
click to toggle source
# File lib/getvideo/youtube.rb, line 14 def id if url =~ /(?:v=|youtu\.be\/|youtube\.com\/v\/)([^.|&]+)/ url.scan(/(?:v=|youtu\.be\/|youtube\.com\/v\/)([^.|&]+)/)[0][0] else url end end
m3u8()
click to toggle source
# File lib/getvideo/youtube.rb, line 30 def m3u8 media["mp4"][0] end
media()
click to toggle source
# File lib/getvideo/youtube.rb, line 34 def media stream = CGI::unescape(response.scan(/url_encoded_fmt_stream_map=([^&]+)/)[0][0]) media = stream.scan(/url=([^&]+)/) sig = stream.scan(/sig=([^&]+)/) type = stream.scan(/type=([^&]+)/) vedio_list = {} media.zip(sig, type).each do |m| m_type = m[2][0].match(/(flv|mp4|webm|3gp)/)[0] u = CGI::unescape(m[0][0]) if m[1] u += "&signature=" + m[1][0] end if vedio_list[m_type].nil? vedio_list[m_type] = [] vedio_list[m_type] << u else vedio_list[m_type] << u end end return vedio_list end
title()
click to toggle source
# File lib/getvideo/youtube.rb, line 56 def title CGI::unescape response.scan(/title=([^&]+)/)[0][0] end
Private Instance Methods
connection()
click to toggle source
# File lib/getvideo/youtube.rb, line 62 def connection conn = Faraday.new res = conn.post "http://www.youtube.com/get_video_info", { "video_id" => id } Response.new(res).body end