From e510b8ef776ca591d62fb19203e98e19d3d4fcda Mon Sep 17 00:00:00 2001 From: Roman Bazalevskiy Date: Tue, 31 Oct 2017 09:12:59 +0300 Subject: [PATCH 1/1] =?utf8?q?"=D0=A3=D0=BC=D0=BD=D0=B0=D1=8F"=20=D0=B3?= =?utf8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20ID=20=D0=BA?= =?utf8?q?=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?utf8?q?=D0=BE=D0=B1=D0=B5=D1=81=D0=BF=D0=B5=D1=87=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D1=8F=20=D0=BE=D0=B4=D0=BD=D0=BE=D0=B2=D1=80=D0=B5=D0=BC=D0=B5?= =?utf8?q?=D0=BD=D0=BD=D0=BE=D0=B9=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?utf8?q?=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=B8=D1=85?= =?utf8?q?=20=D1=8D=D0=BA=D0=B7=D0=B5=D0=BC=D0=BF=D0=BB=D1=8F=D1=80=D0=BE?= =?utf8?q?=D0=B2=20=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- mqtt-mpd/mqmpd | 5 +-- mqtt-mpd/mqmpdj | 83 ++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/mqtt-mpd/mqmpd b/mqtt-mpd/mqmpd index 5d378ea..595c08d 100755 --- a/mqtt-mpd/mqmpd +++ b/mqtt-mpd/mqmpd @@ -1,5 +1,7 @@ #!/bin/bash +id=`hostname`-$$ + if [ "$1" = "stop" ] then @@ -28,7 +30,7 @@ done # сами остаемся слушать команды -mosquitto_sub -v -h $mqhost -p $mqport -t "$mqcmd/#" -u $mquser -P $mqpassword | while read line +mosquitto_sub -i mqtt-mpd-$id -v -h $mqhost -p $mqport -t "$mqcmd/#" -u $mquser -P $mqpassword | while read line do template="s!$mqcmd/!!" @@ -113,7 +115,6 @@ do esac ;; currentnum) - $mpccmd pause $mpccmd play $arg ;; repeat|random|single|consume) diff --git a/mqtt-mpd/mqmpdj b/mqtt-mpd/mqmpdj index 70603f2..b8c935a 100755 --- a/mqtt-mpd/mqmpdj +++ b/mqtt-mpd/mqmpdj @@ -2,6 +2,8 @@ . /opt/mqtt-mpd/mqmpd.cfg +id=`hostname`-$$ + host=$1 passwd=$2 @@ -18,9 +20,6 @@ fi while : do - $command idle - if [ $? = 0 ] - then # current=`mpc -h $host -P $passwd current | sed 's/"/\"/g'` # volume=`mpc -h $host -P $passwd volume | cut -d: -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'` @@ -41,37 +40,57 @@ do single=${str3[7]} consume=${str3[9]} else - current='-' - status='stopped' - current_track_num='0' - tracks_in_list='0' - current_pos='-' - track_length='-' - str3=( ${array[0]}) - volume=`echo ${str3[1]} | sed 's/%//'` - if [ "$volume" = "n/a" ] + if [ ${#array[@]} = 1 ] then + current='-' + status='stopped' + current_track_num='0' + tracks_in_list='0' + current_pos='-' + track_length='-' + str3=( ${array[0]}) + volume=`echo ${str3[1]} | sed 's/%//'` + if [ "$volume" = "n/a" ] + then + volume="0" + fi + repeat=${str3[3]} + random=${str3[5]} + single=${str3[7]} + consume=${str3[9]} + else + # not responding or error + current='-' + status='failed' + current_track_num='0' + tracks_in_list='0' + current_pos='-' + track_length='-' volume="0" - fi - repeat=${str3[3]} - random=${str3[5]} - single=${str3[7]} - consume=${str3[9]} + repeat="off" + random="off" + single="off" + consume="off" + fi fi + + sleep 0.2 + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/nowplaying -m "$current" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/volume -m "$volume" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/status -m "$status" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/currentnum -m "$current_track_num" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/tracks -m "$tracks_in_list" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/currentpos -m "$current_pos" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/tracklen -m "$track_length" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/repeat -m "$repeat" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/random -m "$random" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/single -m "$single" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/consume -m "$consume" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/nowplaying -m "$current" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/volume -m "$volume" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/status -m "$status" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/currentnum -m "$current_track_num" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/tracks -m "$tracks_in_list" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/currentpos -m "$current_pos" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/tracklen -m "$track_length" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/repeat -m "$repeat" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/random -m "$random" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/single -m "$single" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/consume -m "$consume" -u $mquser -P $mqpassword - - else - sleep 30 - fi + $command idle + if [ $? != 0 ] + then + sleep 60 + fi + done -- 2.34.1