{"id":158,"date":"2020-11-20T10:03:41","date_gmt":"2020-11-20T01:03:41","guid":{"rendered":"http:\/\/charon.s1005.xrea.com\/?p=158"},"modified":"2020-11-20T10:03:41","modified_gmt":"2020-11-20T01:03:41","slug":"raspberry-pi%e3%81%a7nhk%e3%83%a9%e3%82%b8%e3%82%aa%e3%82%92%e8%87%aa%e5%8b%95%e9%8c%b2%e9%9f%b3%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/linux-walker.net\/?p=158","title":{"rendered":"Raspberry Pi\u3067NHK\u30e9\u30b8\u30aa\u3092\u81ea\u52d5\u9332\u97f3\u3059\u308b"},"content":{"rendered":"\n<p>\u3053\u308c\u306f\u3068\u3063\u304f\u306b\u3053\u3053\u306b\u30dd\u30b9\u30c8\u3057\u3066\u3044\u305f\u6c17\u304c\u3059\u308b\u3051\u3069\u3001\u5b9f\u306f\u307e\u3060\u3060\u3063\u305f\u306e\u3067\u3059\u306d\u3002<br>\u3053\u3053\u306b\u6765\u308b\u307e\u3067\u3051\u3063\u3053\u3046\u82e6\u52b4\u3057\u305f\u306e\u3067\u8f09\u305b\u3066\u304a\u304d\u307e\u3059\u3002<br><br>\u57fa\u672c\u7684\u306b\u306friocampos\u3055\u3093\u306e<a href=\"https:\/\/gist.github.com\/riocampos\/93739197ab7c765d16004cd4164dca73\" data-type=\"URL\" data-id=\"https:\/\/gist.github.com\/riocampos\/93739197ab7c765d16004cd4164dca73\">\u3053\u306e\u30da\u30fc\u30b8<\/a>\u3092\u53c2\u8003\u306b\u3057\u307e\u3057\u305f\u3002\u9055\u3044\u306f <a href=\"http:\/\/www.nhk.or.jp\/radio\/config\/config_web.xml\">http:\/\/www.nhk.or.jp\/radio\/config\/config_web.xml<\/a> \u3092\u6bce\u56de\u53c2\u7167\u3057\u3066\u3001akamaihd.net \u306eURL\u304c\u5909\u66f4\u3055\u308c\u3066\u3044\u3066\u3082\u5bfe\u5fdc\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3067\u306fRuby\u30b9\u30af\u30ea\u30d7\u30c8\u3002\u8aad\u3081\u3070\u308f\u304b\u308b\u306e\u3067\u8aac\u660e\u306f\u7565\u3002<\/p>\n\n\n\n<p class=\"has-vivid-green-cyan-color has-text-color\">#!\/usr\/bin\/env ruby<br># Usage: record_nhk.rb [options] area station duration outdir<br><br>require &#8216;optparse&#8217;<br>require &#8220;rexml\/document&#8221;<br>require &#8220;open-uri&#8221;<br><br>URL = &#8220;http:\/\/www.nhk.or.jp\/radio\/config\/config_web.xml&#8221;<br><br># MYAREA is one of the followings<br># sapporo \u00a0<br># sendai \u00a0<br># tokyo \u00a0<br># nagoya \u00a0<br># osaka \u00a0<br># hiroshima \u00a0<br># matsuyama \u00a0<br># fukuoka \u00a0<br><br>params = ARGV.getopts(nil, &#8216;title:&#8217;, &#8216;artist:&#8217;, &#8216;album:&#8217;)<br><br>myarea = ARGV[0]<br>station = ARGV[1]<br>duration = ARGV[2]<br>outdir = ARGV[3]<br><br>xml = open(URL).read<br>doc = REXML::Document.new(xml)<br><br>radiru_config = \u00a0nil<br>doc.each do |e|<br>\u00a0if e.kind_of?(REXML::Element) and e.name == &#8220;radiru_config&#8221;<br>\u00a0\u00a0\u00a0radiru_config = e<br>\u00a0\u00a0\u00a0break<br>\u00a0end<br>end<br><br>stream_url= radiru_config.elements[&#8216;stream_url&#8217;]<br><br>area = nil<br>stream_url.each do |data|<br>\u00a0if data.kind_of?(REXML::Element)<br>\u00a0\u00a0\u00a0if data.elements[&#8216;area&#8217;].text == myarea<br>\u00a0\u00a0\u00a0\u00a0\u00a0area = data<br>\u00a0\u00a0\u00a0\u00a0\u00a0break<br>\u00a0\u00a0\u00a0end<br>\u00a0end<br>end<br><br>case station<br>when &#8216;r1&#8217;<br>\u00a0surl = area.elements[&#8216;r1hls&#8217;].text<br>when &#8216;r2&#8217;<br>\u00a0surl = area.elements[&#8216;r2hls&#8217;].text<br>when &#8216;fm&#8217;<br>\u00a0surl = area.elements[&#8216;fmhls&#8217;].text<br>else<br>\u00a0surl = area.elements[&#8216;fmhls&#8217;].text<br>end<br><br>now = Time.now.to_s.sub(\/(\\d\\d\\d\\d-\\d\\d-\\d\\d)\\s+(\\d\\d:\\d\\d):\\d\\d.*$\/){ $1 + &#8216;_&#8217; + $2.sub(\/<br>:\/, &#8216;-&#8216;) }<br><br>meta = &#8220;&#8221;<br><br>if params[&#8216;title&#8217;]<br>\u00a0meta += &#8221; -metadata title=\\&#8221;&#8221; + params[&#8216;title&#8217;] + &#8220;\\&#8221;&#8221;<br>end<br><br>if params[&#8216;artist&#8217;]<br>\u00a0meta += &#8221; -metadata artist=\\&#8221;&#8221; + params[&#8216;artist&#8217;] + &#8220;\\&#8221;&#8221;<br>end<br><br>if params[&#8216;album&#8217;]<br>\u00a0meta += &#8221; -metadata album=\\&#8221;&#8221; + params[&#8216;album&#8217;] + &#8220;\\&#8221;&#8221;<br>end<br><br>ffmpeg_cmd = sprintf(&#8220;ffmpeg -t %s -i %s %s -write_xing 0 %s\/%s.mp3&#8221;, duration, surl, meta<br>, outdir, now)<br><br>system(ffmpeg_cmd)<\/p>\n\n\n\n<p>\u4f7f\u3044\u304b\u305f\u306fcron\u3067\u3053\u3093\u306a\u611f\u3058\u3067\u3059\u3002\u8da3\u5473\u304c\u308f\u304b\u3063\u3066\u3057\u307e\u3046&#8230;<br>sleep 30\u306f\u9045\u5ef6\u3092\u8003\u616e\u3057\u3066\u3067\u3059\u304c\u3001\u3082\u3063\u3068\u591a\u3044\u307b\u3046\u304c\u3044\u3044\u304b\u3082\u3002<\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color\">05 16 * * 0 \u00a0\u00a0\u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;DJ\u65e5\u672c\u53f2&#8221; &#8211;album &#8220;\u30c8\u30fc\u30af&#8221; tokyo r1 00:50:00 \/disk\/Music\/Radio\/NHK-R1\/DJ \u00a0<br>30 19 * * 1-5 \u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;\u30d9\u30b9\u30c8\u30fb\u30aa\u30d6\u30fb\u30af\u30e9\u30b7\u30c3\u30af&#8221; &#8211;album &#8220;\u30af\u30e9\u30b7\u30c3\u30af&#8221; tokyo fm 01:40:00 \/disk\/Music\/Radio\/NHK-FM\/Classic<br>15 21 * * 1-5 \u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;\u9752\u6625\u30a2\u30c9\u30d9\u30f3\u30c1\u30e3\u30fc&#8221; &#8211;album &#8220;\u30e9\u30b8\u30aa\u30c9\u30e9\u30de&#8221; tokyo fm 00:15:00 \/disk\/Music\/Radio\/NHK-FM\/Adventure<br>00 22 * * 6 \u00a0\u00a0\u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;FM\u30b7\u30a2\u30bf\u30fc&#8221; &#8211;album &#8220;\u30e9\u30b8\u30aa\u30c9\u30e9\u30de&#8221; tokyo fm 01:00:00 \/disk\/Music\/Radio\/NHK-FM\/Theatre<br>05 10 * * 6 \u00a0\u00a0\u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;\u771f\u6253\u3061\u7af6\u6f14&#8221; &#8211;album &#8220;\u843d\u8a9e&#8221; tokyo r1 00:50:00 \/disk\/Music\/Radio\/NHK-R1\/Sin-uti<br>20 19 * * 0 \u00a0\u00a0\u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;\u65b0\u65e5\u66dc\u540d\u4f5c\u5ea7&#8221; &#8211;album &#8220;\u30e9\u30b8\u30aa\u30c9\u30e9\u30de&#8221; tokyo r1 00:30:00 \/disk\/Music\/Radio\/NHK-R1\/Meisaku<br>30 10 * * 1-3 \u00a0\u00a0sleep 30;\/home\/pi\/NHK\/record_nhk.rb &#8211;artist &#8220;\u9060\u5c71\u9855\u306e\u82f1\u4f1a\u8a71\u697d\u7fd2&#8221; &#8211;album &#8220;\u82f1\u8a9e&#8221; tokyo r2 00:15:00 \/disk\/Music\/Radio\/NHK-R2\/Rakushuu<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u308c\u306f\u3068\u3063\u304f\u306b\u3053\u3053\u306b\u30dd\u30b9\u30c8\u3057\u3066\u3044\u305f\u6c17\u304c\u3059\u308b\u3051\u3069\u3001\u5b9f\u306f\u307e\u3060\u3060\u3063\u305f\u306e\u3067\u3059\u306d\u3002\u3053\u3053\u306b\u6765\u308b\u307e\u3067\u3051\u3063\u3053\u3046\u82e6\u52b4\u3057\u305f\u306e\u3067\u8f09\u305b\u3066\u304a\u304d\u307e\u3059\u3002 \u57fa\u672c\u7684\u306b\u306friocampos\u3055\u3093\u306e\u3053\u306e\u30da\u30fc\u30b8\u3092\u53c2\u8003\u306b\u3057\u307e\u3057\u305f\u3002\u9055\u3044\u306f http:\/\/www.nh&hellip; <a class=\"more-link\" href=\"https:\/\/linux-walker.net\/?p=158\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Raspberry Pi\u3067NHK\u30e9\u30b8\u30aa\u3092\u81ea\u52d5\u9332\u97f3\u3059\u308b<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,10],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-raspberry-pi","category-10","entry"],"_links":{"self":[{"href":"https:\/\/linux-walker.net\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linux-walker.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux-walker.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux-walker.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linux-walker.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":1,"href":"https:\/\/linux-walker.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/linux-walker.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/linux-walker.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux-walker.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux-walker.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}