示例#1
0
def main():
    args = my_arg_parser()

    parent_dir = os.path.abspath(os.pardir)
    config_file = os.path.join(parent_dir, "config.ini")
    config = ConfigParser.ConfigParser()
    config.read(config_file)

    spotify_client_id = config.get('spotify', 'client_id')
    print "spotify_client_id"
    spotify_client_secret = config.get('spotify', 'client_secret')
    print "spotify_client_secret"
    spotify_token_url = config.get('spotify', 'token_url')
    print "spotify_token_url"
    token = sp.get_spotify_oauth_token(spotify_client_id, spotify_client_secret, spotify_token_url)
    print "get get_spotify_oauth_token"
    playlists = sp.get_user_playlists(token, args.username)
    print "get_user_playlists"
    track_urls = sp.get_playlist_track_urls(playlists, args.username)
    print "get_playlist_track_urls"
    track_data = sp.get_tracks(track_urls, token)
    print "get_tracks"
    parsed_data, json_data = sp.parse_track_data(track_data)
    print "parse_track_data"
    output_file = "track_data.json"
    output = os.path.abspath(os.path.realpath(output_file))

    sp.save_json_data(json_data, output)
    print "save_json_data"
    sorted_data = sp.sort_track_data(parsed_data)
    print "sort_track_data"
    sp.create_bar_chart(sorted_data)
    print "create_bar_chart"
示例#2
0
def add_spotify_songs():
    songs = spotify.get_tracks()
    for song in songs:
        add_song(title=song[0],
                 album=song[1],
                 artist=song[2],
                 duration=song[3])
    return True
示例#3
0
def get_songs():
    access_token = spotify.get_spotify_token()
    songs = spotify.get_tracks(access_token, '3fCn2nqmX6ZnYUe9uoty98')

    threads = []

    for song in songs:
        thread = Thread(target=download_song, args=(song,))
        thread.start()
        threads.append(thread)

    for thread in threads:
        thread.join()
示例#4
0
def find_song(search_words, sentiment):
    spotify_data = spotify.get_tracks(spotify_token, search_words, 20)

    if len(spotify_data) < 1:
        return None

    selected_song = spotify_data[0]
    for song in spotify_data:
        text = lyrics.get_lyrics(song["artist"], song["name"])
        song_sentiment = sentiments.analyze_sentiment(text)

        if song_sentiment is None:
            continue

        if abs(song_sentiment - sentiment) <= SENTIMENT_THRESHOLD:
            selected_song = song
            break

    return selected_song["url"]
示例#5
0
def main():
    args = parse_args()

    # load your config.ini file
    parent_dir = os.path.dirname(os.path.dirname(__file__))
    config_file = os.path.join(parent_dir, "config.ini")
    config = ConfigParser.ConfigParser()
    config.read(config_file)

    # parse out spotify configuration
    spotify_client_id = config.get('spotify', 'client_id')
    spotify_client_secret = config.get('spotify', 'client_secret')
    spotify_token_url = config.get('spotify', 'token_url')

    # Get an OAuth token from Spotify
    token = sp.get_spotify_oauth_token(spotify_client_id,
                                       spotify_client_secret,
                                       spotify_token_url)

    # get the desired user's list of playlists
    playlists = sp.get_user_playlists(token, args.username)

    # parse out the tracks URL for each playlist
    track_urls = sp.get_playlist_track_urls(playlists, args.username)

    # request track data from the tracks URLs
    track_data = sp.get_tracks(track_urls, token)

    # parse track data into parsed_data and json_data
    parsed_data, json_data = sp.parse_track_data(track_data)

    # save the json_data for future use with EchoNest
    output_file_name = config.get('spotify', 'output_file_name')
    output_file = os.path.abspath(os.path.realpath(output_file_name))
    sp.save_json_data(json_data, output_file)

    # sort the parsed_data of tracks into their appropriate buckets
    sorted_data = sp.sort_track_data(parsed_data)

    # create a bar chart with the sorted_data!
    sp.create_bar_chart(sorted_data)
def load(path):
    spotify = util.get_spotify_db()
    ids = []
    data = None

    with open(path) as f:
        data = json.loads(f.read())
        ids = []
        creds = get_credentials()

        for track in data:
            if not "trackId" in track:
                continue

            ids.append(track["trackId"])

        ids = list(set(ids))

    full_tracks = get_tracks(ids, creds)
    track_by_id = {}
    for f_track in full_tracks:
        track_by_id[f_track["id"]] = f_track
    print("GOT {} tracks".format(len(full_tracks)))

    states = []
    for track in data:
        if "trackId" not in track:
            continue
        state = {
            "played_at": track["time"],
            "track": track_by_id[track["trackId"]]
        }

        states.append(state)

    spotify.tracks.insert_many(states)
