Mopidy Discourse

What is translate_uri for?

Hello,

I created a Mopidy extension for rudimentary Jamendo support (Github). Your template makes development a lot easier, thank you for that.

I’m a little confused about the translate_uri method. The docu says “This is very likely the only thing you need to override as a backend author”, but for the extension to work I had to override LibraryProvider.lookup. translate_uri was never called during my testing. What is the intended usage for these methods?

Override means provide your own implementation which replaces Mopidy’s default implementation. It applies to methods marked with ‘MAY be implemented by subclass’.

LibraryProvider.lookup is marked as ‘MUST be implemented by subclass’ as Mopidy does not provide a default implementation. Sounds exactly as you found…

Other extensions are a good resource if the docs are not clear enough but every method should have description. Please let us know if there’s something we could improve in the docs. translate_uri is called when Mopidy tried to play your track, you can see exactly where if you look at Mopidy’s code.

Thanks for your quick answer.

The docu for translate_uri says: “This is very likely the only thing you need to override as a backend author”. So I thought I’d get away with skipping the LibraryProvider. Adding songs with mpc did not work however, as it apparently requires a library lookup. I think something along the lines “adding tracks from external services requires this method to be overridden” would have helped me in lookup's docs, maybe with a reference in translate_uri.

Now I also understand why translate_uri was never called in my case. I always created tracks with a playable (real) uri in lookup, so Mopidy then did not need to translate anything.

You can’t avoid implementing something which must be implemented. I guess perhaps that isn’t clear that those comments are per class. I will make that change.

Great, thanks!
Other than that, the documentation is superb. The extensiondev page got me started quickly and setup.py develop makes development very comfortable. I really appreciate the work you put into all of this.