rckclmbr / pyportify

App to transfer your spotify playlists to Google Play Music
Apache License 2.0
779 stars 58 forks source link

Songs with no artists cause pyportify to stop working. #64

Closed snowl closed 7 years ago

snowl commented 8 years ago

Hi rckclmbr, I'm trying to use pyportify to copy my music to GPM. I found pyportify but when I try and use it on my main playlist (https://open.spotify.com/user/1112911680/playlist/4Uqi6PgbGU69RkzGLcYtQM) this is the error I get:

Gathering tracks for playlist Good Music (387)
Not emitting portify
Not emitting portify
Traceback (most recent call last):
  File "/usr/local/bin/pyportify-copyall", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/pyportify/copy_all.py", line 61, in main
    loop.run_until_complete(start())
  File "/usr/lib/python3.5/asyncio/base_events.py", line 337, in run_until_complete
    return future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.5/dist-packages/pyportify/copy_all.py", line 55, in start
    yield from app.transfer_playlists(None, session, s, g, playlists)
  File "/usr/local/lib/python3.5/dist-packages/pyportify/app.py", line 195, in transfer_playlists
    queries = get_queries(d_list['uri'], sp_playlist_tracks)
  File "/usr/local/lib/python3.5/dist-packages/pyportify/spotify.py", line 9, in get_queries
    if "artists" in sp_track:
TypeError: argument of type 'NoneType' is not iterable

Thanks, Snowl

jonreeve commented 8 years ago

Trying to migrate a lot of playlists and I was seeing this on a few, breaking the whole process part way through. I did a little investigation.

The initial exception was raised from spotify.py, lin 14:

        if "artists" in self.sp_track['track']:

...where self.sp_track['track'] is None.

This SpotifyQuery object is created from app.py, line 159:

query = SpotifyQuery(i, sp_playlist_uri, sp_track, track_count)

...where sp_track['track'] is None.

Since sp_track at this point comes from enumerate(sp_playlist_tracks), I added a little check in here to dump the data:

            if sp_track['track'] is None:
                raise Exception("None track in playlist:\n{0}".format(sp_playlist_tracks))

That data contains a track like this:

[
...
  {
    'added_by': None,
    'track': None,
    'is_local': None,
    'added_at': None
  },
...
]

I wondered if this was a completely fake track inserted in here, or a track that exists that we're missing the data for. So I checked:

So this just appears to just be a weird fake item inserted in between, and I figure I can safely ignore it. I've ended up skipping these by adding this at app.py, line 159:

            if sp_track['track'] is not None:

... and indenting the following 3 lines of course to nest them in that check.

This resolves the issue for me. If I get a little more time later I will submit a patch for it.