Skip to content

Commit

Permalink
Updates for Spotify and Deezer metadata
Browse files Browse the repository at this point in the history
- Improve metadata handling in hook scripts
- Add FORMAT env var for pleezer
- Encode HTML entities before sending to front-end
  • Loading branch information
moodeaudio committed Dec 30, 2024
1 parent ec0bafe commit c80ec1c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions var/local/www/commandw/deezevent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ if [[ $EVENT == "disconnected" ]]; then
fi

if [[ $EVENT == "track_changed" ]]; then
METADATA=$TITLE";"$ARTIST";"$ALBUM_TITLE";"$DURATION";"https://e-cdns-images.dzcdn.net/images/cover/${ALBUM_COVER}/500x500.jpg
echo -e $METADATA > $DEEZMETA_FILE
FORMAT="MP3 or FLAC"
METADATA="${TITLE}~~~${ARTIST}~~~${ALBUM_TITLE}~~~${DURATION}~~~https://e-cdns-images.dzcdn.net/images/cover/${ALBUM_COVER}/500x500.jpg~~~${FORMAT}"
echo -e "$METADATA" > $DEEZMETA_FILE
/var/www/util/send-fecmd.php "update_deezmeta,$METADATA"
fi
8 changes: 4 additions & 4 deletions var/local/www/commandw/spotevent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ fi

if [[ $PLAYER_EVENT == "track_changed" ]]; then
COVER=$(echo $COVERS | cut -d " " -f 1)
#ARTIST=$(echo $ARTISTS | cut -d " " -f 1) should be \n delimited
#ARTISTS=$(echo "$ARTISTS" | tr '\n' ', ') should be \n delimited
METADATA=$NAME";"$ARTISTS";"$ALBUM";"$DURATION_MS";"$COVER
echo -e $METADATA > $SPOTMETA_FILE
#ARTIST=$(echo $ARTISTS | cut -d " " -f 1) should be \n delimited?
#ARTISTS=$(echo "$ARTISTS" | tr '\n' ', ') should be \n delimited?
METADATA="${NAME}~~~${ARTISTS}~~~${ALBUM}~~~${DURATION_MS}~~~${COVER}"
echo -e "$METADATA" > $SPOTMETA_FILE
/var/www/util/send-fecmd.php "update_spotmeta,$METADATA"
fi
2 changes: 1 addition & 1 deletion www/audioinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
$_decode_rate = '';
} else if ($deezActive == '1') {
$_file = 'Deezer stream';
$_encoded_at = 'MP3 or FLAC';
$_encoded_at = getDeezerFormat();
$_decoded_to = 'PCM 16 bit 44.1 kHz, Stereo';
$_decode_rate = '';
} else if ($slActive == '1') {
Expand Down
4 changes: 4 additions & 0 deletions www/inc/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ function stopDeezer() {
$GLOBALS['deezactive'] = '0';
sendFECmd('deezactive0');
}
function getDeezerFormat() {
$metadata = explode('~~~', file_get_contents(DEEZMETA_FILE));
return $metadata[5];
}

// Squeezelite
function startSqueezeLite() {
Expand Down
6 changes: 3 additions & 3 deletions www/js/playerlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -798,9 +798,9 @@ function updateInpsrcMeta(cmd, data) {
$('#inpsrc-backdrop').css('filter', 'blur(0px)');
$('#inpsrc-backdrop').css('transform', 'scale(1.0)');

// Spotify: title;artists;album;duration;coverurl (duration is in ms)
// Deezer: title;artist;album;duration;coverurl (duration is in secs)
var metadata = data.split(';');
// Spotify: title;artist;album;duration;coverurl (duration is in ms)
// Deezer: title;artist;album;duration;coverurl;format (duration is in secs)
var metadata = data.split('~~~');
var timeDivisor = (cmd == 'get_spotmeta' || cmd == 'update_spotmeta') ? 1000 : 1;

$('#inpsrc-backdrop').html('<img class="inpsrc-metadata-backdrop" ' + 'src="' + metadata[4] + '">');
Expand Down
7 changes: 6 additions & 1 deletion www/util/send-fecmd.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@
"Usage: send-fecmd.php [command]
Send a command to the front-end\n";
} else {
sendFECmd($argv[1]);
// Preprocess data for certain commands
$cmd = (str_contains($argv[1], 'update_deezmeta') || str_contains($argv[1], 'update_spotmeta')) ?
htmlspecialchars($argv[1], ENT_NOQUOTES) : $argv[1];

// Send to front-end
sendFECmd($cmd);
}

0 comments on commit c80ec1c

Please sign in to comment.