Created
February 26, 2012 18:03
-
-
Save miminashi/1918026 to your computer and use it in GitHub Desktop.
youtubeのflvのURLひっこぬくRubyスクリプト書いてみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding: utf-8 | |
require 'uri' | |
require 'open-uri' | |
require 'json' | |
require 'pp' | |
#url = 'http://www.youtube.com/watch?v=PwluBRxGAeI&feature=g-vrec&context=G2ab931cRVAAAAAAAAAw' | |
#watch_url = 'http://www.youtube.com/watch_video?v=PwluBRxGAeI' | |
print 'video url: ' | |
url = gets.chop | |
page_body = open(url) | |
json_string = '' | |
page_body.each do |line| | |
if line =~ /yt.playerConfig\ =\ / | |
#puts line | |
json_string = line.gsub(/yt.playerConfig\ =\ /, '').gsub(/;$/, '') | |
end | |
end | |
player_config = JSON.parse(json_string) | |
url_encoded_fmt_stream_map = player_config['args']['url_encoded_fmt_stream_map'] | |
#URI.decode(url_encoded_fmt_stream_map).split('url=') | |
flv_url = URI.decode(url_encoded_fmt_stream_map).gsub(/^url=/, '').split(',url=')[3] | |
flv_uri = URI.parse(flv_url) | |
flv_uri.query = flv_uri.query.split('&')[0..-5].join('&') | |
puts flv_uri.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2012/08/14時点でまだ使えるっぽい