タグ「radish-play らじるらじる xmllint シェルスクリプト」が付けられているもの

※「らじるらじる」の仕様変更に対応しました!記事末尾の(2022.04/14) 追記したところ。

radio_happy_man.png

寝床のRaspberry Piの話。Windows(親)にfreerdp2(リモートデスクトップ)接続してる。ここで、ラジオを聴こうとしてChromeを立ち上げるとすごく重くなり、radikoを聞くところまで辿り着かない。

そこで、terminal上でradikoを聴くシェルスクリプトを利用していたが、radikoが提供するflashを利用する機構だったので、しばらく前に聞こえなくなってしまっていた。しかし、偉い人が新たなシェルスクリプトを開発してくれた!

今回インストールする環境は

  • raspi-os(buster 32bit desktop)
  • rasberry pi 3

である。

そこでgoogle先生にお伺いを立てると、

github: radish-play.sh

というスクリプトが公開されている。何と素晴らしい!

(追加)
手前味噌ながら、4月のらじるらじる仕様変更に対応してforkしました。

https://github.com/hsoljp/radish-play

githubからzipをDL/解凍するか、

git clone https://github.com/hsoljp/radish-play

として、radish-play.sh を取り寄せる。

chmod 755 radish-play.sh

として実行権限を与えるのをお忘れなく。

raspi-os で必要となるパッケージは以下。

apt-get install curl libxml2-utils jq ffmpeg -y

※readmeには「libxml2を導入」とあるが、raspi-os(=Debian)では、肝心なxmllintがインストールされない。libxml2-utils をインストールすること。curlは手動インストール済だった。作者様はUbuntuとFreeBSDで動作確認したとのことだが、raspi-osでは"libxml2-utils"の選択が必要だと推定。
(追記:2022/04/29)大元の作者様(@ulu_2)のgitにて、「xmllintを使う」とreadmeに追記されてた。

xmllintが入ってないので、NHKのリスト取得のところにexitを入れて、動作を確認したりしている端末の画像。

radish-play.jpg聞き方;
シェルスクリプトが./radish-play/rasdish-play.shとして

./radish-play/radish-play.sh -t {nhk|radiko|...|lisradi} -s {station-id}

たとえば東京NHK-第1
./radish-play/radish-play.sh -t nhk -s tokyo-r1

ステーションidは、

radish-play -l

で取得する。


ということで、無事動きました。

しかしまぁ、リスラジまで聞けるって素晴らしいです!


(追記 2022/04/11)

たぶん、らじるらじるの変更だと想像するのですが、

pi@nedoko:~ $ ./radish-play/radish-play.sh -l|grep tokyo
tokyo-r1: 東京 R1
tokyo-fm: 東京 FM
^C
pi@nedoko:~ $ ./radish-play/radish-play.sh -t nhk -s tokyo-r1
https://nhkradioakr1-i.akamaihd.net/hls/live/511633/1-r1/1-r1-01.m3u8: Server returned 404 Not Found

pi@nedoko:~ $

と、-t nhk -s *** でエラーが出て止まりません。スクリーンショットを以下。

rajiru.png

スクリプトを見てみると、

(想像)
https://www.nhk.or.jp/radio/config/config_v5.7.3_radiru_and.xml

https://www.nhk.or.jp/radio/config/config_web.xml に変更して
さらにxmllint から後の部分を書き換えをすれば、直る予感。

なお、radikoは正常動作するので、

./radish-play/radish-play -t radiko -s JOAK

で、NHK第一東京は聞けます。


さらに追記(2022/04/13,14)

何とか動くようになった。(祝)

xmllint -nocdata というオプションを見つけた。

改変後の シェルスクリプトとライセンス文書:radish-play-20220414.zip
※zip解凍後、ご利用ください。

下記のpatchファイル:radish-play-20220414.patch

美しくないpatchで恥ずかしいのだが、晒します。

--- radish-play.sh.org 2022-04-14 15:16:49.701360975 +0900
+++ radish-play.sh 2022-04-14 15:33:41.622189830 +0900
@@ -41,12 +41,12 @@ _EOT_
show_all_stations() {
# Radiru
echo "Record type: nhk"
- list=$(curl --silent "https://www.nhk.or.jp/radio/config/config_v5.7.3_radiru_and.xml")
- cnt=$(echo "${list}" | xmllint --xpath "count(/radiru_config/area)" - 2> /dev/null)
+ list=$(curl --silent "https://www.nhk.or.jp/radio/config/config_web.xml")
+ cnt=$(echo "${list}" | xmllint --xpath "count(/radiru_config/stream_url/data/area)" - 2> /dev/null)
cntarray=$(echo "${cnt}" | awk '{for (i=1; i<=$1; i++) print i}')
for i in ${cntarray}; do
- echo " $(echo "${list}" | xmllint --xpath "concat(string((/radiru_config/area)[${i}]/@id), '-r1: ', string((/radiru_config/area)[${i}]/@name), ' R1')" - 2> /dev/null)"
- echo " $(echo "${list}" | xmllint --xpath "concat(string((/radiru_config/area)[${i}]/@id), '-fm: ', string((/radiru_config/area)[${i}]/@name), ' FM')" - 2> /dev/null)"
+ echo " $(echo "${list}" | xmllint --xpath "concat(string((/radiru_config/stream_url/data/area)[${i}]), '-r1: ', string((/radiru_config/stream_url/data/areajp)[${i}]), ' R1')" - 2> /dev/null)"
+ echo " $(echo "${list}" | xmllint --xpath "concat(string((/radiru_config/stream_url/data/area)[${i}]), '-fm: ', string((/radiru_config/stream_url/data/area)[${i}]), ' FM')" - 2> /dev/null)"
done
echo " r2: R2"
echo ""
@@ -201,15 +201,14 @@ radiko_authorize() {
#######################################
get_hls_uri_nhk() {
station_id=$1
-
if [ "${station_id}" = "r2" ]; then
# R2
- curl --silent "https://www.nhk.or.jp/radio/config/config_v5.7.3_radiru_and.xml" | xmllint --xpath "string(/radiru_config/config[@key='url_stream_r2']/value[1]/@text)" - 2> /dev/null
+ curl --silent "https://www.nhk.or.jp/radio/config/config_web.xml" | xmllint --nocdata --xpath "/radiru_config/stream_url/data[area='tokyo']/r2hls/text()" - 2> /dev/null
else
# Split area and channel
area="$(echo "${station_id}" | cut -d '-' -f 1)"
channel="$(echo "${station_id}" | cut -d '-' -f 2)"
- curl --silent "https://www.nhk.or.jp/radio/config/config_v5.7.3_radiru_and.xml" | xmllint --xpath "string(/radiru_config/area[@id='${area}']/config[@key='url_stream_${channel}']/value[1]/@text)" - 2> /dev/null
+ curl --silent "https://www.nhk.or.jp/radio/config/config_web.xml" | xmllint --nocdata --xpath "/radiru_config/stream_url/data[area='${area}']/${channel}hls/text()" - 2> /dev/null
fi
}

JCBAは、使えなくなったものと思った方がよさそう。

以上