Skip to content

Commit

Permalink
Merge pull request #1491 from rern/UPDATE
Browse files Browse the repository at this point in the history
u
  • Loading branch information
rern authored Nov 11, 2023
2 parents 8511c23 + d3a0646 commit dd47673
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 81 deletions.
10 changes: 0 additions & 10 deletions srv/http/assets/js/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -1943,16 +1943,6 @@ function thumbUpdate( path ) {
);
$( '#formtemp' ).submit();
}
function urlReachable( url, sec ) {
if ( ! sec ) var sec = 0;

fetch( url, { mode: 'no-cors' } ).then( function() {
location.href = url;
} ).catch( function() {
sec++
setTimeout( () => urlReachable( url, sec ), 1000 );
} );
}
function versionHash() {
return '?v='+ Math.round( Date.now() / 1000 )
}
Expand Down
10 changes: 6 additions & 4 deletions srv/http/bash/audiocd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ elif [[ $1 == eject || $1 == off || $1 == ejecticonclick ]]; then # eject/off :

fi

! urlReachable gnudb.org audiocd 'Audio CD Database' || [[ $( mpc -f %file% playlist | grep ^cdda: ) ]] && exit
[[ $( mpc -f %file% playlist | grep ^cdda: ) ]] && exit

cddiscid=( $( cd-discid 2> /dev/null ) ) # ( id tracks leadinframe frame1 frame2 ... totalseconds )
if [[ ! $cddiscid ]]; then
Expand All @@ -56,16 +56,18 @@ if [[ ! -e $diraudiocd/$discid ]]; then
server='http://gnudb.org/~cddb/cddb.cgi?cmd=cddb'
discdata=$( tr ' ' + <<< ${cddiscid[@]} )
options='hello=owner+rAudio+rAudio+1&proto=6'
query=$( curl -sL "$server+query+$discdata&$options" | head -2 | tr -d '\r' )
notify 'audiocd blink' 'Audio CD' 'Fetch CD data ...'
query=$( curl -sfL "$server+query+$discdata&$options" | head -2 | tr -d '\r' ) # contains \r
[[ $? != 0 ]] && notify audiocd 'Audio CD' 'Server not reachable.' && exit

