Example #1
0
 def generate_catalog_data(self):
     """Generate a list of songs to update our Echo Nest Catalog with"""
     data = []
     songs = set()
     ids = set()
     progress = ProgressBar(widgets=['Scanning Library: ',
         LibraryProgress(), ' songs'])
     for song in progress(self.walk_library(self.library)):
         try:
             artist = song['artist'][0]
             title = song['title'][0]
         except (KeyError, IndexError):
             self.missing_tags += 1
             continue
         if song.get('bpm'):
             self.bpm_exists += 1
             continue
         if artist and title:
             id = sha.new(('%s-%s' % (artist, title))
                     .encode('utf-8', errors='ignore')).hexdigest()
             if song.filename in songs or id in ids:
                 self.song_dupe += 1
                 continue
             songs.add(song.filename)
             ids.add(id)
             data.append({
                 'action': 'update',
                 'item': {
                     'url': song.filename,
                     'item_id': id.encode('utf-8'),
                     'artist_name': artist.encode('utf-8'),
                     'song_name': title.encode('utf-8'),
                     }})
     return data
Example #2
0
def identify_song(song, mpdc):
    artist = song.get('artist')
    title = song.get('title')

    if not (artist or title):
        return  #TODO: try harder

    results = pyechonest.song.search(artist=artist, title=title)
    if results:
        return results[0]
    logger.warn(u'No results for: {} - {}'.format(artist,title))

    # try stripping weird characters from the names
    artist = re.sub(r'([^\s\w]|_)+', '', artist)
    title = re.sub(r'([^\s\w]|_)+', '', title)

    results = pyechonest.song.search(artist=artist, title=title)
    if results:
        return results[0]
    logger.warn(u'No results for: {} - {}'.format(artist,title))
Example #3
0
    def fetch_song(self, item):
        """Try all methods to get a matching song object from the
        EchoNest. If no method succeeds, return None.
        """
        # There are four different ways to get a song. Each method is a
        # callable that takes the Item as an argument.
        methods = [self.profile, self.search]
        if self.config['upload']:
            methods.append(self.analyze)

        # Try each method in turn.
        for method in methods:
            song = method(item)
            if song:
                self._log.debug(u'got song through {0}: {1} [{2}]',
                                method.__name__,
                                item,
                                song.get('duration'),
                                )
                return song
Example #4
0
    def fetch_song(self, item):
        """Try all methods to get a matching song object from the
        EchoNest. If no method succeeds, return None.
        """
        # There are four different ways to get a song. Each method is a
        # callable that takes the Item as an argument.
        methods = [self.profile, self.search]
        if self.config['upload']:
            methods.append(self.analyze)

        # Try each method in turn.
        for method in methods:
            song = method(item)
            if song:
                self._log.debug(u'got song through {0}: {1} [{2}]',
                                method.__name__,
                                item,
                                song.get('duration'),
                                )
                return song
Example #5
0
def prev_songs(mpdc, num=5):
    "Get the last songs listened to"

    current_song = mpdc.currentsong()

    if not current_song:
        return []

    current_pos = int(current_song.get('pos'))
    queue = mpdc.playlistinfo()
    queue = filter(lambda x: not x.get('file', '').startswith(settings.dj_bumps_dir), queue)  #FIXME: bumps filter needs dry
    queue_dict = dict([ (int(song.get('pos')), song) for song in queue ])
    sample = []
    i = current_pos
    while len(sample) < num and i >= 0:
        song = queue_dict.get(i)
        if song:
            sample.append(song)
        i -= 1

    return sample