村上や

“TOP”へMC900432676[1]

ニュース

 

2019831

 

Raspberry Pi Zero WH」で作るインターネットラジオです。

 

 

radikoのアプリを「mplayer」から「vlc」に変更しました。

支障はなかったのですが、mplayer」だとNHKが音飛びするので、vlc」で再生していました。

vlc」に統一しただけです。

 

ラジオを持ち運ぶ場合、電源プラグを抜く必要があります。

そのため、スマホから「Raspberry Pi Zero WH」をシャットダウンできるようにしました。

ただ、「Raspberry Pi Zero WH」をシャットダウンすると、GPIOピンがLowになり、アンプがActiveになります。

Raspberry Pi Zero WH」をシャットダウンして、電源プラグを抜くので、支障はありません。

 

スマホのイメージ画面です。

 

備忘録です。

radikoPHPファイル(/var/www/html/play_radiko.sh)です。(属性:755

#!/bin/bash

 

#LANG=ja_JP.utf8

 

pid=$$

date=`date '+%Y-%m-%d-%H_%M'`

playerurl=http://radiko.jp/apps/js/flash/myplayer-release.swf

playerfile="/tmp/player.swf"

keyfile="/tmp/authkey.png"

 

outdir="."

 

 

if [ $# -le 0 ]; then

  echo "usage : $0 channel_name duration(minuites) [outputdir] [prefix]"

  exit 1

fi

 

if [ $# -ge 1 ]; then

  channel=$1

fi

 

if [ $# -ge 2 ]; then

  channel=$1

  DURATION=`expr $2 \* 60`

fi

if [ $# -ge 3 ]; then

  outdir=$3

fi

PREFIX=${channel}

if [ $# -ge 4 ]; then

  PREFIX=$4

fi

 

#

# get player

#

if [ ! -f $playerfile ]; then

  wget -q -O $playerfile $playerurl

 

  if [ $? -ne 0 ]; then

    echo "failed get player"

    exit 1

  fi

fi

 

#

# access auth1_fms

#

auth1_fms=`wget -q \

     --header="pragma: no-cache" \

     --header="X-Radiko-App: pc_ts" \

     --header="X-Radiko-App-Version: 4.0.0" \

     --header="X-Radiko-User: test-stream" \

     --header="X-Radiko-Device: pc" \

     --post-data='\r\n' \

     --no-check-certificate \

     --save-headers \

     https://radiko.jp/v2/api/auth1_fms \

     -O -`

if [ $? -ne 0 -o ! "${auth1_fms}" ]; then

    echo "failed auth1 process" 1>&2

    exit 1

fi

 

#

# get partial key

#

authtoken=`echo ${auth1_fms} | perl -ne 'print $1 if(/x-radiko-authtoken: ([\w-]+)/i)'`

offset=`echo ${auth1_fms} | perl -ne 'print $1 if(/x-radiko-keyoffset: (\d+)/i)'`

length=`echo ${auth1_fms} | perl -ne 'print $1 if(/x-radiko-keylength: (\d+)/i)'`

 

partialkey=`wget -q -O - ${playerurl} 2>/dev/null | \

            swfextract -b 12 /dev/stdin -o /dev/stdout | \

            dd bs=1 skip=${offset} count=${length} 2> /dev/null | \

            base64`

 

if [ $? -ne 0 -o ! "${partialkey}" ]; then

    echo "failed auth1 process" 1>&2

    exit 1

fi

 

#

# access auth2_fms

#

auth2_fms=`wget -q \

     --header="pragma: no-cache" \

     --header="X-Radiko-App: pc_ts" \

     --header="X-Radiko-App-Version: 4.0.0" \

     --header="X-Radiko-User: test-stream" \

     --header="X-Radiko-Device: pc" \

     --header="X-Radiko-Authtoken: ${authtoken}" \

     --header="X-Radiko-Partialkey: ${partialkey}" \

     --post-data='\r\n' \

     --no-check-certificate \

     https://radiko.jp/v2/api/auth2_fms \

     -O -`

 

if [ $? -ne 0 -o ! "${auth2_fms}" ]; then

  echo "failed auth2 process" 1>&2

  exit 1

fi

 

echo "authentication success"

 

areaid=`echo ${auth2_fms} | perl -ne 'print $1 if(/^([^,]+),/i)'`

echo "areaid: $areaid"

 

rm -f auth2_fms_${pid}

 

echo "${playerurl}" "${authtoken}"

 

#

# get stream-url

#

 

if [ -f ${channel}.xml ]; then

  rm -f ${channel}.xml

fi

 

wget -q "http://radiko.jp/v2/station/stream/${channel}.xml"

 

stream_url=`echo "cat /url/item[1]/text()" | xmllint --shell ${channel}.xml | tail -2 | head -1`

url_parts=(`echo ${stream_url} | perl -pe 's!^(.*)://(.*?)/(.*)/(.*?)$/!$1://$2 $3 $4!'`)

 

rm -f ${channel}.xml

 

#ffmpeg -loglevel quiet -y -i "/tmp/${channel}_${date}" -acodec libmp3lame -ab 128k "${outdir}/${PREFIX}_${date}.mp3"

 

echo ${url_parts[0]}

echo ${url_parts[1]}

echo ${url_parts[2]}

echo $playerurl

echo $authtoken

 

 

rtmpdump -v \

              -r ${url_parts[0]} \

              --app ${url_parts[1]} \

              --playpath ${url_parts[2]} \

              -W $playerurl \

              -C S:"" -C S:"" -C S:"" -C S:$authtoken \

              --live | cvlc -

 

if [ $? = 0 ]; then

  rm -f "/tmp/${channel}_${date}"

fi

 

/var/www/html/play_radiko2.shでアップロードし、改行コードを変換します。

# tr -d '\r' < /var/www/html/play_radiko2.sh > /var/www/html/play_radiko.sh

 

play_radiko2.shは不要なので、FTPで削除します。

 

/var/www/html/play_radiko.shの属性を755にします。

# chmod 755 /var/www/html/play_radiko.sh

 

↓福岡県の放送局コードです。

放送局名

放送局ID

RKBラジオ

RKB

KBCラジオ

KBC

FM FUKUOKA

FMFUKUOKA

LOVE FM

LOVEFM

CROSS FM

CROSSFM

ラジオNIKKEI1

RN1

ラジオNIKKEI2

RN2

放送大学

HOUSOU-DAIGAKU

 

php から sudo コマンドを実行できるようにする

# nano /etc/sudoers

/etc/sudoers の末尾に以下を追記

www-data ALL=(ALL) NOPASSWD: /sbin/shutdown

 

↓シャットダウンのPHPファイル(/var/www/html/ shutdown .php)です。(属性:755

<?php

exec("killall vlc");

exec("gpio -g mode 3 out");

exec("gpio -g write 3 1");

exec("gpio -g mode 15 out");

exec("gpio -g write 15 1");

exec("sudo shutdown -h now");

?>

 

↓メインのPHPファイル(/var/www/html/index.php)です。(属性:755

<?php

if(isset($_GET['stop'])) {

exec("killall vlc");

exec("gpio -g mode 3 out");

exec("gpio -g write 3 0");

exec("gpio -g mode 15 out");

exec("gpio -g write 15 1");

}

 

if(isset($_GET['vol'])) {

$vol = $_GET['vol'];

exec("amixer sset PCM " .$vol. "%");

}

 

if(isset($_GET['music'])) {

$music = $_GET['music'];

exec("killall vlc");

exec("cvlc -Z -L /var/www/html/music/" .$music. "/*.mp3 > /dev/null &");exec("gpio -g mode 3 out");

exec("gpio -g write 3 1");

exec("gpio -g mode 15 out");

exec("gpio -g write 15 0");

}

 

if(isset($_GET['url'])) {

$url = $_GET['url'];

exec("killall vlc");

exec("cvlc " .$url. " > /dev/null &");

exec("gpio -g mode 3 out");

exec("gpio -g write 3 1");

exec("gpio -g mode 15 out");

exec("gpio -g write 15 0");

}

 

if(isset($_GET['radiko'])) {

$radiko = $_GET['radiko'];

exec("killall vlc");

system("/var/www/html/play_radiko.sh " .$radiko. " > /dev/null &");

exec("gpio -g mode 3 out");

exec("gpio -g write 3 1");

exec("gpio -g mode 15 out");

exec("gpio -g write 15 0");

}

 

?>

 

<html>

<head>

<meta name="viewport" charset="utf-8" content="width=device-width">

<title>Raspberry Pi</title>

<link rel="shortcut icon" href="favicon.ico">

 

<script type="text/javascript">

function disp(){

              if(window.confirm('必ず電源プラグを抜いてください')){

                            location.href = "shutdown.php";

              }

}

</script>

 

</head>

<body>

<Div Align="right">

<a href="#" onClick="disp(); return false;">Shutdown</a>

</Div>

<a href="index.php?stop=stop">Stop</a><br>

<br>

Volum

(Min)

<a href="index.php?vol=0">0</a>

<a href="index.php?vol=60">1</a>

<a href="index.php?vol=70">2</a>

<a href="index.php?vol=80">3</a>

<a href="index.php?vol=85">4</a>

<a href="index.php?vol=90">5</a>

<a href="index.php?vol=92">6</a>

<a href="index.php?vol=94">7</a>

<a href="index.php?vol=96">8</a>

<a href="index.php?vol=98">9</a>

<a href="index.php?vol=100">10</a>

(Max)

<br>

<br>

Radio

<br>

&nbsp;<a href="index.php?url=https://nhkradiolkr1-i.akamaihd.net/hls/live/512088/1-r1/1-r1-01.m3u8">NHK R1</a><br>

&nbsp;<a href="index.php?url=https://nhkradioakr2-i.akamaihd.net/hls/live/511929/1-r2/1-r2-01.m3u8">NHK R2</a><br>

&nbsp;<a href="index.php?url=https://nhkradiolkfm-i.akamaihd.net/hls/live/512097/1-fm/1-fm-01.m3u8">NHK FM</a><br>

 

&nbsp;<a href="index.php?radiko=RKB">RKB</a><br>

&nbsp;<a href="index.php?radiko=KBC">KBC</a><br>

&nbsp;<a href="index.php?radiko=FMFUKUOKA">FM FUKUOKA</a><br>

&nbsp;<a href="index.php?radiko=LOVEFM">Love FM</a><br>

&nbsp;<a href="index.php?radiko=CROSSFM">CROSS FM</a><br>

&nbsp;<a href="index.php?radiko=RN1">ラジオNIKKEI1</a><br>

&nbsp;<a href="index.php?radiko=RN2">ラジオNIKKEI2</a><br>

&nbsp;<a href="index.php?radiko=HOUSOU-DAIGAKU">放送大学</a><br>

 

&nbsp;<a href="index.php?url=http://ottava.out.airtime.pro:8000/ottava_b">OTTAVA</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1782029">Cool Jazz New York</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1794791">Cool Jazz FLA</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1605192">Cool Jazz Global</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1586446">J-Pop Sakura 17</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1656313">J-Pop - PowerPlay</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1659345">Asia DREAM Radio - Japan Hits</a><br>

&nbsp;<a href="index.php?url=http://yp.shoutcast.com/sbin/tunein-station.pls?id=1659314">J-Pop - PowerPlay Kawaii</a><br>

 

<br>

Music

<br>

&nbsp;<a href="index.php?music=joehisaishi">久石譲</a><br>

&nbsp;<a href="index.php?music=Paul_Mauriat">ポール・モーリア</a><br>

&nbsp;<a href="index.php?music=Shakatak">シャカタク</a><br>

&nbsp;<a href="index.php?music=12_Girls_Band">女子十二楽坊</a><br>

&nbsp;<a href="index.php?music=Yo-Yo_Ma">ヨーヨー・マ</a><br>

<br>

 

</body>

</html>

 

 

 

【バックナンバー】

MC900053825[1] 2019825

MC900053825[1] 2019817

MC900053825[1] 2019813

MC900053825[1] 2019812

MC900053825[1] 201984

MC900053825[1] 2019728

MC900053825[1] 2019721

MC900053825[1] 2019715

MC900053825[1] 201977

MC900053825[1] 2019630

MC900053825[1] 2019623

MC900053825[1] 2019616

MC900053825[1] 201969

MC900053825[1] 201962

MC900053825[1] 2019526

MC900053825[1] 2019512

MC900053825[1] 201956

MC900053825[1] 201953

MC900053825[1] 2019430

MC900053825[1] 2019421

MC900053825[1] 2019414

MC900053825[1] 201947

MC900053825[1] 2019330

MC900053825[1] 2019323

MC900053825[1] 2019321

MC900053825[1] 2019317

MC900053825[1] 201939

MC900053825[1] 201933

MC900053825[1] 2019224

MC900053825[1] 2019217

MC900053825[1] 2019211

MC900053825[1] 201923

MC900053825[1] 2019127

MC900053825[1] 2019120

MC900053825[1] 2019114

MC900053825[1] 201916

MC900053825[1] 201913

MC900053825[1] 2019年1月1

MC900053825[1] 2018

MC900053825[1] 2017

MC900053825[1] 2016

MC900053825[1] 2015

MC900053825[1] 2014

MC900053825[1] 2013

MC900053825[1] 2012

MC900053825[1] 2011