# Mopidy-headless coding

**URL:** <https://discourse.mopidy.com/t/mopidy-headless-coding/5538>\
**Category:** Help and support\
**Created:** [August 16, 2022, 7:14am UTC](https://discourse.mopidy.com/t/mopidy-headless-coding/5538 "2022-08-16T07:14:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregorv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/gregorv/32/2296_2.png) [@gregorv](https://discourse.mopidy.com/u/gregorv)\
**Post date:** [August 16, 2022, 7:14am UTC](https://discourse.mopidy.com/t/mopidy-headless-coding/5538/1 "2022-08-16T07:14:49Z")

</div>

for adding remote control I installed the extension mopidy-headless 0.30. However this is quite old and does not work with latest mopidy. In module **frontend.py** in the function **change\_playlist** (also **set\_playlist** ) the line:  
`self.core.tracklist.add(uri=self.playlists[self.selected_playlist].uri)`  
throws an error.  
The function **tracklist.add** expects a list of uris with parameter **uris=** (not uri) and **self.playlists[self.selected\_playlist].uri** just delivers the uri of the playlist.  
So I first called `track_list = self.core.playlists.get_items(self.playlists[self.selected_playlist].uri).get()` to get a list of all tracks and then build a list of uris with a for loop:

```auto
        track_uris = []
        for track in track_list:                                                                        
           track_uris.append(track.uri)

```

This can be used in **tracklist.add**  
`self.core.tracklist.add(uris=track_uris)` and it works perfectly as it should.  
I am a beginner with mopidy and python and I have the feeling that there is a better way to do this (without the iteration trough the tracks list).  
What would be the way, how mopidy experts do this fix ?

---

<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:** [August 24, 2022, 1:06pm UTC](https://discourse.mopidy.com/t/mopidy-headless-coding/5538/2 "2022-08-24T13:06:57Z")

</div>

> [@gregorv](#):
>
> for adding remote control I installed the extension mopidy-headless 0.30. However this is quite old and does not work with latest mopidy.

I’m not sure what is going on there but the 0.3 release on PyPi is actually a fork of the original and is missing a load of fixes including the one you need: [Bugfix playing of playlists · qurben/mopidy-headless@09f6d39 · GitHub](https://github.com/qurben/mopidy-headless/commit/09f6d3993585635d23e7da5955bc8f4e7ad4df28)

The project seems a little messed up, maybe we should remove it from our list.

What you have is fine but if you look at the original fix, you tdon’t need to call `get_items`:

```auto
track_uris = [track.uri for track in self.playlists[self.selected_playlist].tracks]

```

---

<div class="post-metadata">

**Author:** ![gregorv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/gregorv/32/2296_2.png) [@gregorv](https://discourse.mopidy.com/u/gregorv)\
**Post date:** [August 24, 2022, 3:43pm UTC](https://discourse.mopidy.com/t/mopidy-headless-coding/5538/3 "2022-08-24T15:43:12Z")

</div>

Thanks, I knew it could be coded better.  
However, the line throws an error “tracks is no member…”  
But I found the original and changed it to:

```auto
        tracks = self.core.playlists.get_items(self.playlists[self.selected_playlist].uri).get()
        track_uris = [track.uri for track in tracks]

```

which is nicer than what I had but still needs the **get\_items**. Also it seems there are a lot of useless .get() in the 0.30 code (e.g. behind .play()).  
So I share your thoughts about removing the 0.30 and make the original available on PyPi.  
The github link to the fix delivers confusing infos. It shows the line, you sent me, and it also shows a line in  
**reload\_playlists(self)**  
`for playlist in self.core.playlists.playlists.get():`  
This seems not to be correct - the repeated **.playlists** makes no sense for me and it also throws even more strange errors . I had the idea that this may deliver a different format for the list of playlists which works with the code

```auto
track_uris = [track.uri for track in self.playlists[self.selected_playlist].tracks]

```

Thanks,  
Gregor

---

<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:** [August 24, 2022, 8:17pm UTC](https://discourse.mopidy.com/t/mopidy-headless-coding/5538/4 "2022-08-24T20:17:47Z")

</div>

Sorry, I only had a very quick look. I don’t have the bandwidth right now.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/system/32/1_2.png) [@system](https://discourse.mopidy.com/u/system)\
**Post date:** [February 23, 2023, 8:18am UTC](https://discourse.mopidy.com/t/mopidy-headless-coding/5538/5 "2023-02-23T08:18:20Z")

</div>

Closed on February 23, 2023, 8:18am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
