Hallon/libspotify folder hierarchy questions

Skip to first unread message

Mathias Bruce

Jul 28, 2012, 12:44:07 PM7/28/12
to ruby-...@googlegroups.com
Hi Kim,

First off, thanks for a great library!

Unfortunately, I find libspotify's notion of folders a bit unintuitive, so it would be very helpful if you could correct my conceptual mistakes and perhaps provide a bit more insight. I understand that many of your design choices are probably direct results of the libspotify design.

* Using Hallon, I find 2 items for every folder that seem essentially identical. Why not just a single item?
* Why the folder begin and end indices? What value do they add compared to every folder just having a collection with its contents and the ability to add new items in (or move existing items to) that collection?

What I want to do is use Hallon to create folder and playlist hierarchies several levels deep. I assume that the add (for playlists) and add_folder (for folders) methods on the root container can be used to create playlists and folders in the root, but no obvious way to place them elsewhere, i.e. the same methods don't exist on the folder class. Since the folder child contents is offered by a regular method instead of an attribute I get the impression that the array returned by contents isn't supposed to be used to populate a folder with new (or existing) folders and playlists using just << or similar.

Is it necessary to first create folders and playlists in the root container and then use the container methods move and move_playlist to move them, passing the beginning index of the folder I want to move them into? Or folder beginning index+1? When I move a folder, are all its contents "moved" accordingly (their indices adjusted) and both its begin and end indices adjusted accordingly? Or should I use the root container method insert_folder using the beginning index (+1?) of the destination folder?

I'll provide a use case: Let's say I wanted to create the following folder/playlist hierarchy, playlists designated by a trailing *

What would be the most convenient way to do that with Hallon?

Thanks again for a great library, and sorry about the long rambling above. =o)

Best regards,

Kim Burgestrand

Jul 29, 2012, 5:46:55 AM7/29/12
to ruby-...@googlegroups.com
Hi! I won’t have enough time with my computer to write you a full reply today, so here’s the short points.

- Hallon’s API is spotty at best. I don’t like the direction Hallon’s been taking, so I’ve been working (on paper) on a better, opinionated API for Hallon.
- As a result of the above point, I’ve also been working on moving a lot of the low level stuff in Hallon towards the Spotify gem. Once done, I hope Hallon will be much more clear in how to do things (and also more clear in that certain things are not meant to be done with Hallon), and Spotify will be much more painless to use to fill in the gaps if necessary.
- Your issue is mainly a symptom of both the above points, but the real reason is that the API was not written to make writing to playlist containers or folders easy, only reading. Excluding good write support is not something I deliberately did, it is simply something I never considered when writing the implementation.
- Playlist containers in libspotify are _flat_. The playlist entries are simply playlists, but folders are nothing but markers with a start marker and an ending marker. This is why the folders have a beginning index and an end index. When you read the contents of a playlist container on a folder marker (either the beginning one, or the ending one), Hallon will search upwards or downwards for the other marker (either beginning, or end), and give you a folder back with those indices. This is why you will receive two identical folder entries for each folder when reading the playlist container.

However, with the above said, there’s nothing hindering giving a folder the ability to insert playlists and folders into itself. It has a reference back to the playlist container, and it’s own start/stop indices. You’re very welcome to create an issue on Hallon with this, and I’ll tag it as a feature request to make it happen. :)

PS: You are of course very welcome to try and write your own solution and submit a pull request and I’ll merge it in!
PPS: Sorry about the brevity in my response, most of my day today will be spent off the computer and I’m a bit low on time already. :)

— Kim

Aurélien Malisart

Jan 18, 2013, 4:56:03 AM1/18/13
to ruby-...@googlegroups.com

I think I understand the container structure. But so is it possible to update the begin and end indices to actually put a given playlist inside of a folder ?

Let's say I have a playlist at position i and a folder at position j which ends in k.

In order to put the playlist inside the folder, in need to :
* move the playlist from i to k+1
* change the end of the folder to k + 1

Right ?

Maybe I'm missing something !

Aurélien Malisart

Jan 18, 2013, 7:06:29 AM1/18/13
to ruby-...@googlegroups.com
OK I managed to do what I want.  To move a playlist inside a folder, you simply have to move it to a position which is in its range (between begin and end).  The end grows automatically.


Kim Burgestrand

Jan 18, 2013, 5:19:58 PM1/18/13
to Hallon on behalf of Aurélien Malisart
Yes, this is because the markers that mark the begin and end of a playlist are themselves
items inside the playlist. If you move a playlist that is below a folder, to inside it, the ending
marker of the folder must move up one index, as must every item after the newly inserted

— Kim

Aurélien Malisart

Jan 19, 2013, 8:40:58 AM1/19/13
to ruby-...@googlegroups.com
Absolutely !
Reply all
Reply to author
0 new messages