How to switch between directories in frontend extension?

Hey, I’m writing a serial port frontend for mopidy to work with my Arduino [1]. I intend to switch “channels” with a rotating knob, like on old radios. Such a channel would be an URI defined in the config file.

Anyways, I was under the impression that this code

self.core.tracklist.add(uri='soundcloud:directory:explore/10')

should correctly fetch n tracks from this soundcloud explore stream and add it to my tracklist. But what actually happens is I get an error that no such track was found, because lookup in mopidy-soundcloud is implemented in a way to look for specific tracks and doesn’t resolve streams (is this fully intended behavior?).

I worked around it with

tracks = flatten(map(lambda ref: self.core.library.lookup(ref.uri).get(), self.core.library.browse(channel_uri).get()))
self.core.tracklist.add(tracks=tracks, at_position=0).get()

I’m sure there is a better option? Should the lookup function be extended?

Thank you very much,
Nikolaus

[1] https://github.com/prayerslayer/mopidy-serialport

A simpler way is to use add()'s uris parameter (new in 1.0 and the only argument that isn’t deprecated):

refs = self.core.library.browse(channel_uri).get()
tl_tracks = self.core.tracklist.add(uris=[ref.uri for ref in refs]).get()

And yes, Mopidy-SoundCloud’s lookup() implementation could clearly be extended to support this directly. Please open an issue with Mopidy-SoundCloud suggesting it.

Ah, that is really better code. Will open an issue in mopidy-soundcloud, thank you very much!