Exemplo n.º 1
0
 def _read_pl_list(self, filename):
     # read and return the contents of the specified playlist
     _req=self.protocolclass.PLPlayListFile()
     _buf=prototypes.buffer(self.getfilecontents(filename))
     _req.readfrombuffer(_buf, logtitle="Read playlist "+filename)
     _songs=[]
     for _item in _req.items:
         _songs.append(common.basename(_item.pathname))
     _entry=playlist.PlaylistEntry()
     _entry.name=common.stripext(common.basename(filename))
     _entry.songs=_songs
     return _entry
Exemplo n.º 2
0
 def _read_pl_list(self, file_name):
     _buf=prototypes.buffer(self.getfilecontents(file_name))
     _pl_index=self.protocolclass.playlistfile()
     _pl_index.readfrombuffer(_buf, logtitle="Read playlist "+file_name)
     _songs=[x.name[self.protocolclass.mp3_dir_len:] for x in _pl_index.items]
     _entry=playlist.PlaylistEntry()
     if file_name.endswith(self.protocolclass.pl_extension):
         _entry.name=file_name[self.protocolclass.pl_dir_len:\
                               -self.protocolclass.pl_extension_len]            
     else:
         _entry.name=file_name[self.protocolclass.pl_dir_len:]
     _entry.songs=_songs
     return _entry
Exemplo n.º 3
0
 def search_track(self, song, artist=None, limit=10):
     query = 'track:' + song
     if artist:
         query = query + ' artist:' + artist
     sp = spotipy.Spotify()
     #sp.trace = True
     results = sp.search(q=query, limit=limit, type='track')
     #print json.dumps(results)
     items = results['tracks']['items']
     hits = []
     if len(items):
         for item in items:
             pe = playlist.PlaylistEntry()
             setattr(pe, 'album', item['album']['name'])
             setattr(pe, 'artist', item['artists'][0]['name'])
             setattr(pe, 'song', item['name'])
             setattr(pe, 'song_id', item['uri'])
             setattr(pe, 'popularity', item['popularity'])
             pe.label = ''
             hits.append(pe)
     return hits
Exemplo n.º 4
0
 def _search_internal(self, text, limit=3):
     payload = {
         'method': 'getSongSearchResults',
         'parameters': {
             'query': text,
             'country': 'us',
             'limit': limit
         },
         'header': {
             'wsKey': self.wsKey
         }
     }
     jr = self._post(payload)
     hits = []
     if 'result' in jr and 'songs' in jr['result']:
         for i, song in enumerate(jr['result']['songs'], start=1):
             if i > limit:
                 break
             pe = playlist.PlaylistEntry()
             for (attr_name, song_field) in self.field_map.iteritems():
                 setattr(pe, attr_name, song[song_field])
             pe.label = ''
             hits.append(pe)
     return hits