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

**URL:** <https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943>\
**Category:** Misc\
**Created:** [October 20, 2015, 10:31pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943 "2015-10-20T22:31:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwjt42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/mwjt42/32/260_2.png) [@mwjt42](https://discourse.mopidy.com/u/mwjt42)\
**Post date:** [October 20, 2015, 10:31pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/1 "2015-10-20T22:31:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Geert](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/geert/32/252_2.png) [@Geert](https://discourse.mopidy.com/u/Geert)\
**Post date:** [October 21, 2015, 6:53pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/2 "2015-10-21T18:53:13Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [October 21, 2015, 7:16pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/3 "2015-10-21T19:16:07Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [October 21, 2015, 7:16pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/4 "2015-10-21T19:16:46Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![mwjt42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/mwjt42/32/260_2.png) [@mwjt42](https://discourse.mopidy.com/u/mwjt42)\
**Post date:** [October 21, 2015, 7:21pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/5 "2015-10-21T19:21:18Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![Geert](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/geert/32/252_2.png) [@Geert](https://discourse.mopidy.com/u/Geert)\
**Post date:** [October 21, 2015, 8:05pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/6 "2015-10-21T20:05:34Z")

</div>

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](http://mp3.streampower.be/stubru-high.mp3)

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [October 21, 2015, 8:11pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/7 "2015-10-21T20:11:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Geert](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/geert/32/252_2.png) [@Geert](https://discourse.mopidy.com/u/Geert)\
**Post date:** [October 21, 2015, 8:15pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/8 "2015-10-21T20:15:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [October 21, 2015, 8:31pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/9 "2015-10-21T20:31:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mwjt42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/mwjt42/32/260_2.png) [@mwjt42](https://discourse.mopidy.com/u/mwjt42)\
**Post date:** [October 21, 2015, 8:38pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/10 "2015-10-21T20:38:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwjt42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/mwjt42/32/260_2.png) [@mwjt42](https://discourse.mopidy.com/u/mwjt42)\
**Post date:** [October 21, 2015, 8:40pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/11 "2015-10-21T20:40:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [October 21, 2015, 8:50pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/12 "2015-10-21T20:50:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwjt42](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/mwjt42/32/260_2.png) [@mwjt42](https://discourse.mopidy.com/u/mwjt42)\
**Post date:** [October 21, 2015, 8:55pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/13 "2015-10-21T20:55:10Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [October 22, 2015, 10:47am UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/14 "2015-10-22T10:47:54Z")

</div>

> <https://github.com/pimusicbox/pimusicbox/blob/develop/filechanges/opt/musicbox/startup.sh#L253-L271>

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.

---

<div class="post-metadata">

**Author:** ![kingosticks](https://avatars.discourse-cdn.com/v4/letter/k/858c86/32.png) [@kingosticks](https://discourse.mopidy.com/u/kingosticks)\
**Post date:** [December 7, 2015, 10:45pm UTC](https://discourse.mopidy.com/t/mpc-cli-spotify-playlist-not-found-unless-recently-browsed-in-http-client/943/15 "2015-12-07T22:45:35Z")

</div>

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