# Buggy code
def get_album_info(self, result):
    """Returns an AlbumInfo object for a discogs Release object."""
    artist, artist_id = self.get_artist([a.data for a in result.artists])
    album = re.sub(r" +", " ", result.title)
    album_id = result.data["id"]
    # Use `.data` to access the tracklist directly instead of the
    # convenient `.tracklist` property, which will strip out useful artist
    # information and leave us with skeleton `Artist` objects that will
    # each make an API call just to get the same data back.
    tracks = self.get_tracks(result.data["tracklist"])
    albumtype = ", ".join(result.data["formats"][0].get("descriptions", [])) or None
    va = result.data["artists"][0]["name"].lower() == "various"
    if va:
        artist = config["va_name"].as_str()
    year = result.data["year"]
    label = result.data["labels"][0]["name"]
    mediums = len(set(t.medium for t in tracks))
    catalogno = result.data["labels"][0]["catno"]
    if catalogno == "none":
        catalogno = None
    country = result.data.get("country")
    media = result.data["formats"][0]["name"]
    # Explicitly set the `media` for the tracks, since it is expected by
    # `autotag.apply_metadata`, and set `medium_total`.
    for track in tracks:
        track.media = media
        track.medium_total = mediums
    data_url = result.data["uri"]
    return AlbumInfo(
        album,
        album_id,
        artist,
        artist_id,
        tracks,
        asin=None,
        albumtype=albumtype,
        va=va,
        year=year,
        month=None,
        day=None,
        label=label,
        mediums=mediums,
        artist_sort=None,
        releasegroup_id=None,
        catalognum=catalogno,
        script=None,
        language=None,
        country=country,
        albumstatus=None,
        media=media,
        albumdisambig=None,
        artist_credit=None,
        original_year=None,
        original_month=None,
        original_day=None,
        data_source="Discogs",
        data_url=data_url,
    )


# Traceback (IndexError)
/data/Music/Unsorted/New Stuff/Para One - 2003 - Paraone - Iris - Le Sept - Flynt - Lyricson (Maxi) [CD - FLAC] (6 items)
Finding tags for album "Paraone - Iris - Le sept - Flynt - Lyricson - Paraone - Iris - Le Sept - Flynt - Lyricson".
Candidates:
1. The Kenny Clarke - Francy Boland Big Band - Paris Jazz Concert: TNP - Oct. 29th, 1969, Part 2 (35.9%) (tracks, artist, album, ...) (CD, 2002, DE, LaserLight Digital)
2. A - Z Consolidated - A - Z Consolidated (33.8%) (tracks, album, artist)
3. Μίκης Θεοδωράκης - Βασίλης Τσιτσάνης - Σταμάτης Κόκοτας - Θεοδωράκης - Τσιτσάνης - Κόκοτας (29.3%) (tracks, missing tracks, album, ...) (12" Vinyl, 1985, GR, Μίνως Μάτσας &amp; Υιός Α.Ε.)
4. Pirkko Mannola - Brita Koivunen - Vieno Kekkonen - Pirkko - Brita - Vieno (20.2%) (missing tracks, tracks, artist, ...) (CD, 1989, FI, Finnlevy)
5. _ - _ (7.7%) (missing tracks, tracks, album, ...)
# selection (default 1), Skip, Use as-is, as Tracks, Group albums,
Enter search, enter Id, aBort? I
Enter release ID: 690105
Traceback (most recent call last):
File "/home/cesar/.local/bin/beet", line 11, in <module>
sys.exit(main())
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/__init__.py", line 1250, in main
_raw_main(args)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/__init__.py", line 1240, in _raw_main
subcommand.func(lib, suboptions, subargs)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/commands.py", line 967, in import_func
import_files(lib, paths, query)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/commands.py", line 944, in import_files
session.run()
File "/home/cesar/.local/lib/python2.7/site-packages/beets/importer.py", line 320, in run
pl.run_parallel(QUEUE_SIZE)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/util/pipeline.py", line 301, in run
out = self.coro.send(msg)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/util/pipeline.py", line 160, in coro
task = func(*(args + (task,)))
File "/home/cesar/.local/lib/python2.7/site-packages/beets/importer.py", line 1285, in user_query
task.choose_match(session)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/importer.py", line 779, in choose_match
choice = session.choose_match(self)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/ui/commands.py", line 755, in choose_match
task.items, search_ids=search_id.split()
File "/home/cesar/.local/lib/python2.7/site-packages/beets/autotag/match.py", line 407, in tag_album
search_cands.extend(hooks.albums_for_id(search_id))
File "/home/cesar/.local/lib/python2.7/site-packages/beets/autotag/hooks.py", line 541, in albums_for_id
plugin_albums = plugins.album_for_id(album_id)
File "/home/cesar/.local/lib/python2.7/site-packages/beets/plugins.py", line 373, in album_for_id
res = plugin.album_for_id(album_id)
File "/home/cesar/.local/lib/python2.7/site-packages/beetsplug/discogs.py", line 188, in album_for_id
return self.get_album_info(result)
File "/home/cesar/.local/lib/python2.7/site-packages/beetsplug/discogs.py", line 225, in get_album_info
result.data['formats'][0].get('descriptions', [])) or None
IndexError: list index out of range

