#author("2021-10-12T07:15:19+09:00","default:nobuoki","nobuoki")
#author("2021-10-12T07:16:12+09:00","default:nobuoki","nobuoki")
* 最終形 [#b9650620]

ワンライナー
** ワンライナー [#s680516a]

curl -sSL https://www.afnpacific.net/afn-360/ | grep -woE 'AFNP?_[A-Z]+' | while read -r afnID; do (curl -sSL "https://playerservices.streamtheworld.com/api/livestream?transport=http&version=1.8&station=$afnID" | xmllint --xpath "//*[local-name()='mountpoints']" - | xmllint --xpath '//server[last()]/ip/text() | //mount/text()' - &); done | paste - - | awk '{printf "http://%s/%s.%s\n", $1, $2, /AAC$/ ? "aac" : "mp3"}' | sort -t/ -k4,4

出力
** 出力例 [#hbba5b8d]
#pre{{{
http://19793.live.streamtheworld.com/AFNP_DGU.mp3
http://14613.live.streamtheworld.com/AFNP_DGUAAC.aac
http://19213.live.streamtheworld.com/AFNP_IWA.mp3
http://14943.live.streamtheworld.com/AFNP_IWAAAC.aac
http://23603.live.streamtheworld.com/AFNP_KSN.mp3
http://19213.live.streamtheworld.com/AFNP_KSNAAC.aac
http://18393.live.streamtheworld.com/AFNP_MSW.mp3
http://19213.live.streamtheworld.com/AFNP_MSWAAC.aac
http://17853.live.streamtheworld.com/AFNP_OKN.mp3
http://21233.live.streamtheworld.com/AFNP_OKNAAC.aac
http://19793.live.streamtheworld.com/AFNP_OSN.mp3
http://14613.live.streamtheworld.com/AFNP_OSNAAC.aac
http://20853.live.streamtheworld.com/AFNP_SBO.mp3
http://19213.live.streamtheworld.com/AFNP_SBOAAC.aac
http://18393.live.streamtheworld.com/AFNP_TKO.mp3
http://22343.live.streamtheworld.com/AFNP_TKOAAC.aac
http://19793.live.streamtheworld.com/AFN_CTYP.mp3
http://17963.live.streamtheworld.com/AFN_CTYPAAC.aac
http://16813.live.streamtheworld.com/AFN_FAN.mp3
http://24503.live.streamtheworld.com/AFN_FANAAC.aac
http://18393.live.streamtheworld.com/AFN_FREP.mp3
http://18393.live.streamtheworld.com/AFN_FREPAAC.aac
http://14103.live.streamtheworld.com/AFN_GRV.mp3
http://13743.live.streamtheworld.com/AFN_GRVAAC.aac
http://16693.live.streamtheworld.com/AFN_HOTP.mp3
http://15373.live.streamtheworld.com/AFN_HOTPAAC.aac
http://20423.live.streamtheworld.com/AFN_JOEP.mp3
http://22723.live.streamtheworld.com/AFN_JOEPAAC.aac
http://18683.live.streamtheworld.com/AFN_LGYP.mp3
http://18683.live.streamtheworld.com/AFN_LGYPAAC.aac
http://18393.live.streamtheworld.com/AFN_PTK.mp3
http://17343.live.streamtheworld.com/AFN_PTKAAC.aac
http://16603.live.streamtheworld.com/AFN_VCE.mp3
http://14983.live.streamtheworld.com/AFN_VCEAAC.aac
}}}

利用例)AFN東京をaacで再生する
** 利用例 [#se03cd57]

AFN東京(aacで配信)を再生する

  ffplay http://22343.live.streamtheworld.com/AFNP_TKOAAC.aac


* 解説 [#ncce8bc4]

** [[AFN 360 Internet Radio>https://www.afnpacific.net/afn-360/]] からステーションIDを取得 [#e6727b0c]

#prism(bash){{{
curl -sSL https://www.afnpacific.net/afn-360/ | grep -woE 'AFNP?_[A-Z]+' |
}}}

** ステーションID毎に配信サーバ情報(xml)を取得 [#lee1608e]

#prism(bash){{{
while read -r afnID; do 
  curl -sSL "https://playerservices.streamtheworld.com/api/livestream?transport=http&version=1.8&station=$afnID" |
  (xmlパース処理が続く)
...
done |
}}}

** 配信サーバ情報(xml)に含まれるサーバのうち、最後に記載されたサーバとエンコード形式毎のステーションIDを取得 [#g7db4a83]

#prism(bash){{{
while read ...
  xmllint --xpath "//*[local-name()='mountpoints']" - |
  xmllint --xpath '//server[last()]/ip/text() | //mount/text()' - ;
done |
}}}

** 2行を1行に束ね、エンコード形式に合わせてURLを組み立てる [#r9aa3fcd]

#prism(bash){{{
paste - - | awk '{printf "http://%s/%s.%s\n", $1, $2, /AAC$/ ? "aac" : "mp3"}'
}}}

* 高速化 [#qbc5e299]

- curlでのxml取得処理を並列化(バックグラウンド化)するため、while ... done をサブシェル化してバックグラウンドに追いやる
-- 出力順序が乱れるので、URL末尾でソートしておく

大体 30秒 -> 5秒程度に短縮できる

#prism(bash){{{
curl -sSL https://www.afnpacific.net/afn-360/ |
grep -woE 'AFNP?_[A-Z]+'                      |
while read -r afnID; do
  (
    curl -sSL "https://playerservices.streamtheworld.com/api/livestream?transport=http&version=1.8&station=$afnID" |
    xmllint --xpath "//*[local-name()='mountpoints']" -                                                            |
    xmllint --xpath '//server[last()]/ip/text() //mount/text()' -
  &);
done                                                               |
paste - -                                                          |
awk '{printf "http://%s/%s.%s\n", $1, $2, /AAC$/ ? "aac" : "mp3"}' |
sort -t/ -k4,4
}}}

* 参考 [#r0e1a904]

[[Linuxで「AFN」を聞くスクリプト – キクチラヂヲ堂>https://kikuradio.com/pc/linux%e3%81%a7%e3%80%8cafn%e3%80%8d%e3%82%92%e8%81%9e%e3%81%8f%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97%e3%83%88/]]
[[AFN 360の配信URL一覧の取得: ∵なっから∴今日のラヂヲ>http://nakkara.cocolog-nifty.com/nakkara/2021/04/post-1d1379.html]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS