Skip to content

Instantly share code, notes, and snippets.

@nagayama
Last active August 29, 2015 14:03
Show Gist options
  • Save nagayama/57310b5e36e7695815ff to your computer and use it in GitHub Desktop.
Save nagayama/57310b5e36e7695815ff to your computer and use it in GitHub Desktop.
NHK RADIO Grabber
#!/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