Esempio n. 1
0
File: twt.py Progetto: jkwok91/dumb
def getFave(platform):
  if platform == 'sc':
    sc = soundcloud.get('/me/favorites')[0]
    print sc['title'], sc['permalink_url']
    return (sc['title'], sc['permalink_url'])
  elif platform == 'hm':
    hypem_f = urllib2.urlopen("http://hypem.com/playlist/loved/jazzcar/json/1/data.js")
    hm_faves = json.loads(hypem_f.read())
    hm = hm_faves["0"]
    print hm['title'], hm['artist']
    return (hm['title'],hm['artist'])
  else:
    print 'error'
    return 'error'
Esempio n. 2
0
def getFave(platform):
    if platform == 'sc':
        sc = soundcloud.get('/me/favorites')[0]
        print sc['title'], sc['permalink_url']
        return (sc['title'], sc['permalink_url'])
    elif platform == 'hm':
        hypem_f = urllib2.urlopen(
            "http://hypem.com/playlist/loved/jazzcar/json/1/data.js")
        hm_faves = json.loads(hypem_f.read())
        hm = hm_faves["0"]
        print hm['title'], hm['artist']
        return (hm['title'], hm['artist'])
    else:
        print 'error'
        return 'error'
Esempio n. 3
0
def sc_to_sp():
    sc_playlists_list = soundcloud.get('/me/playlists')
    sc_playlists = {}
    for pl in sc_playlists_list:
        sc_playlists[pl.title] = pl
    spotify = spotipy.Spotify(session["token"])
    user_id = spotify.current_user().get('id')
    selected_playlists = request.form.getlist('playlists')
    fails = {}
    for pl in selected_playlists:
        playlist = sc_playlists[str(pl)]
        fails[playlist.title] = []
        songs_to_add = []
        for track in playlist.tracks:
            title = track['title']
            artist = track['user']['username']
            duration = track['duration']
            matches = spotify.search('{} {}'.format(title, artist))['tracks']['items']
            if not len(matches):
                matches = spotify.search(title)['tracks']['items']
                # if not len(matches):
                #     print ("No match for {}, {}.".format(title, artist))
            success = False
            for match in matches:
                if abs(match['duration_ms'] - duration) <= 1321:
                    # print ('{}, {}'.format(match['name'], match['artists'][0]['name']))
                    songs_to_add.append(match['id'])
                    success = True
                    break
            if not success:
                fails[playlist.title].append(title)
        if len(songs_to_add):
            playlist_id = spotify.user_playlist_create(user_id, playlist.title)['id']
            spotify.user_playlist_add_tracks(user_id, playlist_id, songs_to_add)
        # else:
        #     print ('No matches found.')
    for key in deepcopy(fails):
        if not len(fails[key]):
            fails.pop(key)
    # return jsonify(fails)
    return render_template('fails.html', fails = fails)
Esempio n. 4
0
def sccallback():
    client_token = soundcloud.exchange_token(code=request.args.get('code')).fields()
    access_token = client_token["access_token"]
    scope = client_token["scope"]
    sc_playlists = soundcloud.get('/me/playlists')
    return render_template('playlists.html', playlists = [p.title for p in sc_playlists])