예제 #1
0
파일: twt.py 프로젝트: 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'
예제 #2
0
파일: twt.py 프로젝트: CamilaEBF/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'
예제 #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)
예제 #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])