def search(artist, song_name, include=None): if include is None: include = [song_name, artist] response = pandora_api().search(' '.join(include)) found_songs = response['songs'] backup, backup_confidence = None, 0 for result in found_songs: if result['songName'] == song_name and result['artistName'] == artist: return Pandora_Track(result) else: confidence = result.get('score', 0) if confidence > backup_confidence: backup = Pandora_Track(result) backup_confidence = confidence if backup is None: include.pop() if len(include): return Pandora_Track.search(artist, song_name, include) else: print u"Failed to match {} - {}".format(artist, song_name) return None else: print u"Matched {} - {} to backup {} with confidence {}".format( artist, song_name, backup, backup_confidence) return backup
def _sync_seeds(self): existing_seeds = [] for current_seed in self._data['music'].get('songs', []): key = Pandora_Track.make_key(current_seed) if not self._track_map.is_still_valid(current_seed): print u"Removing seed: {}".format(key) pandora_api().remove_seed(current_seed['seedId']) else: existing_seeds.append(key) for new_seed in self._track_map: key = Pandora_Track.make_key(new_seed._data) if key not in existing_seeds: print u"Adding seed: {}".format(key) pandora_api().add_seed(self._data.get('stationToken'), new_seed._data['musicToken']) else: #print "Keeping seed: {}".format(key) continue
def get_or_create(languages, emotion, seed_tracks, recreate=False): station_name = u"Maze_{}_{}".format(''.join(languages), emotion) pandora_station = None response = pandora_api().get_station_list() for station in response.get('stations', []): if station.get('stationName') == station_name: pandora_station = station break if recreate: pandora_api().delete_station(pandora_station.get('stationToken')) pandora_station = None track_map = Pandora_Track_Map(seed_tracks) if pandora_station is None: seed_track = track_map.get_one() if not seed_track: raise SeedsNotFound("This stations seeds could not be found on Pandora") pandora_station = pandora_api().create_station(musicToken=seed_track.get_music_token()) pandora_api().rename_station(pandora_station.get('stationToken'), station_name) data = pandora_api().get_station(pandora_station.get('stationToken')) return Pandora_Station(data, track_map)
def get_playlist(self): response = pandora_api().get_playlist(self._data.get('stationToken')) return response.get('items', [])