Repository: beetbox/beets

Issue:
Spotify plugin crashes often
### Problem

Bunch of results online all over the place for this one, seems to be a problem with their API

`beet import [whatever]`

Led to this problem:

```
  File "/Library/Frameworks/Python.framework/Versions/3.9/bin/beet", line 33, in <module>
    sys.exit(load_entry_point('beets==1.6.1', 'console_scripts', 'beet')())
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/ui/__init__.py", line 1304, in main
    _raw_main(args)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/ui/__init__.py", line 1291, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/ui/commands.py", line 1034, in import_func
    import_files(lib, paths, query)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/ui/commands.py", line 974, in import_files
    session.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/importer.py", line 340, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/util/pipeline.py", line 446, in run_parallel
    raise exc_info[1].with_traceback(exc_info[2])
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/util/pipeline.py", line 311, in run
    out = self.coro.send(msg)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/util/pipeline.py", line 193, in coro
    func(*(args + (task,)))
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/importer.py", line 1395, in lookup_candidates
    task.lookup_candidates()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/importer.py", line 661, in lookup_candidates
    autotag.tag_album(self.items, search_ids=self.search_ids)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/autotag/match.py", line 461, in tag_album
    for matched_candidate in hooks.album_candidates(items,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/plugins.py", line 573, in decorated
    for v in generator(*args, **kwargs):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/autotag/hooks.py", line 632, in album_candidates
    yield from plugins.candidates(items, artist, album, va_likely, extra_tags)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/plugins.py", line 384, in candidates
    yield from plugin.candidates(items, artist, album, va_likely,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/plugins.py", line 733, in candidates
    albums = [self.album_for_id(album_id=r['id']) for r in results]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beets/plugins.py", line 733, in <listcomp>
    albums = [self.album_for_id(album_id=r['id']) for r in results]
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beetsplug/spotify.py", line 260, in album_for_id
    track = self._get_track(track_data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/beetsplug/spotify.py", line 300, in _get_track
    album = track_data['album']['name']
TypeError: 'NoneType' object is not subscriptable
```

### Setup

* OS: macOS High Sierra
* Python version: 3.9.5
* beets version: 1.6.1
* Turning off plugins made problem go away (yes/no): turning off Spotify plugin





Discussion:

Resolving patch:
diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py
--- a/beetsplug/spotify.py
+++ b/beetsplug/spotify.py
@@ -298,7 +298,7 @@ def _get_track(self, track_data):
         # Get album information for spotify tracks
         try:
             album = track_data['album']['name']
-        except KeyError:
+        except (KeyError, TypeError):
             album = None
         return TrackInfo(
             title=track_data['name'],


Test patch: