def is_track_available(self, track, country): allowed_countries = [] forbidden_countries = [] available = False for restriction in track.restriction: allowed_str = restriction.countries_allowed allowed_countries += [allowed_str[i : i + 2] for i in range(0, len(allowed_str), 2)] forbidden_str = restriction.countries_forbidden forbidden_countries += [forbidden_str[i : i + 2] for i in range(0, len(forbidden_str), 2)] allowed = not restriction.HasField("countries_allowed") or country in allowed_countries forbidden = self.country in forbidden_countries and len(forbidden_countries) > 0 if country in allowed_countries and country in forbidden_countries: allowed = True forbidden = False # guessing at names here, corrections welcome account_type_map = {"premium": 1, "unlimited": 1, "free": 0} applicable = account_type_map[self.account_type] in restriction.catalogue available = allowed and not forbidden and applicable if available: break if available: logger.warning(utils.gid2uri("track", track.gid) + " is available!") else: logger.warning(utils.gid2uri("track", track.gid) + " is NOT available!") return available
def objectFromInternalObj(self, object_type, objs, nameOnly=False): if nameOnly: return ", ".join([obj.name for obj in objs]) try: uris = [utils.gid2uri(object_type, obj.gid) for obj in objs] except: uris = utils.gid2uri(object_type, objs.gid) return self.objectFromURI(uris, asArray=True)
def is_track_available(self, track, country): allowed_countries = [] forbidden_countries = [] available = False for restriction in track.restriction: allowed_str = restriction.countries_allowed allowed_countries += [ allowed_str[i:i + 2] for i in range(0, len(allowed_str), 2) ] forbidden_str = restriction.countries_forbidden forbidden_countries += [ forbidden_str[i:i + 2] for i in range(0, len(forbidden_str), 2) ] allowed = not restriction.HasField( "countries_allowed") or country in allowed_countries forbidden = self.country in forbidden_countries and len( forbidden_countries) > 0 if country in allowed_countries and country in forbidden_countries: allowed = True forbidden = False # guessing at names here, corrections welcome account_type_map = {"premium": 1, "unlimited": 1, "free": 0} applicable = account_type_map[ self.account_type] in restriction.catalogue available = allowed and not forbidden and applicable if available: break if available: logger.warning( utils.gid2uri("track", track.gid) + " is available!") else: logger.warning( utils.gid2uri("track", track.gid) + " is NOT available!") return available
def removeTracks(self, tracks): tracks = [tracks] if type(tracks) != list else tracks uris = [] for track in tracks: if track.replaced: uris.append(utils.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( utils.gid2uri("track", new_obj.gid)) self.old_obj = self.obj self.obj = new_obj self.replaced = True return True
if action == "track": uri = sys.argv[4] if len( sys.argv) > 4 else "spotify:track:3IKSCoHEblCE60IKr4SVNd" track = sp.metadata_request(uri) print track.name elif action == "album": uri = sys.argv[4] if len( sys.argv) > 4 else "spotify:album:3OmHoatMS34vM7ZKb4WCY3" album = sp.metadata_request(uri) print album.name + " - " + album.artist[0].name + "\n" uris = [utils.gid2uri("track", track.gid) for track in album.disc[0].track] tracks = sp.metadata_request(uris) for track in tracks: print track.name elif action == "playlists": username = sys.argv[4] if len(sys.argv) > 4 else sp.username playlist_uris = [ playlist.uri for playlist in sp.playlists_request(username).contents.items ] playlists = [ sp.playlist_request(playlist_uri) for playlist_uri in playlist_uris ]
def album_callback(sp, album): print album.name + " - " + album.artist[0].name + "\n" uris = [utils.gid2uri("track", track.gid) for track in album.disc[0].track] sp.metadata_request(uris, track_callback)
def getURI(self): return utils.gid2uri(self.uri_type, self.obj.gid)
print "\n" if action == "track": uri = sys.argv[4] if len(sys.argv) > 4 else "spotify:track:3IKSCoHEblCE60IKr4SVNd" track = sp.metadata_request(uri) print track.name elif action == "album": uri = sys.argv[4] if len(sys.argv) > 4 else "spotify:album:3OmHoatMS34vM7ZKb4WCY3" album = sp.metadata_request(uri) print album.name+" - "+album.artist[0].name+"\n" uris = [utils.gid2uri("track", track.gid) for track in album.disc[0].track] tracks = sp.metadata_request(uris) for track in tracks: print track.name elif action == "playlists": username = sys.argv[4] if len(sys.argv) > 4 else sp.username playlist_uris = [playlist.uri for playlist in sp.playlists_request(username).contents.items] playlists = [sp.playlist_request(playlist_uri) for playlist_uri in playlist_uris] for playlist in playlists: display_playlist(playlist) elif action == "playlist": uri = sys.argv[4] if len(sys.argv) > 4 else "spotify:user:topsify:playlist:1QM1qz09ZzsAPiXphF1l4S"