Created
November 11, 2010 18:05
-
-
Save swdyh/672914 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require 'open-uri' | |
require 'rubygems' | |
require 'nokogiri' | |
# how to use | |
# ruby ust_rec.rb http://www.ustream.tv/channel/alpacas-live | |
# | |
# ref | |
# http://give-me-money.g.hatena.ne.jp/fuba/20100714/1279116473 | |
# http://textt.net/mapi/20101018201937/1 | |
def get_id url | |
h = open(url).read | |
doc = Nokogiri::HTML h | |
t = doc.at('#UstreamExposedVariables').text | |
if m = t.match(/ustream\.vars\.channelId=(\d+);/) | |
m[1] | |
end | |
end | |
def get_rtmp_url uid | |
url_amf = "http://cdngw.ustream.tv/Viewer/getStream/1/#{uid}.amf" | |
amf = open(url_amf).read | |
if m = amf.match(/rtmp:\/\/[\w\/\.]+/) | |
m[0] | |
end | |
end | |
def main | |
if ARGV.size == 0 | |
puts 'input url' | |
exit | |
end | |
u = ARGV[0].gsub(/#.+\Z/, '') | |
channel = u.split('/').last | |
uid = get_id u | |
if uid | |
rtmp = get_rtmp_url uid | |
if rtmp | |
cmd = %(rtmpdump -q -v -r #{rtmp} -a "ustreamVideo/#{uid}" -f "LNX 10,0,45,2" -y "streams/live" -o "#{channel}.flv") | |
puts cmd | |
system cmd | |
else | |
puts 'no rtmp url' | |
end | |
else | |
puts 'no uid' | |
end | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment