Пример #1
0
def downloadSpotify():
    with open('/home/pi/2048-Pi-Display/spotify.json', 'w') as outfile:
        ak_token = util.prompt_for_user_token(
            "jc8a1vumj4nofex2isggs9uur",
            "user-read-currently-playing",
            client_id='a362ed228f6f42dda29df88594deacf9',
            client_secret='55924005c1a04aaca88d5a8e3dd39653',
            redirect_uri='https://callback/')
        lo_token = util.prompt_for_user_token(
            "loganjohnson_",
            "user-read-currently-playing",
            client_id='40905780d3124d0c8454937552023133',
            client_secret='6402502d32834e568339004b885ad0a1',
            redirect_uri='https://callback/')

        # Check logan
        sp = Spotify(auth=lo_token)
        result = sp.current_user_playing_track()

        try_aaron = False

        if result is None:
            try_aaron = True
        elif result["is_playing"] == False:
            try_aaron = True

        if try_aaron:
            #print('Nope!')
            sp = Spotify(auth=ak_token)
            result = sp.current_user_playing_track()

        if result is not None:
            if result["item"]["name"] != '':
                try:
                    resp = requests.get(
                        result["item"]["album"]["images"][0]["url"])
                    image_file = io.BytesIO(resp.content)
                    with open('/home/pi/2048-Pi-Display/spotify_image.jpeg',
                              'w') as imagefile:
                        imagefile.write(resp.content)
                        imagefile.close()
                except:
                    print("Couldn't fetch image")
            json.dump(result, outfile, indent=4)
            outfile.close()
Пример #2
0
# Creates a playlist for a user

import pprint
import sys
import os
import subprocess

import spotipy

import util
import spotipy.oauth2 as oauth2


if len(sys.argv) > 2:
    username = sys.argv[1]
    playlist_name = sys.argv[2]
else:
    print "Usage: %s username playlist-name" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username)

if token:
    sp = spotipy.Spotify(auth=token)
    sp.trace = False
    playlists = sp.user_playlist_create(username, playlist_name)
    pprint.pprint(playlists)
else:
    print "Can't get token for", username
Пример #3
0
    print("No existing store")

store[
    'test_id'] = "spotify:user:andrew_walker2:playlist:6VXKlqxCX4ItIHWgFT9I6c"

scope = ScopeBuilder().library().spotify_connect().get_scopes()

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print("Usage: %s username" % (sys.argv[0], ))
    sys.exit()

token = util.prompt_for_user_token(USERNAME,
                                   scope,
                                   client_id=CLIENT_ID,
                                   client_secret=CLIENT_SECRET,
                                   redirect_uri=REDIRECT_URL)

device = None

if token:
    sp = Spotify(auth=token)
    devices = sp.devices()
    devices = devices['devices'][0]['id']
else:
    print("Can't get token for", username)

with open('store.pkl', 'wb') as f:
    pickle.dump(store, f, pickle.HIGHEST_PROTOCOL)
Пример #4
0
from __future__ import print_function  # (at top of module)
import os, sys, time, math, json, pprint, subprocess, requests
import spotipy
from oauth2 import SpotifyClientCredentials
import util
import simplejson as json
from tqdm import tqdm

scope = 'user-library-read, playlist-read-private'
USERNAME = os.getenv('SPOTIFY_USERNAME')
USER_TOKEN = os.getenv('USER_TOKEN')
token = util.prompt_for_user_token(USERNAME, scope)
print(token)

creds = SpotifyClientCredentials()
sp = spotipy.Spotify(client_credentials_manager=creds)
sp.trace = False

url = "https://api.spotify.com/v1/me/tracks?limit=50&offset=0"
headers = {
    "Accept": "application/json",
    "Content-Type": "application/json",
    "Authorization": "Bearer " + USER_TOKEN
}
total = requests.get(url, headers=headers).json()['total']
playlist = []
tempos = {}
offset = 0
for i, num in enumerate(tqdm(range(0, total, 50))):  # offset < total:
    url = "https://api.spotify.com/v1/me/tracks?limit=50&offset={}".format(num)
    songs = requests.get(url, headers=headers).json()['items']
Пример #5
0
# Adds tracks to a playlist

import pprint
import sys

import spotipy
import spotipy.oauth2 as oauth2
import util

scope = 'user-library-read'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0], )
    sys.exit()

token = util.prompt_for_user_token(username, scope)

if token:
    sp = spotipy.Spotify(auth=token)
    sp.trace = False
    results = sp.current_user_saved_tracks()
    pprint.pprint(results)
else:
    print "Can't get token for", username
Пример #6
0
        except NameError:
            response = input("Enter the URL you were redirected to: ")

        print()
        print()

        code = sp_oauth.parse_response_code(response)
        token_info = sp_oauth.get_access_token(code)
    # Auth'ed API request
    if token_info:
        return token_info['access_token']
    else:
        return None


token = prompt_for_user_token(username, scope, client_id, client_secret,
                              redirect_uri)

if token:

    #Step 1. Authenticating Spotipy

    def authenticate_spotify():
        print('...connecting to Spotify')
        sp = spotipy.Spotify(auth=token)
        return sp

#Step 2. Creating a list of your favorite artists

    def aggregate_top_artists(sp):
        print('...getting your top artists')
        top_artists_name = []