Unable to create a playlist from a podcast URI in mopidy.js

Hi guys!

I’m working on a internet radio (spotify/podcasts) on a raspberry pi in an Ikea hack, and absolutely loving Mopidy so far! However, I run into the following problem: when trying to create a playlist based on a podcast URI, no playlist seems to be created. More specifically, the following code returns the console error: [TypeError: Cannot read property ‘name’ of null]

var Mopidy = require("mopidy");
var mopidy = new Mopidy({
  webSocketUrl: "ws://localhost:6680/mopidy/ws",
  callingConvention: "by-position-only"

var init = function() {
  mopidy.playlists.create("Podcast Playlist", "http://www.npr.org/rss/podcast.php?id=510019").then(function(playlist) {

mopidy.on("state:online", init);

I tried different variations of the podcast url (e.g., podcast:// or podcast+http:// instead of http://, as mentioned on https://github.com/tkem/mopidy-podcast/issues/7) but got the same error. Probably, I’m missing something obvious :slight_smile: but I’m not finding any clues in the forums or on github. Any clues or pointers are greatly appreciated!

I suspect this is the same issue as was fixed in https://github.com/mopidy/mopidy/pull/1165, which was released in Mopidy 1.0.5 a few mintues ago. Can you retry with that version?

Thanks a lot, @jodal ! Indeed, after the upgrade to 1.0.5, the javascript code displayed the name of the playlist correctly :slight_smile:

However, I expected that the podcast episodes would then be added as tracks for that playlist. Currently, no tracks seem to be present in the playlist: the musicbox web client also shows the playlist, but no tracks. Is this by design? Anyway, I’ll try to look further into it tomorrow.

The API is a bit funny due to well legacy reasons. You have to create a new playlist model instance, then you can replace that tracks key with a new list of tracks. These also need to be valid models, so run the URIs through library.lookup to get them converted. Then once that is done you can call save on your modified playlist instance.

Longer term we really really hope to kill this form of the API, as it isn’t exactly nice to work with or explain.

Since a few lines of code may explain this better, @Fluppe2root may want to have a look at


which saves the current tracklist as a playlist. Note also that you don’t have to do a library.lookup necessarily; you can use any JS object that looks like a proper Track model to Mopidy, i.e. has uri, name and __model__ fields; see


for an example.

Which reminds me, that I always wanted to suggest for Mopidy.js to provide some way to create proper models in a less “hackish” way. Like

Mopidy.track({uri="foo", name="bar", ...})

I thought that one benefit of the newer Ref based APIs was the that we wouldn’t have to worry about creating models any more.

Thanks @adamcik and @tkem, I’m able to add tracks now! I’ll keep on tinkering, and hope to show you another finished Mopidy project soon!

@kingosticks: But a Ref is a model :wink:

True, but even I can’t get it wrong!

See also https://github.com/mopidy/mopidy.js/issues/7