code=$( head -c 3 <<< $query )
if (( $code == 210 )); then # exact match
genre_id=$( sed -n 2p <<< $query | cut -d' ' -f1,2 | tr ' ' + )
elif (( $code == 200 )); then
genre_id=$( cut -d' ' -f2,3 <<< $query | tr ' ' + )
fi
if [[ $genre_id ]]; then
notify 'audiocd blink' 'Audio CD' 'Fetch CD data ...'
data=$( curl -sL "$server+read+$genre_id&$options" | grep '^.TITLE' | tr -d '\r' ) # contains \r
data=$( curl -sfL "$server+read+$genre_id&$options" | grep '^.TITLE' | tr -d '\r' ) # contains \r
readarray -t artist_album <<< $( sed -n '/^DTITLE/ {s/^DTITLE=//; s| / |\n|; p}' <<< $data )
artist=${artist_album[0]}
album=${artist_album[1]}
Expand Down
12 changes: 0 additions & 12 deletions srv/http/bash/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -328,18 +328,6 @@ statePlay() {
stringEscape() {
echo ${@//\"/\\\"}
}
urlReachable() {
url=$1
if ping -c 1 -w 1 $url &> /dev/null; then
return 0
else
icon=$2
title=$3
ping -c 1 -w 1 8.8.8.8 &> /dev/null && text="Unreachable: $url" || text='Internet is offline'
notify $icon "$title" "$text"
return 1
fi
}
volumeCardControl() {
local card control volume
if [[ -e $dirshm/nosound && ! -e $dirshm/btreceiver ]]; then
Expand Down
10 changes: 6 additions & 4 deletions srv/http/bash/scrobble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@

. /srv/http/bash/common.sh

! urlReachable ws.audioscrobbler.com scrobble 'Scrobble Server' && rm -f $dirshm/scrobble && exit

args2var "$1"

. $dirsystem/scrobblekey # sharedsecret
timestamp=$( date +%s )
apisig=$( echo -n "api_key${apikey}artist${ARTIST}methodtrack.scrobblesk${sk}timestamp${timestamp}track${TITLE}${sharedsecret}" \
| md5sum \
| cut -c1-32 )
response=$( curl -sX POST \
response=$( curl -sfX POST \
--data "api_key=$apikey" \
--data-urlencode "artist=$ARTIST" \
--data "method=track.scrobble" \
Expand All @@ -25,6 +23,10 @@ response=$( curl -sX POST \
--data "api_sig=$apisig" \
--data "format=json" \
http://ws.audioscrobbler.com/2.0 )
[[ $response =~ error ]] && msg="Error: $( jq -r .message <<< $response )" || msg=$( stringEscape $TITLE )
if [[ $? == 0 ]]; then
[[ $response =~ error ]] && msg="Error: $( jq -r .message <<< $response )" || msg=$( stringEscape $TITLE )
else
msg='Server not reachable.'
fi
[[ $msg ]] && notify lastfm Scrobble "$msg"
rm -f $dirshm/scrobble
44 changes: 20 additions & 24 deletions srv/http/bash/settings/addons-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,45 @@
online=true
if [[ -e $dirshm/addonsprogress ]]; then
rm $dirshm/addonsprogress
data=$( < $diraddons/addonslist.json )
elif urlReachable github.com addons 'Addons Server'; then
data=$( curl -sSfL https://github.com/rern/rAudio-addons/raw/main/addonslist.json )
[[ $? == 0 ]] && echo "$data" > $diraddons/addonslist.json || notify addons Addons 'Database download failed.' -1
else
online=false
data=$( < $diraddons/addonslist.json )
data=$( curl -sfL https://github.com/rern/rAudio-addons/raw/main/addonslist.json )
if [[ $? == 0 ]]; then
echo "$data" > $diraddons/addonslist.json
else
online=false
data=$( < $diraddons/addonslist.json )
notify addons Addons 'Server not reachable.' -1
fi
fi

installed='"r1"'
addons=$( sed -n '/^\s, .*{$/ {s/.*, "\(.*\)".*/\1/; p}' <<< $data )
for addon in $addons; do
addondata=$( sed -n '/"'$addon'"/,/^\s}$/ p' <<< $data )
if grep -q '"hide"' <<< $addondata; then
hide=$( sed -n '/"hide"/ {s/.* : "//; s/"$//; p}' <<< $addondata )
[[ ! $data ]] && data=$( < $diraddons/addonslist.json )
addons=( $( jq keys <<< $data | tr -d '[",]' ) )
for addon in ${addons[@]}; do
addondata=$( jq -r ."$addon" <<< $data )
hide=$( jq -r .hide <<< $addondata )
if [[ $hide != null ]]; then
[[ $hide != 1 ]] && hide=$( eval $hide )
[[ $hide ]] && hidden+=',"'$addon'"'
fi
verify=$( sed -n '/"verify"/ {s/.* : "//; s/"$//; p}' <<< $addondata )
verify=$( jq -r .verify <<< $addondata )
[[ $verify && $( eval $verify 2> /dev/null ) == 1 ]] && notverified+=',"'$addon'"'
if [[ -e $diraddons/$addon ]]; then
installed+=',"'$addon'"'
version=$( sed -n '/"version"/ {s/.* : "//; s/"$//; p}' <<< $addondata )
version=$( jq -r .version <<< $addondata )
[[ $( < $diraddons/$addon ) < $version ]] && update+=',"'$addon'"'
fi
done
[[ $hidden ]] && hidden='['${hidden:1}']' || hidden='[""]'
installed='['$installed']'
[[ $notverified ]] && notverified='['${notverified:1}']' || notverified='[""]'
if [[ $update ]]; then
update='['${update:1}']'
pushData option '{ "addons": 1 }'
touch $diraddons/update
else
update='[""]'
rm -f $diraddons/update
fi
echo $( head -n -1 <<< $data )'
, "status" : {
"hidden" : '$hidden'
, "installed" : '$installed'
, "notverified" : '$notverified'
, "update" : '$update'
"hidden" : [ '${hidden:1}' ]
, "installed" : [ '${installed:1}' ]
, "notverified" : [ '${notverified:1}' ]
, "update" : [ '${update:1}' ]
, "online" : '$online'
}
}'
18 changes: 8 additions & 10 deletions srv/http/bash/settings/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,15 @@ mirror )
;;
mirrorlist )
file=/etc/pacman.d/mirrorlist
mirror=$( sed -n '/^Server/ {s|\.*mirror.*||; s|.*//||; p}' $file )
if urlReachable github.com timezone 'Package Mirror Server'; then
curl -sfLO https://github.com/archlinuxarm/PKGBUILDs/raw/master/core/pacman-mirrorlist/mirrorlist
if [[ $? == 0 ]]; then
mv -f mirrorlist $file
[[ $mirror ]] && sed -i "0,/^Server/ s|//.*mirror|//$mirror.mirror|" $file
else
rm mirrorlist
fi
list=$( curl -sfL https://github.com/archlinuxarm/PKGBUILDs/raw/master/core/pacman-mirrorlist/mirrorlist )
if [[ $? == 0 ]]; then
mirror=$( sed -n '/^Server/ {s|\.*mirror.*||; s|.*//||; p}' $file )
[[ $mirror ]] && list=$( sed -i "0,/^Server/ s|//.*mirror|//$mirror.mirror|" <<< $list )
echo "$list" > $file
else
list=$( < $file )
fi
readarray -t lines <<< $( sed -E -n '/^### Mirror/,$ {/^\s*$|^### Mirror/ d; s|.*//(.*)\.mirror.*|\1|; p}' $file )
readarray -t lines <<< $( sed -E -n '/^### Mirror/,$ {/^\s*$|^### Mirror/ d; s|.*//(.*)\.mirror.*|\1|; p}' <<< $list )
codelist='"Auto":""'
for line in "${lines[@]}"; do
if [[ ${line:0:4} == '### ' ]];then
Expand Down
32 changes: 15 additions & 17 deletions srv/http/bash/status-coverartonline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

. /srv/http/bash/common.sh

! urlReachable ws.audioscrobbler.com coverart 'Online Cover Art' && exit

args2var "$1"

name=$( tr -d ' "`?/#&'"'" <<< $ARTIST$ALBUM )
Expand Down Expand Up @@ -32,22 +30,22 @@ data=$( curl -sfG -m 5 \
--data "api_key=$apikey" \
--data "format=json" \
http://ws.audioscrobbler.com/2.0 )
[[ $TYPE == webradio ]] && album=$( jq -r .track.album <<< $data ) || album=$( jq -r .album <<< $data )
[[ $album == null ]] && exit

image=$( jq -r .image <<< $album )
if [[ $image && $image != null ]]; then
extralarge=$( jq -r '.[3]."#text"' <<< $image )
if [[ $extralarge ]]; then
url=$( sed 's|/300x300/|/_/|' <<< $extralarge ) # get larger size than 300x300
else
if [[ $? == 0 && $data ]]; then
[[ $TYPE == webradio ]] && album=$( jq -r .track.album <<< $data ) || album=$( jq -r .album <<< $data )
[[ $album && $album != null ]] && image=$( jq -r .image <<< $album )
if [[ $image && $image != null ]]; then
extralarge=$( jq -r '.[3]."#text"' <<< $image )
[[ $extralarge && $extralarge != null ]] && url=$( sed 's|/300x300/|/_/|' <<< $extralarge ) # get larger size than 300x300
fi
fi
### 2 - coverartarchive.org #####################################
mbid=$( jq -r .mbid <<< $album )
if [[ $mbid && $mbid != null ]]; then
! urlReachable coverartarchive.org coverart 'Online Cover Art' && exit
imgdata=$( curl -sfL -m 10 https://coverartarchive.org/release/$mbid )
[[ $? == 0 ]] && url=$( jq -r .images[0].image <<< $imgdata )
fi
if [[ ! $url ]]; then
mbid=$( jq -r .mbid <<< $album )
if [[ $mbid && $mbid != null ]]; then
imgdata=$( curl -sfL -m 10 https://coverartarchive.org/release/$mbid )
[[ $? != 0 ]] && notify coverart 'Online Cover Art' 'Server not reachable.' && exit

url=$( jq -r .images[0].image <<< $imgdata )
fi
fi
[[ ! $url || $url == null ]] && exit
Expand Down

0 comments on commit dd47673

Please sign in to comment.