sh/ネタ/AFN配信URL

最終形

ワンライナー

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

出力例

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で配信)を再生する

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

解説

AFN 360 Internet Radio からステーションIDを取得

curl -sSL https://www.afnpacific.net/afn-360/ | grep -woE 'AFNP?_[A-Z]+' |

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

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

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

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

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

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

高速化

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

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

参考

Linuxで「AFN」を聞くスクリプト – キクチラヂヲ堂
AFN 360の配信URL一覧の取得: ∵なっから∴今日のラヂヲ


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-10-12 (火) 07:17:08