New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while reordering a playlist with reorder_tracks : TypeError: int() not supported on cdata 'sp_track *' #134

Closed
ghost opened this Issue Jun 6, 2014 · 8 comments

Comments

2 participants
@ghost

ghost commented Jun 6, 2014

Hi,

I'm trying to reorder a playlist I retrieved, but keep on getting the following error :

File "/usr/local/lib/python2.7/dist-packages/spotify/playlist.py", line 272, in reorder_tracks
    new_index))
  File "/usr/local/lib/python2.7/dist-packages/spotify/__init__.py", line 58, in wrapper
    return f(*args, **kwargs)
TypeError: int() not supported on cdata 'sp_track *'

The code is reordering a playlist retrieved previously:

playlist = session.get_playlist(playlistURI)
playlist.load()
playlist.reorder_tracks(playlist.tracks, tracksToSortIndex)

with tracksToSortIndex being a list of index [2, 1, 0, 3, 5, 4, 6] the same size as the playlist.tracks playlist.

The tracks is a valid list of track :

_Tracks([Track(u'spotify:track:3rfPymjrNU59M5PaTw3ZQn'),
 Track(u'spotify:track:6hxHtk3eMy1tWwIBgYeYoY'),
 Track(u'spotify:track:6Fl2SdGRGMH5G0BsbwzVH6'),
 Track(u'spotify:track:5SWtM7JOkCyTjrSoHoBymx'),
 Track(u'spotify:track:6b7z3keZ5gDJ2zBnyrke9P'),
 Track(u'spotify:track:7BnJoLoOxYrNxzo6Hs0J7k')])

This also happens if I reorder a specific task:

  File "NovaSpotifyPlaylist.py", line 107, in pushTrackPlaylist
    playlist.reorder_tracks(playlist.tracks[1], 2)
  File "/usr/local/lib/python2.7/dist-packages/spotify/playlist.py", line 272, in reorder_tracks
    new_index))
  File "/usr/local/lib/python2.7/dist-packages/spotify/__init__.py", line 58, in wrapper
    return f(*args, **kwargs)
TypeError: int() not supported on cdata 'sp_track *'

Any idea where this error comes from?

@jodal jodal added 2.x labels Jun 7, 2014

@jodal jodal self-assigned this Jun 7, 2014

@jodal jodal modified the milestone: v2.0.0b4 Jun 7, 2014

@jodal jodal added question and removed bug labels Jun 7, 2014

@kingosticks

This comment has been minimized.

Member

kingosticks commented Jun 8, 2014

This looks like a very similar bug to #128 and needs the same fix.

Can the tests not catch stuff like this?

EDIT: Also, the parameter name new_index is slightly confusing since, unlike track indexes, it's not zero-based. libspotify document it with the term new_position which isn't a whole lot clearer but it is a distinction. Maybe a note in the docs to this effect would be nice.

@kingosticks

This comment has been minimized.

Member

kingosticks commented Jun 8, 2014

p.s. same with the callback docs.

@kingosticks

This comment has been minimized.

Member

kingosticks commented Jun 8, 2014

Ahh right, I've just found the changelog entry regarding these parameter names. So this is on purpose
but I would have to argue with the statement

a mix of the terms “position” and “index” for the same concept

For example:

0: We Might Be Dead By Tomorrow
1: Running Up That Hill (A Deal With God)
2: Monument
3: Nýfallið regn
4: Hollow Talk

And running playlist.reorder_tracks(1, 3) (after fixing) gives:

0: We Might Be Dead By Tomorrow
1: Monument
2: Running Up That Hill (A Deal With God)
3: Nýfallið regn
4: Hollow Talk

So it's moved track[1] to position 3 rather than (zero-based) index 3.

@ghost

This comment has been minimized.

ghost commented Jun 8, 2014

Ooh I get it now! I thought it was expecting a Track.
It would be worth updating the documentation for reorder_track
I'll have a look at it, thanks a lot!

@kingosticks

This comment has been minimized.

Member

kingosticks commented Jun 8, 2014

@becspam just to be clear, reorder_track does currently expect a Track or list of Tracks. However, in your first example you are incorrectly passing the new_index parameter as a list of integers.

Your second example is called correctly but fails due to the bug in pyspotify.

@ghost

This comment has been minimized.

ghost commented Jun 9, 2014

Fair enough!
I'll test it after the issue has been fixed in pyspotify.
Thanks!

@jodal jodal closed this in c913b45 Jun 9, 2014

@jodal jodal added 2.x and removed 2.x labels Jun 9, 2014

@jodal jodal added this to the v2.0.0b4 milestone Jun 9, 2014

@jodal

This comment has been minimized.

Member

jodal commented Jun 9, 2014

Given that new_position points to a location in the list before any tracks are removed from the list, I'd argue that the index behavior as is is correct and identical with how Python collections works. reorder_tracks() works kind of like insert() of all the tracks on new_index with a following removal from the old index.

>>> tracks = ['a', 'b', 'c', 'd', 'e']
>>> tracks[1]
'b'
>>> tracks.insert(3, 'b')
>>> tracks
['a', 'b', 'c', 'b', 'd', 'e']
>>> del tracks[1]
>>> tracks
['a', 'c', 'b', 'd', 'e']
@kingosticks

This comment has been minimized.

Member

kingosticks commented Jun 9, 2014

I guess I was thinking about it the other way around: a removal followed be an insert. But your way makes sense. Sorry for the noise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment