Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env rvm 1.9.3 do bundle exec ruby
- # -*- coding: utf-8 -*-
- require 'open-uri'
- require 'openssl'
- require 'rexml/document'
- require 'rubygems'
- require 'taglib'
- OP_NO_TLSv1_2 = 0x08000000
- OpenSSL::SSL::SSLContext::DEFAULT_PARAMS[:options] |= OP_NO_TLSv1_2
- def make_path file
- "https://nhk-vh.akamaihd.net/i/gogaku-stream/mp4/#{file}/master.m3u8"
- end
- def listdataxml(lang, course)
- "https://cgi2.nhk.or.jp/gogaku/#{lang}/#{course}/listdataflv.xml"
- end
- def download path, outfile
- system "ffmpeg -i #{path} -absf aac_adtstoasc -acodec copy #{outfile}"
- end
- def proc_xml url
- open(url) do |f|
- doc = REXML::Document.new(f)
- doc.elements.each("musicdata/music") do |e|
- title = e.attributes["title"]
- hdate = e.attributes["hdate"]
- kouza = e.attributes["kouza"]
- code = e.attributes["code"]
- file = e.attributes["file"]
- path = make_path(file)
- outfile = "data/" + file.sub("mp4", "m4a")
- if FileTest.exist?(outfile) && FileTest.size?(outfile) >= 1000000
- puts "Skipped . . . #{outfile}"
- else
- puts "Downloading . . . #{outfile}"
- download path, outfile
- set_title outfile, title, hdate, kouza, code
- end
- end
- end
- end
- def proc_url_list(list)
- list.each do |url|
- proc_xml url
- end
- end
- def language(lang)
- listdataxml(lang, "kouza")
- end
- def levelup(lang)
- listdataxml(lang, "levelup")
- end
- def english(course)
- listdataxml("english", course)
- end
- def set_title file, title, hdate, kouza, code
- TagLib::MP4::File.open(file) do |mp4|
- tag = mp4.tag
- tag.genre = "Education"
- tag.artist = 'NHK'
- tag.album = title
- tag.title = hdate
- tag.year = 2013
- tag.track = code.to_i
- tag.comment = code
- mp4.save
- end
- end
- list = [
- language("german"),
- language("french"),
- language("italian"),
- language("spanish"),
- language("russian"),
- language("chinese"),
- levelup("chinese"),
- language("hangeul"),
- levelup("hangeul"),
- english("business1"),
- english("business2"),
- english("yomu"),
- ]
- # list = [ english("business1") ]
- # list = [ english("yomu") ]
- proc_url_list list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement