def objectFromInternalObj(self, object_type, objs, nameOnly=False): if nameOnly: return ", ".join([obj.name for obj in objs]) try: uris = [SpotifyUtil.gid2uri(object_type, obj.gid) for obj in objs] except: uris = SpotifyUtil.gid2uri(object_type, objs.gid) return self.objectFromURI(uris, asArray=True)
def album_callback(sp, album): print album.name+"\n" uris = [] for track in album.disc[0].track: uris.append(SpotifyUtil.gid2uri("track", track.gid)) sp.metadata_request(uris, track_callback)
def album_metadata_callback(sp, album): print album.name+"\n" uris = [] for track in album.disc[0].track: uris.append(SpotifyUtil.gid2uri("track", track.gid)) sp.track_uri(SpotifyUtil.gid2id(track.gid), "mp3160", track_uri_callback) sp.metadata_request(uris, multi_track_metadata_callback)
def removeTracks(self, tracks): tracks = [tracks] if type(tracks) != list else tracks uris = [] for track in tracks: if track.replaced: uris.append(SpotifyUtil.gid2uri("track", track.old_obj.gid)) else: uris.append(self.getURI()) self.spotify.api.playlist_remove_track(self.getURI(), uris) self.reload_refs()
def isAvailable(self, country=None): country = self.spotify.api.country if country is None else country new_obj = self.spotify.api.recurse_alternatives(self.obj, country=country) if not new_obj: return False else: # invalidate cache self._Cache__cache = {} if not new_obj.HasField("name"): new_obj = self.spotify.api.metadata_request(SpotifyUtil.gid2uri("track", new_obj.gid)) self.old_obj = self.obj self.obj = new_obj self.replaced = True return True
def isAvailable(self, country=None): country = self.spotify.api.country if country is None else country new_obj = self.spotify.api.recurse_alternatives(self.obj, country=country) if not new_obj: return False else: # invalidate cache self._Cache__cache = {} if not new_obj.HasField("name"): new_obj = self.spotify.api.metadata_request( SpotifyUtil.gid2uri("track", new_obj.gid)) self.old_obj = self.obj self.obj = new_obj self.replaced = True return True
def getURI(self): return SpotifyUtil.gid2uri(self.uri_type, self.obj.gid)
def getAlbumURI(self): return SpotifyUtil.gid2uri('album', self.obj.album.gid)