Skip to content

Instantly share code, notes, and snippets.

@cielavenir
Last active June 19, 2018 14:24
Show Gist options
  • Save cielavenir/a858255c4009ecbb9b67 to your computer and use it in GitHub Desktop.
Save cielavenir/a858255c4009ecbb9b67 to your computer and use it in GitHub Desktop.
GyaoのURLを表示するやつ yet another。それにしてもrtmpから移行してくれてとても楽になった。
#!/usr/bin/ruby
#coding:utf-8
Encoding.default_external='UTF-8'
FFMPEG='ffmpeg -vcodec copy -acodec copy'
EXT='ts' # ts / flv / mp4
# gyao_url_another by @cielavenir
class String
def resolve(enc="UTF-8") #must be called if you use regexp for Mechanize::Page#body
if RUBY_VERSION >= '1.9' then self.force_encoding(enc) end
return self
end
end
require 'net/https'
ARGV.each{|player_url|
if !(player_url=~/gyao.yahoo.co.jp\/player\/(\d+)\/(v\d+)\/(v\d+)/)
puts 'URL wrong: '+player_url
next
end
arg=[$1,$2,$3]
title=''
Net::HTTP.start('gyao.yahoo.co.jp'){|http|
resp=http.get('/player/'+arg*'/'+'/')
resp.body=~/<title>(.*?)<\/title>/
title=$1.resolve.split('|')[0]
}
https=Net::HTTP.new('gw.gyao.yahoo.co.jp',443)
https.use_ssl=true
https.start{
resp=https.get('/v1/hls/'+arg*':'+'/variant.m3u8?device_type=1100&delivery_type=2&min_bandwidth=253&appkey=52hd8q-XnozawaXc727tmojaFD.SD1yc&appid=ff_rbJCxg67.bRk_lk7CbWFjhorGVKjvFsRgiLDHW4PE.vN6zxDW6KyRr1Zw3rI-')
lines=resp.body.split("\n")
i=0
while i<lines.size
if lines[i]=~/BANDWIDTH=(\d+)/
puts 'bandwidth='+$1+':'
i+=1
if i<lines.size
puts FFMPEG+(EXT=='ts' ? '' : ' -bsf:a aac_adtstoasc')+' "'+title+'.'+EXT+'" -i "'+'https://gw.gyao.yahoo.co.jp'+lines[i]+'"'
end
end
i+=1
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment