Last active
August 29, 2015 14:03
-
-
Save nagayama/57310b5e36e7695815ff to your computer and use it in GitHub Desktop.
NHK RADIO Grabber
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 'open-uri' | |
require "nokogiri" | |
xmls = [ | |
"https://cgi2.nhk.or.jp/gogaku/st/xml/english/kaiwa/listdataflv.xml", | |
"https://cgi2.nhk.or.jp/gogaku/st/xml/english/timetrial/listdataflv.xml", | |
"https://cgi2.nhk.or.jp/gogaku/st/xml/english/business1/listdataflv.xml", | |
] | |
xmls.each do |xml| | |
doc = Nokogiri::HTML.parse(open(xml)) | |
doc.css("music").each do |music| | |
filename = sprintf("%s.aac", music.attribute("hdate")).encode("UTF-8-MAC", "UTF-8") | |
dirname = sprintf("./%s/", music.attribute("title")).encode("UTF-8-MAC", "UTF-8") | |
url = sprintf "https://nhk-vh.akamaihd.net/i/gogaku-stream/mp4/%s/master.m3u8", music.attribute("file").to_s | |
command = sprintf "ffmpeg -n -vn -i %s -acodec copy '%s/%s'", url, dirname, filename | |
Dir.mkdir dirname unless Dir.exist? dirname | |
system command | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment