Created
December 2, 2015 17:59
-
-
Save tondol/00d4f0ebadcd3aa8e8d3 to your computer and use it in GitHub Desktop.
GyaoのチャンネルURLからいい感じのコマンドを出力する
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 'net/https' | |
require 'pp' | |
# https://gist.github.com/cielavenir/a858255c4009ecbb9b67 | |
@channel_urls = ARGV | |
@player_urls = [] | |
@channel_urls.each {|channel_url| | |
unless channel_url =~ %r!gyao.yahoo.co.jp/p/(\d+)/(v\d+)/! | |
next | |
end | |
args = [$1, $2] | |
title = nil | |
player_urls = [] | |
Net::HTTP.start('gyao.yahoo.co.jp') {|http| | |
response = http.get('/p/' + args.join('/') + '/') | |
response.body =~ %r!<title>(.*?)</title>! | |
title = $1.force_encoding('utf-8').split('|')[0] | |
player_urls = response.body.scan(%r!/player/\d+/v\d+/v\d+/!) | |
} | |
@player_urls += player_urls.select {|player_url| | |
player_url.include?(args[0]) && player_url.include?(args[1]) | |
}.uniq | |
} | |
@player_urls.each {|player_url| | |
unless player_url =~ %r!/player/(\d+)/(v\d+)/(v\d+)/! | |
next | |
end | |
args = [$1, $2, $3] | |
https = Net::HTTP.new('gw.gyao.yahoo.co.jp', 443) | |
https.use_ssl = true | |
https.start { | |
response = https.get('/v1/hls/' + args.join(':') + '/variant.m3u8?' + | |
'device_type=1100&delivery_type=2&appkey=52hd8q-XnozawaXc727tmojaFD.SD1yc&' + | |
'appid=ff_rbJCxg67.bRk_lk7CbWFjhorGVKjvFsRgiLDHW4PE.vN6zxDW6KyRr1Zw3rI-') | |
lines = response.body.force_encoding('utf-8').split("\n") | |
urls = [] | |
(0 ... lines.size).to_a.each_cons(2) {|k1, k2| | |
if lines[k1] =~ /BANDWIDTH=(\d+)/ | |
urls << [$1.to_i, 'https://gw.gyao.yahoo.co.jp' + lines[k2]] | |
end | |
} | |
url = urls.sort {|v1, v2| v2[0] <=> v1[0] }[0][1] | |
puts "ffmpeg -bsf:a aac_adtstoasc -acodec copy -vcodec copy #{args[0]}_#{args[1]}_#{args[2]}.mp4 -i #{url}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment