def __init__(self, title='unknown', songs=[], artist=None): Playlist.__init__(self, songs, 0) self.title = title self.artist = artist self.artwork = None self.placeholder = None self.item = None
def create_playlist(self, name, description, add_random_torrents=False): playlist = Playlist(len(self.playlists) + 1, name, description) if add_random_torrents: picked_torrents = sample(self.torrents, randint(0, min(20, len(self.torrents)))) for torrent in picked_torrents: playlist.add_torrent(torrent) self.playlists.add(playlist)
async def save(self, ctx: commands.Context, *, title: str = None): """Sauvegarde une playliste.""" if not title: raise Exception("Vous devez préciser un nom pour votre playliste.") playlist_id = title music = self.bot.get_cog("Music") Playlist.create(ctx, self.playlists[playlist_id], title, music) self.user_playlists[ctx.author.id] = playlist_id msg = "La playliste a été sauvegardée." return await ctx.send(msg)
def create_playlist(): backup_playlist_arg = request.args.get('backup_id') playlist_query = Playlist.objects(backup_playlist=backup_playlist_arg).first() if playlist_query: result = str(playlist_query.playlist_hash) else: playlist = Playlist(backup_playlist=backup_playlist_arg).save() playlist_query = Playlist.objects(backup_playlist=backup_playlist_arg).first() result = playlist_query.playlist_hash return jsonify(result=result)
def get_playlist(): playlist_arg = request.args.get('playlist_hash') playlist = Playlist.objects(playlist_hash=playlist_arg).first() if playlist.currently_playing: currently_playing = dict( adder=playlist.currently_playing['adder'], artist=playlist.currently_playing['artist'], album=playlist.currently_playing['album'], track=playlist.currently_playing['track'], added=playlist.currently_playing['added'], vote_rating=playlist.currently_playing['vote_rating'], voters=playlist.currently_playing['voters'], uri=playlist.currently_playing['uri']) else: currently_playing = dict( adder=None, artist=None, album=None, track=None, added=None, vote_rating=None, voters=None, uri=None) result = dict( playlist=str(playlist.id), updated=playlist.updated.strftime('%Y-%M-%d %H:%M:%S'), currently_playing=currently_playing, tracks=playlist.tracks) return jsonify(result=result)
def callback(): # Auth Step 4: Requests refresh and access tokens auth_token = request.args['code'] code_payload = { "grant_type": "authorization_code", "code": str(auth_token), "redirect_uri": REDIRECT_URI, 'client_id': CLIENT_ID, 'client_secret': CLIENT_SECRET, } post_request = requests.post(SPOTIFY_TOKEN_URL, data=code_payload) # Auth Step 5: Tokens are Returned to Application response_data = json.loads(post_request.text) access_token = response_data["access_token"] refresh_token = response_data["refresh_token"] token_type = response_data["token_type"] expires_in = response_data["expires_in"] # Auth Step 6: Use the access token to access Spotify API authorization_header = {"Authorization": "Bearer {}".format(access_token)} # Get profile data user_profile_api_endpoint = "{}/me".format(SPOTIFY_API_URL) profile_response = requests.get(user_profile_api_endpoint, headers=authorization_header) profile_data = json.loads(profile_response.text) user = User(spotify_id=profile_data['id'], name=profile_data['display_name'], jwt=access_token) user_check = User.query.filter_by(spotify_id=profile_data['id']).first() # Updates DB if not user_check: user.save() else: user_check.name = user.name user_check.spotify_id = user.spotify_id user_check.jwt = user.jwt user_check.save() user = user_check login_user(user) # Get user playlist data playlist_api_endpoint = "{}/playlists".format(profile_data["href"]) playlists_response = requests.get(playlist_api_endpoint, headers=authorization_header) playlist_data = json.loads(playlists_response.text) playlists = [] for item in playlist_data["items"]: playlists.append( Playlist(spotify_id=item['id'], name=item['name'], image=item['images'][0]['url']).to_json()) session['playlists'] = playlists return redirect(url_for('web.like'))
def next_track(): playlist_arg = request.args.get('playlist_hash') playlist = Playlist.objects(playlist_hash=playlist_arg).first() next_track = playlist.get_next_track() result = dict(track=next_track['track'], artist=next_track['artist'], album=next_track['album'], uri=next_track['uri']) playlist.update_que() return jsonify(result=result)
def get_playlist(self, ctx: commands.Context, title: str = None): """Return a playlist with an id.""" if not ctx.author.id in self.user_playlists: raise Exception( "Utilisez 'playlist select [title]' pour sélectionner une playliste." ) playlist_id = self.user_playlists[ctx.author.id] if not playlist_id in self.playlists: raise Exception(f"La playliste d'id {playlist_id} n'existe pas.") return Playlist(self.playlists[playlist_id])
def select(id): playlist = None sql = "SELECT * FROM playlists WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: league_type = league_type_repo.select(result['league_type_id']) playlist = Playlist(league_type, result['round_no']) return playlist
def add_vote(): playlist_arg = request.args.get('playlist_hash') uri_arg = request.args.get('uri') facebook_id_arg = request.args.get('facebook_id') vote_arg = request.args.get('vote') playlist = Playlist.objects(playlist_hash=playlist_arg).first() playlist.vote(uri_arg, facebook_id_arg, vote_arg) playlist.update_que() return jsonify(result='Voted on track.')
def select_all(): playlists = [] sql = "SELECT * FROM playlists" results = run_sql(sql) for result in results: league_type = league_type_repo.select(result['league_type_id']) playlist = Playlist(league_type, result['round_no']) playlists.append(playlist) return playlists
def url_add_track(): playlist_arg = request.args.get('playlist_hash') facebook_id_arg = request.args.get('facebook_id') track_arg = request.args.get('track') artist_arg = request.args.get('artist') album_arg = request.args.get('album') uri_arg = request.args.get('uri') print 'track_arg', track_arg playlist = Playlist.objects(playlist_hash=playlist_arg).first() playlist.add_track(facebook_id_arg, track_arg, artist_arg, album_arg, uri_arg) playlist.update_que() return jsonify(result='Added track.')
def set_playlist(self, name, description, assets): self.kv.set_playlist(name, Playlist(name, description, assets))
def get_playlist_from_id(self, playlist_id: str): """Return a playlist given its id.""" if playlist_id in self.playlists: return Playlist(self.playlists[playlist_id]) else: raise Exception(f"La playliste d'id {playlist_id} n'existe pas.")
def check_update(): playlist_arg = request.args.get('playlist_hash') playlist = Playlist.objects(playlist_hash=playlist_arg).first() result = playlist.updated.strftime('%Y-%M-%d %H:%M:%S') return jsonify(result=result)