'Since we call the same url for both info and artwork, we\'ll update both at the same time'

def _update_cache(self):

    myDB = db.DBConnection()
    if (self.id_type == 'artist'):
        data = lastfm.request_lastfm('artist.getinfo', mbid=self.id, api_key=LASTFM_API_KEY)
        if (not data):
            dbartist = myDB.action('SELECT    ArtistName,    Type    FROM    artists    WHERE    ArtistID=?', [self.id]).fetchone()
            if dbartist:
                data = lastfm.request_lastfm('artist.getinfo', artist=helpers.clean_musicbrainz_name(dbartist['ArtistName']), api_key=LASTFM_API_KEY)
        if (not data):
            return
        try:
            self.info_summary = data['artist']['bio']['summary']
        except KeyError:
            logger.debug('No    artist    bio    summary    found')
            self.info_summary = None
        try:
            self.info_content = data['artist']['bio']['content']
        except KeyError:
            logger.debug('No    artist    bio    found')
            self.info_content = None
        try:
            image_url = data['artist']['image'][(-1)]['#text']
        except KeyError:
            logger.debug('No    artist    image    found')
            image_url = None
        thumb_url = self._get_thumb_url(data)
        if (not thumb_url):
            logger.debug('No    artist    thumbnail    image    found')
    else:
        dbalbum = myDB.action('SELECT    ArtistName,    AlbumTitle,    ReleaseID,    Type    FROM    albums    WHERE    AlbumID=?', [self.id]).fetchone()
        if (dbalbum['ReleaseID'] != self.id):
            data = lastfm.request_lastfm('album.getinfo', mbid=dbalbum['ReleaseID'], api_key=LASTFM_API_KEY)
            if (not data):
                data = lastfm.request_lastfm('album.getinfo', artist=helpers.clean_musicbrainz_name(dbalbum['ArtistName']), album=helpers.clean_musicbrainz_name(dbalbum['AlbumTitle']), api_key=LASTFM_API_KEY)
        elif (dbalbum['Type'] != 'part    of'):
            data = lastfm.request_lastfm('album.getinfo', artist=helpers.clean_musicbrainz_name(dbalbum['ArtistName']), album=helpers.clean_musicbrainz_name(dbalbum['AlbumTitle']), api_key=LASTFM_API_KEY)
        else:
            artist = mb.getArtistForReleaseGroup(self.id)
            if artist:
                data = lastfm.request_lastfm('album.getinfo', artist=helpers.clean_musicbrainz_name(artist), album=helpers.clean_musicbrainz_name(dbalbum['AlbumTitle']), api_key=LASTFM_API_KEY)
        if (not data):
            return
        try:
            self.info_summary = data['album']['wiki']['summary']
        except KeyError:
            logger.debug('No    album    summary    found')
            self.info_summary = None
        try:
            self.info_content = data['album']['wiki']['content']
        except KeyError:
            logger.debug('No    album    infomation    found')
            self.info_content = None
        try:
            image_url = data['album']['image'][(-1)]['#text']
        except KeyError:
            logger.debug('No    album    image    link    found')
            image_url = None
        thumb_url = self._get_thumb_url(data)
        if (not thumb_url):
            logger.debug('No    album    thumbnail    image    found')
    if (self.id_type == 'artist'):
        controlValueDict = {'ArtistID': self.id}
    else:
        controlValueDict = {'ReleaseGroupID': self.id}
    newValueDict = {'Summary': self.info_summary, 'Content': self.info_content, 'LastUpdated': helpers.today()}
    myDB.upsert('descriptions', newValueDict, controlValueDict)
    if image_url:
        if (self.id_type == 'artist'):
            myDB.action('UPDATE    artists    SET    ArtworkURL=?    WHERE    ArtistID=?', [image_url, self.id])
        else:
            myDB.action('UPDATE    albums    SET    ArtworkURL=?    WHERE    AlbumID=?', [image_url, self.id])
    if thumb_url:
        if (self.id_type == 'artist'):
            myDB.action('UPDATE    artists    SET    ThumbURL=?    WHERE    ArtistID=?', [thumb_url, self.id])
        else:
            myDB.action('UPDATE    albums    SET    ThumbURL=?    WHERE    AlbumID=?', [thumb_url, self.id])
    if (image_url and (self.query_type == 'artwork')):
        artwork = request.request_content(image_url, timeout=20)
        if artwork:
            if (not os.path.isdir(self.path_to_art_cache)):
                try:
                    os.makedirs(self.path_to_art_cache)
                    os.chmod(self.path_to_art_cache, int(headphones.CONFIG.FOLDER_PERMISSIONS, 8))
                except OSError as e:
                    logger.error('Unable    to    create    artwork    cache    dir.    Error:    %s', e)
                    self.artwork_errors = True
                    self.artwork_url = image_url
            for artwork_file in self.artwork_files:
                try:
                    os.remove(artwork_file)
                except:
                    logger.error('Error    deleting    file    from    the    cache:    %s', artwork_file)
            ext = os.path.splitext(image_url)[1]
            artwork_path = os.path.join(self.path_to_art_cache, (((self.id + '.') + helpers.today()) + ext))
            try:
                with open(artwork_path, 'wb') as f:
                    f.write(artwork)
                os.chmod(artwork_path, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
            except (OSError, IOError) as e:
                logger.error('Unable    to    write    to    the    cache    dir:    %s', e)
                self.artwork_errors = True
                self.artwork_url = image_url
    if (thumb_url and (self.query_type in ['thumb', 'artwork']) and (not (self.thumb_files and self._is_current(self.thumb_files[0])))):
        artwork = request.request_content(thumb_url, timeout=20)
        if artwork:
            if (not os.path.isdir(self.path_to_art_cache)):
                try:
                    os.makedirs(self.path_to_art_cache)
                    os.chmod(self.path_to_art_cache, int(headphones.CONFIG.FOLDER_PERMISSIONS, 8))
                except OSError as e:
                    logger.error(('Unable    to    create    artwork    cache    dir.    Error:    %s' + e))
                    self.thumb_errors = True
                    self.thumb_url = thumb_url
            for thumb_file in self.thumb_files:
                try:
                    os.remove(thumb_file)
                except OSError as e:
                    logger.error('Error    deleting    file    from    the    cache:    %s', thumb_file)
            ext = os.path.splitext(image_url)[1]
            thumb_path = os.path.join(self.path_to_art_cache, (((('T_' + self.id) + '.') + helpers.today()) + ext))
            try:
                with open(thumb_path, 'wb') as f:
                    f.write(artwork)
                os.chmod(thumb_path, int(headphones.CONFIG.FILE_PERMISSIONS, 8))
            except (OSError, IOError) as e:
                logger.error('Unable    to    write    to    the    cache    dir:    %s', e)
                self.thumb_errors = True
                self.thumb_url = image_url