# Fixed code
def get_album_info(self, result):
    """Returns an AlbumInfo object for a discogs Release object."""
    # Explicitly reload the `Release` fields, as they might not be yet
    # present if the result is from a `discogs_client.search()`.
    if not result.data.get("artists"):
        result.refresh()

    # Sanity check for required fields. The list of required fields is
    # defined at Guideline 1.3.1.a, but in practice some releases might be
    # lacking some of these fields. This function expects at least:
    # `artists` (>0), `title`, `id`, `tracklist` (>0)
    # https://www.discogs.com/help/doc/submission-guidelines-general-rules
    if not all([result.data.get(k) for k in ["artists", "title", "id", "tracklist"]]):
        self._log.warn("Release does not contain the required fields")
        return None

    artist, artist_id = self.get_artist([a.data for a in result.artists])
    album = re.sub(r" +", " ", result.title)
    album_id = result.data["id"]
    # Use `.data` to access the tracklist directly instead of the
    # convenient `.tracklist` property, which will strip out useful artist
    # information and leave us with skeleton `Artist` objects that will
    # each make an API call just to get the same data back.
    tracks = self.get_tracks(result.data["tracklist"])

    # Extract information for the optional AlbumInfo fields, if possible.
    va = result.data["artists"][0].get("name", "").lower() == "various"
    year = result.data.get("year")
    mediums = len(set(t.medium for t in tracks))
    country = result.data.get("country")
    data_url = result.data.get("uri")

    # Extract information for the optional AlbumInfo fields that are
    # contained on nested discogs fields.
    albumtype = media = label = catalogno = None
    if result.data.get("formats"):
        albumtype = ", ".join(result.data["formats"][0].get("descriptions", [])) or None
        media = result.data["formats"][0]["name"]
    if result.data.get("labels"):
        label = result.data["labels"][0].get("name")
        catalogno = result.data["labels"][0].get("catno")

    # Additional cleanups (various artists name, catalog number, media).
    if va:
        artist = config["va_name"].as_str()
    if catalogno == "none":
        catalogno = None
    # Explicitly set the `media` for the tracks, since it is expected by
    # `autotag.apply_metadata`, and set `medium_total`.
    for track in tracks:
        track.media = media
        track.medium_total = mediums

    return AlbumInfo(
        album,
        album_id,
        artist,
        artist_id,
        tracks,
        asin=None,
        albumtype=albumtype,
        va=va,
        year=year,
        month=None,
        day=None,
        label=label,
        mediums=mediums,
        artist_sort=None,
        releasegroup_id=None,
        catalognum=catalogno,
        script=None,
        language=None,
        country=country,
        albumstatus=None,
        media=media,
        albumdisambig=None,
        artist_credit=None,
        original_year=None,
        original_month=None,
        original_day=None,
        data_source="Discogs",
        data_url=data_url,
    )