示例#7
0
def main():
    args = parse_args()

    if args.debug:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)

    # Config Shit
    parent_dir = os.path.dirname(os.path.dirname(__file__))
    config_file = os.path.join(parent_dir, "config.ini")
    config = ConfigParser.ConfigParser()
    config.read(config_file)

    echonest_api_key = config.get('echonest', 'api_key')
    spotify_client_id = config.get('spotify', 'client_id')
    spotify_client_secret = config.get('spotify', 'client_secret')
    spotify_token_url = config.get('spotify', 'token_url')
    github_oauth = config.get('github', 'oauth')
    artist_data_file = config.get('echonest', 'output_file_name')
    output_file_name = config.get('echonest', 'output_file_name')
    json_input = config.get('spotify', 'output_file_name')
    artist_json = json.load(open(artist_data_file, 'r'))

    # Spotify API
    log.debug("Getting a Spotify OAuth Token with your client ID")
    token = sp.get_spotify_oauth_token(spotify_client_id,
                                       spotify_client_secret,
                                       spotify_token_url)

    log.debug("Getting public playlists for {0}".format(args.spotify_user))
    playlists = sp.get_user_playlists(token, args.spotify_user)

    log.debug("Parsing out track URLs from each playlist")
    track_urls = sp.get_playlist_track_urls(playlists, args.spotify_user)
    log.debug("Parsed tracks from {0} playlists.".format(len(track_urls)))

    log.debug("Fetching track data for each track URL.")
    track_data = sp.get_tracks(track_urls, token)
    log.debug("Received track data on {0} playlists.".format(len(track_data)))

    log.debug("Parsing track data, and creating & saving a JSON file.")
    parsed_data, json_data = sp.parse_track_data(track_data)

    output_file_name = config.get('spotify', 'output_file_name')
    output_file = os.path.abspath(os.path.realpath(output_file_name))
    sp.save_json_data(json_data, output_file)
    log.debug("Saved the JSON file at: '{0}'".format(output_file))

    log.debug("Sorting parsed track data.")
    sorted_data = sp.sort_track_data(parsed_data)

    log.debug("Attempting to create an awesome bar chart...")
    sp.create_bar_chart(sorted_data)
    current_dir = os.path.abspath(os.path.dirname(__file__))
    log.debug("Chart saved as 'Music Timeline.png' in '{0}'.".format(
              current_dir))
    log.debug("Finished getting playlists from Spotify!")

    # EchoNest API
    en = pyen.Pyen(echonest_api_key)

    playlist_json = json.load(open(json_input, "r"))

    unique_artists = ec.deduplicate_artists(playlist_json)

    log.debug("Fetching artist information for {0} artists.".format(
              len(unique_artists)))
    log.debug("Perhaps go get some coffee, or a have a bathroom break,"
              "this may take a while depending on how many artists "
              "there are :D.")
    artists = ec.get_artists_information(en, unique_artists)

    log.debug("Creating JSON output of artist information.")
    json_output = ec.create_json(artists)

    output_file = os.path.abspath(os.path.realpath(output_file_name))

    log.debug("Saving JSON output to {0}.".format(output_file))
    ec.save_json(json_output, output_file)

    # GitHub API
    log.debug("Creating a GeoJSON file with artist info from {0}".format(
              artist_data_file))
    geojson_file = gh.create_geojson(artist_json)

    if github_oauth:
        log.debug("Logging you into GitHub...")
        try:
            gh_auth = gh.login_github(github_oauth)
            log.debug("Successfully logged into GitHub! \n"
                      "Posting the gist to your Account.")
        except gh.GithubError:
            gh_auth = None
            log.info("Could not log you in. Will post your Gist anonymously.")
    else:
        gh_auth = None

    gist_url = gh.post_gist_github(geojson_file, gh_auth, args.gist_desc)

    log.info("Your gist has been posted! Navigating you to: {0}".format(
             gist_url))
    webbrowser.open(gist_url)
示例#8
0
def main():
    args = parse_args()

    # load your config.ini file
    parent_dir = os.path.dirname(os.path.dirname(__file__))
    config_file = os.path.join(parent_dir, "config.ini")
    config = ConfigParser.ConfigParser()
    config.read(config_file)

    # parse out spotify configuration
    spotify_client_id = config.get('spotify', 'client_id')
    spotify_client_secret = config.get('spotify', 'client_secret')
    spotify_token_url = config.get('spotify', 'token_url')

    # Get an OAuth token from Spotify
    token = sp.get_spotify_oauth_token(spotify_client_id,
                                       spotify_client_secret,
                                       spotify_token_url)

    # get the desired user's list of playlists
    playlists = sp.get_user_playlists(token, args.username)

    # parse out the tracks URL for each playlist
    track_urls = sp.get_playlist_track_urls(playlists, args.username)

    # request track data from the tracks URLs
    track_data = sp.get_tracks(track_urls, token)

    # parse track data into parsed_data and json_data
    parsed_data, json_data = sp.parse_track_data(track_data)

    # save the json_data for future use with EchoNest
    output_file_name = config.get('spotify', 'output_file_name')
    output_file = os.path.abspath(os.path.realpath(output_file_name))
    sp.save_json_data(json_data, output_file)

    # sort the parsed_data of tracks into their appropriate buckets
    sorted_data = sp.sort_track_data(parsed_data)

    # create a bar chart with the sorted_data!
    sp.create_bar_chart(sorted_data)

    # EchoNest API

    # Grab your EchoNest API key from your config
    echonest_api_key = config.get('echonest', 'api_key')

    # Grab where you saved the track data from Spotify
    output_file_name = config.get('echonest', 'output_file_name')
    json_input = config.get('spotify', 'output_file_name')

    # instantiate the EchoNest APY
    en = pyen.Pyen(echonest_api_key)

    # Open the track data we saved from Spotify
    playlist_json = json.load(open(json_input, "r"))

    # Deduplicate the artists
    unique_artists = ec.deduplicate_artists(playlist_json)

    # Get our artist information
    artists = ec.get_artists_information(en, unique_artists)

    # Create a JSON-like object with our artist information
    json_output = ec.create_json(artists)

    # Define where the JSON will be saved based off of our config
    output_file = os.path.abspath(os.path.realpath(output_file_name))

    # Save the data into a JSON file
    ec.save_json(json_output, output_file)
