def profile():
    if 'auth_header' in session:
        auth_header = session['auth_header']
        # get profile data
        profile_data = spotify.get_users_profile(auth_header)

        # get user playlist data
        playlist_data = spotify.get_users_playlists(auth_header)

        # get user recently played tracks
        recently_played = spotify.get_users_recently_played(auth_header)

        # get user top artist
        top_artists_data = spotify.get_users_top_artists(auth_header)

        # get user top tracks
        top_tracks_data = spotify.get_users_top_tracks(auth_header)

        if valid_token(recently_played):
            return render_template("profile.html",
                                   user=profile_data,
                                   playlists=playlist_data["items"],
                                   recently_played=recently_played["items"],
                                   top_artists=top_artists_data["items"],
                                   top_tracks=top_tracks_data["items"])

    return render_template('profile.html')
Beispiel #2
0
def make_filter(playlist_id):
    if 'auth_header' in session:
        session['playlist_id'] = playlist_id
        auth_header = session['auth_header']
        # get profile data
        profile_data = spotify.get_users_profile(auth_header)
        # get playlist data
        playlist_data = spotify.get_playlist(auth_header, playlist_id)

        if valid_token(playlist_data):
            return render_template("filter.html",
                                   user=profile_data,
                                   playlist=playlist_data)
Beispiel #3
0
def profile():
    if 'auth_header' in session:
        auth_header = session['auth_header']
        # get profile data
        profile_data = spotify.get_users_profile(auth_header)

        # get user playlist data
        playlist_data = spotify.get_users_playlists(auth_header)

        if valid_token(playlist_data):
            return render_template("profile.html",
                                   user=profile_data,
                                   playlists=playlist_data["items"])

    return render_template('profile.html')
Beispiel #4
0
def profile():
    if 'auth_header' in session:
        auth_header = session['auth_header']
        profile_data = spotify.get_users_profile(auth_header)

        playlist_data = spotify.get_users_playlists(auth_header)

        recently_played = spotify.get_users_recently_played(auth_header)

        if valid_token(recently_played):
            return render_template(
                'profile.html',
                user=profile_data,
                playlists=playlist_data,
                recently_played=recently_played['items'][:10],
                title=profile_data['display_name'])

        return render_template('profile.html',
                               user=profile_data,
                               title=profile_data['display_name'])

    return redirect(url_for('root'))
Beispiel #5
0
def startFilter():
    if 'auth_header' in session and 'playlist_id' in session:
        max_tempo = float(session['max_input'])
        min_tempo = float(session['min_input'])
        auth_header = session['auth_header']
        playlist_id = session['playlist_id']
        # get profile data
        profile_data = spotify.get_users_profile(auth_header)

        playlist_tracks = spotify.get_playlist_tracks(auth_header, playlist_id)

        offset = 100
        #pages > 100 elements
        while playlist_tracks['next'] != None:
            offset += 100
            for tracks in playlist_tracks['items']:
                track_id = tracks['track']['id']
                print(tracks['track']['name'])
                track_analysis = spotify.get_track_analysis(
                    auth_header, track_id)
                track_tempo = track_analysis['tempo']
                if (track_tempo > min_tempo and track_tempo < max_tempo):
                    print(track_analysis['tempo'])
            playlist_tracks = spotify.get_playlist_tracks(auth_header,
                                                          playlist_id,
                                                          offset=offset)
        #pages < 100 elements
        for tracks in playlist_tracks['items']:
            track_id = tracks['track']['id']
            name = tracks['track']['name']
            print(name)
            track_analysis = spotify.get_track_analysis(auth_header, track_id)
            track_tempo = track_analysis['tempo']
            if (track_tempo > min_tempo and track_tempo < max_tempo):
                print(track_analysis['tempo'])

        if valid_token(profile_data):
            return render_template("startFilter.html", user=profile_data)
Beispiel #6
0
def profile(time_range):
    if time_range not in ['long_term', 'medium_term', 'short_term']:
        print('invalid type')
        return None
    if 'auth_header' in session:
        auth_header = session['auth_header']
        # get profile data
        profile_data = spotify.get_users_profile(auth_header)
        # get users top artists
        top_artists = spotify.get_users_top(auth_header, 'artists', time_range,
                                            50)
        for artist in top_artists["items"]:
            if not artist['images']:
                artist['images'] = [{
                    'height': 640,
                    'url': 'http://bit.ly/2nXRRfX',
                    'width': 640
                }, {
                    'height': 300,
                    'url': 'http://bit.ly/2nXRRfX',
                    'width': 300
                }, {
                    'height': 64,
                    'url': 'http://bit.ly/2nXRRfX',
                    'width': 64
                }]
        # get users top tracks
        top_tracks = spotify.get_users_top(auth_header, 'tracks', time_range,
                                           50)
        if valid_token(top_artists):
            return render_template("profile.html",
                                   user=profile_data,
                                   top_artists=top_artists["items"],
                                   top_tracks=top_tracks["items"])
            #top_artists=[])

    return render_template('profile.html')