Пример #1
0
 def get_foreign_id(self, idspace='musicbrainz', cache=True):
     """Get the foreign id for this artist for a specific id space
     
     Args:
     
     Kwargs:
         idspace (str): A string indicating the idspace to fetch a foreign id for.
     
     Returns:
         A foreign ID string
     
     Example:
     
     >>> a = artist.Artist('fabulous')
     >>> a.get_foreign_id('7digital')
     u'7digital:artist:186042'
     >>> 
     """
     if not (cache and ('foreign_ids' in self.cache) and filter(lambda d: d.get('catalog') == idspace, self.cache['foreign_ids'])):
         response = self.get_attribute('profile', bucket=['id:'+idspace])
         foreign_ids = response['artist'].get("foreign_ids", [])
         self.cache['foreign_ids'] = self.cache.get('foreign_ids', []) + foreign_ids
     cval = filter(lambda d: d.get('catalog') == util.map_idspace(idspace),
                   self.cache.get('foreign_ids'))
     return cval[0].get('foreign_id') if cval else None
Пример #2
0
    def get_tracks(self, catalog, cache=True):
        """Get the tracks for a song given a catalog.
        
        Args:
            catalog (str): a string representing the catalog whose track you want to retrieve.
        
        Returns:
            A list of Track dicts.
        
        Example:
            >>> s = song.Song('SOWDASQ12A6310F24F')
            >>> s.get_tracks('7digital')[0]
            {u'catalog': u'7digital',
             u'foreign_id': u'7digital:track:8445818',
             u'id': u'TRJGNNY12903CC625C',
             u'preview_url': u'http://previews.7digital.com/clips/34/8445818.clip.mp3',
             u'release_image': u'http://cdn.7static.com/static/img/sleeveart/00/007/628/0000762838_200.jpg'}
            >>> 

        """
        if not (cache and ('tracks' in self.cache) and (catalog in [td['catalog'] for td in self.cache['tracks']])):
            kwargs = {
                'bucket':['tracks', 'id:%s' % catalog],
            }
                        
            response = self.get_attribute('profile', **kwargs)
            if not 'tracks' in self.cache:
                self.cache['tracks'] = []
            # don't blow away the cache for other catalogs
            potential_tracks = response['songs'][0].get('tracks', [])
            existing_track_ids = [tr['foreign_id'] for tr in self.cache['tracks']]
            new_tds = filter(lambda tr: tr['foreign_id'] not in existing_track_ids, potential_tracks)
            self.cache['tracks'].extend(new_tds)
        return filter(lambda tr: tr['catalog']==util.map_idspace(catalog), self.cache['tracks'])
Пример #3
0
    def get_tracks(self, catalog, cache=True):
        """Get the tracks for a song given a catalog.
        
        Args:
            catalog (str): a string representing the catalog whose track you want to retrieve.
        
        Returns:
            A list of Track dicts.
        
        Example:
            >>> s = song.Song('SOWDASQ12A6310F24F')
            >>> s.get_tracks('7digital')[0]
            {u'catalog': u'7digital',
             u'foreign_id': u'7digital:track:8445818',
             u'id': u'TRJGNNY12903CC625C',
             u'preview_url': u'http://previews.7digital.com/clips/34/8445818.clip.mp3',
             u'release_image': u'http://cdn.7static.com/static/img/sleeveart/00/007/628/0000762838_200.jpg'}
            >>> 

        """
        if not (cache and ("tracks" in self.cache) and (catalog in [td["catalog"] for td in self.cache["tracks"]])):
            kwargs = {"bucket": ["tracks", "id:%s" % catalog]}

            response = self.get_attribute("profile", **kwargs)
            if not "tracks" in self.cache:
                self.cache["tracks"] = []
            # don't blow away the cache for other catalogs
            potential_tracks = response["songs"][0].get("tracks", [])
            existing_track_ids = [tr["foreign_id"] for tr in self.cache["tracks"]]
            new_tds = filter(lambda tr: tr["foreign_id"] not in existing_track_ids, potential_tracks)
            self.cache["tracks"].extend(new_tds)
        return filter(lambda tr: tr["catalog"] == util.map_idspace(catalog), self.cache["tracks"])
Пример #4
0
 def get_foreign_id(self, idspace='', cache=True):
     """Get the foreign id for this song for a specific id space
     
     Args:
     
     Kwargs:
         idspace (str): A string indicating the idspace to fetch a foreign id for.
     
     Returns:
         A foreign ID string
     
     Example:
     
     >>> s = song.Song('SOYRVMR12AF729F8DC')
     >>> s.get_foreign_id('CAGPXKK12BB06F9DE9')
     
     >>> 
     """
     idspace = util.map_idspace(idspace)
     if not (cache and ('foreign_ids' in self.cache) and filter(lambda d: d.get('catalog') == idspace, self.cache['foreign_ids'])):
         response = self.get_attribute('profile', bucket=['id:'+idspace])
         rsongs = response['songs']
         if len(rsongs) == 0:
             return None
         foreign_ids = rsongs[0].get("foreign_ids", [])
         self.cache['foreign_ids'] = self.cache.get('foreign_ids', []) + foreign_ids
     cval = filter(lambda d: d.get('catalog') == idspace, self.cache.get('foreign_ids'))
     return cval[0].get('foreign_id') if cval else None
Пример #5
0
 def get_foreign_id(self, idspace="", cache=True):
     """Get the foreign id for this song for a specific id space
     
     Args:
     
     Kwargs:
         idspace (str): A string indicating the idspace to fetch a foreign id for.
     
     Returns:
         A foreign ID string
     
     Example:
     
     >>> s = song.Song('SOYRVMR12AF729F8DC')
     >>> s.get_foreign_id('CAGPXKK12BB06F9DE9')
     
     >>> 
     """
     idspace = util.map_idspace(idspace)
     if not (
         cache
         and ("foreign_ids" in self.cache)
         and filter(lambda d: d.get("catalog") == idspace, self.cache["foreign_ids"])
     ):
         response = self.get_attribute("profile", bucket=["id:" + idspace])
         rsongs = response["songs"]
         if len(rsongs) == 0:
             return None
         foreign_ids = rsongs[0].get("foreign_ids", [])
         self.cache["foreign_ids"] = self.cache.get("foreign_ids", []) + foreign_ids
     cval = filter(lambda d: d.get("catalog") == idspace, self.cache.get("foreign_ids"))
     return cval[0].get("foreign_id") if cval else None