示例#9
0
def main():
    args = parse_args()

    log = logging.getLogger('pyladies_api')
    stream = logging.StreamHandler()
    log.addHandler(stream)

    if args.debug:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)

    # load your config.ini file
    parent_dir = os.path.dirname(os.path.dirname(__file__))
    config_file = os.path.join(parent_dir, "config.ini")
    config = ConfigParser.ConfigParser()
    config.read(config_file)

    # parse out spotify configuration
    spotify_client_id = config.get('spotify', 'client_id')
    spotify_client_secret = config.get('spotify', 'client_secret')
    spotify_token_url = config.get('spotify', 'token_url')

    # Get an OAuth token from Spotify
    token = sp.get_spotify_oauth_token(spotify_client_id,
                                       spotify_client_secret,
                                       spotify_token_url)

    # get the desired user's list of playlists
    playlists = sp.get_user_playlists(token, args.username)

    # parse out the tracks URL for each playlist
    track_urls = sp.get_playlist_track_urls(playlists, args.username)

    # request track data from the tracks URLs
    track_data = sp.get_tracks(track_urls, token)

    # parse track data into parsed_data and json_data
    parsed_data, json_data = sp.parse_track_data(track_data)

    # save the json_data for future use with EchoNest
    output_file_name = config.get('spotify', 'output_file_name')
    output_file = os.path.abspath(os.path.realpath(output_file_name))
    sp.save_json_data(json_data, output_file)

    # sort the parsed_data of tracks into their appropriate buckets
    sorted_data = sp.sort_track_data(parsed_data)

    # create a bar chart with the sorted_data!
    sp.create_bar_chart(sorted_data)

    # EchoNest API

    # Grab your EchoNest API key from your config
    echonest_api_key = config.get('echonest', 'api_key')

    # Grab where you saved the track data from Spotify
    output_file_name = config.get('echonest', 'output_file_name')
    json_input = config.get('spotify', 'output_file_name')

    # instantiate the EchoNest APY
    en = pyen.Pyen(echonest_api_key)

    # Open the track data we saved from Spotify
    playlist_json = json.load(open(json_input, "r"))

    # Deduplicate the artists
    unique_artists = ec.deduplicate_artists(playlist_json)

    # Get our artist information
    artists = ec.get_artists_information(en, unique_artists)

    # Create a JSON-like object with our artist information
    json_output = ec.create_json(artists)

    # Define where the JSON will be saved based off of our config
    output_file = os.path.abspath(os.path.realpath(output_file_name))

    # Save the data into a JSON file
    ec.save_json(json_output, output_file)

    ###
    # GitHub API
    ###

    # Load GitHub configuration
    github_oauth = config.get('github', 'oauth')

    # Grab the file that we saved with echonest earlier
    artist_data_file = config.get('echonest', 'output_file_name')

    # load this file so we can read it
    artist_json = json.load(open(artist_data_file, 'r'))

    # Create a GeoJSON-like object with our artist information
    geojson_output = gh.create_geojson(artist_json)

    # Either log into GitHub if you do have a GitHub account
    if github_oauth:
        try:
            gh_auth = gh.login_github(github_oauth)
        except gh.GithubError:
            gh_auth = None

    # Or if no account, then set the auth to None
    else:
        gh_auth = None

    # POST the GeoJSON to GitHub
    gist_url = gh.post_gist_github(geojson_output, gh_auth, args.gist_desc)

    # Open the default system browser to the gist URL that we just created
    webbrowser.open(gist_url)
示例#10
0
import spotify
import encoder

#spotify:playlist:7pcXAz0de0NgQ6Q05okOnb


extracted = ""
offset = 0

while True:
    tracks = spotify.get_tracks("7pcXAz0de0NgQ6Q05okOnb",offset=offset)["items"]
    if len(tracks) == 0:
        break
    for track in tracks:
        extracted +=track["track"]["name"][0]
    offset = offset + len(tracks)

open("ext.zip","wb").write(encoder.base32_decode(extracted))