Created
August 10, 2018 08:03
-
-
Save Matthew238/ce8a8bb242607311ac63b7ff8d503eae to your computer and use it in GitHub Desktop.
某ストリーミングを保存するスクリプト2016年大会版
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
#!/usr/bin/env ruby | |
require 'fileutils' | |
require 'net/http' | |
require 'json' | |
block = { | |
1 => ['北海道', 'ik'], 2 => ['東北', 'hk'], 3 => ['関東甲信越', 'ak'], | |
4 => ['東海北陸', 'ck'], 5 => ['近畿', 'bk'], 6 => ['中国', 'fk'], | |
7 => ['四国', 'zk'], 8 => ['九州沖縄', 'lk'], 99 => ['全国', 'jk'] | |
} | |
title_url_base = "http://www.***.or.jp/.......-live/live/data2016/" | |
movie_url_base = "https://***-vh.akamaihd.net/i/.......-live/2016live/" | |
block.each do |k,v| | |
path = "./movies/#{v[0]}" | |
FileUtils.mkdir_p(path) unless FileTest.exist?(path) | |
url = title_url_base + "#{v[1]}_1.js" | |
res = Net::HTTP.get(URI.parse(url)) | |
json = JSON.parse(res.gsub(/\Acallback\(/, "").gsub(/\)\Z/, "")) | |
json.dig("clip").each do |clip| | |
title = clip.dig("box", 0, "title") rescue nil | |
clip_id = clip.dig("box", 0, "clip_id") rescue nil | |
if title and clip_id then | |
command = "ffmpeg -i #{movie_url_base}#{clip_id.split('_')[0]}_0_,1,2,_" | |
command << "#{clip_id.split('_')[3]}.mp4.csmil/master.m3u8 " | |
command << "-movflags faststart -c copy -bsf:a aac_adtstoasc " | |
command << "#{path}/\"#{title}\".mp4" | |
result = `#{command}` | |
print result | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment