Mpc CLI - Spotify playlist not found unless recently browsed in http client

I want to control MPD by commandline. Adding a playlist immediately after reboot gives me an error:

mpc add spotify:user:spotify:playlist:3ZgmfR6lsnCwdffZUan8EA
error: directory or file not found

However, if I browse Spotify using the http interface (musicbox.local) then the mpc add command works.

What does the http client do that ‘wakes’ up this connection and how would I invoke this behaviour in the commandline?

I guess this problem must be related to Spotify as I do the same to start a normal internet radio stream at boot time:

mpc add http://mp3.streampower.be/stubru-high.mp3

Does that work for you?

If so, did you set your Spotify username and password in the Mopidy config file?

This behaviour is not intentional but there might be a couple of things going on here.

I could not reliably reproduce the mpc add error, but when I did get it, it was due to the mopidy_spotify.lookup timing out. This was also accompanied by numerous ‘ChannelError(10, 1, playlist)’ libspotify messages throughout the log which usually indicate there is an intermittent problem with the Spotify service itself. See log at http://dpaste.com/32X1JN8

All the other times, I found that the mpc add command worked but only some of the tracks were actually added to the tracklist (usually just the first 3). If I then cleared the tracklist and repeated the mpc add command I got all the tracks. There was nothing in the log to indicate anything went wrong. I then found that after adding some logging to report None tracks in mopidy-spotify’s lookup_playlist, I got nearly all 194 tracks added to the playlist first time. Perhaps the tracks do not have sufficient time to load when you try and add a playlist straight to the tracklist that is not present amongst your saved playlists?

This behaviour is not intentional but there might be a couple of things going on here.

I could not reliably reproduce the mpc add error, but when I did get it, it was due to the mopidy_spotify.lookup timing out. This was also accompanied by numerous ‘ChannelError(10, 1, playlist)’ libspotify messages throughout the log which usually indicate there is an intermittent problem with the Spotify service itself. See log at http://dpaste.com/32X1JN8

All the other times, I found that the mpc add command worked but only some of the tracks were actually added to the tracklist (usually just the first 3). If I then cleared the tracklist and repeated the mpc add command I got all the tracks. There was nothing in the log to indicate anything went wrong. I then found that after adding some logging to report None tracks in mopidy-spotify’s lookup_playlist, I got nearly all 194 tracks added to the playlist first time. Perhaps the tracks do not have sufficient time to load when you try and add a playlist straight to the tracklist that is not present amongst your saved playlists?

I’m now unable to replicate this myself (seems to be ok now…), but my issue has progressed.

None of the mpc commands will execute on boot. I have a shell script in /etc/network/if-up.d that writes output to a log file, so I know the script is working, but the mpc commands do not run. (they do if started manually)

script:

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export DISPLAY=:0.0
exec > /etc/network/if-up.d/spotify.log
echo $(date)
echo 'starting'
sleep 60
echo 'sleep'
mpc clear
echo 'clear'
mpc add spotify:user:spotify:playlist:3ZgmfR6lsnCwdffZUan8EA
echo 'add playlist'
mpc random on
echo 'random'
mpc repeat on
echo 'repeat'
mpc volume 10
echo 'volume'
mpc play

I’m using a bash script scheduled as a cron job (etc/crontab). The script is launched as root and all the contained mpc commands specify the Mopidy password and hostname:

mpc -h password@localhost add http://mp3.streampower.be/stubru-high.mp3

How do you know that mopidy has started and is accepting connections by the
time your script runs?

The sleep 60 statement I guess. I use sleep 20 which always works. Sleep 10 sometimes failed.

Sure, you could guess that it’s up by then. Or you could loop until map
status returns with something. If those commands work if you issue them at
the terminal (straight away) but don’t in your script… then that’s what
I’d want to be totally sure about.

I’ve discovered the startup.sh in /opt/musicbox and now appended my script to that - with sleep 30 the autoplay is consistent

Ok, I’m experiencing this error again now. Any idea on how to increase the timeout?

That’s changing in the next version of musicbox because it’s been reported
by some users that it’s not always long enough.

1 Like

That’s good news. Any info how to implement this myself? I’m currently trying this script as a work around.

#!/bin/bash

while [ true ]
do
 if [[ $(mpc add spotify:user:spotify:playlist:3ZgmfR6lsnCwdffZUan8EA) != "" ]]; then
  echo "added ok"
 fi
sleep 1
done

I’m trying to keep the playlist up-to-date (as it’s the top 100)

But I wonder if there really is an issue when adding a foreign (i.e. one you do not follow) spotify playlist straight to the tracklist as per the first few messages in this thread. That is worth getting to the bottom of.

I created an issue for the original bug at https://github.com/mopidy/mopidy-spotify/issues/81