Exemplo n.º 1
0
def start():

    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:

        google_email = input("Enter Google email address: ")
        google_pass = getpass("Enter Google password: "******"Invalid Google username/password")
            sys.exit(1)

        uprint("Go to {0} and get an oauth token".format(OAUTH_URL))
        spotify_token = input("Enter Spotify oauth token: ")

        s = SpotifyClient(session, spotify_token)

        logged_in = yield from s.loggedin()
        if not logged_in:
            uprint("Invalid Spotify token")
            sys.exit(1)

        playlists = yield from s.fetch_spotify_playlists()
        playlists = [l['uri'] for l in playlists]
        yield from app.transfer_playlists(None, s, g, playlists)
Exemplo n.º 2
0
def start():
    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:
        conf = dict(
            google_email=None,
            google_pass=None,
            spotify_token=None,
        )

        try:
            with open(CONFIG_FILE, 'r') as f:
                conf.update(yaml.load(f))
        except Exception as exc:
            if not os.path.exists(CONFIG_FILE):
                log.info('Could not load from config file {}: {}'.format(
                    CONFIG_FILE, exc))

        if not conf['google_email']:
            conf['google_email'] = input("Enter Google email address: ")
        if not conf['google_pass']:
            conf['google_pass'] = getpass("Enter Google password: "******"Invalid Google username/password")
            sys.exit(1)

        if not conf['spotify_token']:
            log.info("Go to {0} and get an oauth token".format(OAUTH_URL))
            conf['spotify_token'] = input("Enter Spotify oauth token: ")

        s = SpotifyClient(session, conf['spotify_token'])

        logged_in = yield from s.loggedin()
        if not logged_in:
            log.info("Invalid Spotify token")
            sys.exit(1)

        log.info('Caching all playlists from Google')
        if os.path.exists('google_playlists.pickle'):
            with open('google_playlists.pickle', 'rb') as f:
                g._playlists = pickle.load(f)
        else:
            yield from g.cache_playlists()
            with open('google_playlists.pickle', 'wb') as f:
                pickle.dump(g._playlists, f)

        log.info('Fetching Spotify playlists')
        playlists = yield from s.fetch_spotify_playlists()

        log.info('Starting sync')
        done = yield from app.transfer_playlists(None, s, g, playlists)
        log.debug('done=%s', done)

        log.info('Success!')
Exemplo n.º 3
0
def start():

    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:

        google_email = input("Enter Google email address: ")
        google_pass = getpass("Enter Google password: "******"Invalid Google username/password")
            sys.exit(1)

        uprint("Go to {0} and get an oauth token".format(OAUTH_URL))
        spotify_token = input("Enter Spotify oauth token: ")

        s = SpotifyClient(session, spotify_token)

        logged_in = yield from s.loggedin()
        if not logged_in:
            uprint("Invalid Spotify token")
            sys.exit(1)

        playlists = yield from s.fetch_spotify_playlists()
        yield from app.transfer_playlists(None, s, g, playlists)
Exemplo n.º 4
0
def spotify_playlists(request):
    with ClientSession() as session:
        c = SpotifyClient(session, user_scope.spotify_token)
        ret_playlists = yield from c.fetch_spotify_playlists()
        return json_response({
            "status": 200,
            "message": "ok",
            "data": ret_playlists
        })
Exemplo n.º 5
0
def spotify_playlists(request):
    with ClientSession() as session:
        c = SpotifyClient(session, user_scope.spotify_token)
        ret_playlists = yield from c.fetch_spotify_playlists()
        return json_response({
            "status": 200,
            "message": "ok",
            "data": ret_playlists
        })
Exemplo n.º 6
0
def transfer_start(request):

    lists = yield from request.json()
    lists = [l['uri'] for l in lists]

    if not user_scope.google_token:
        return json_response({
            "status": 401,
            "message": "Google: not logged in.",
        })

    if not user_scope.spotify_token:
        return json_response({
            "status": 402,
            "message": "Spotify: not logged in.",
        })

    if not lists:
        return json_response({
            "status": 403,
            "message": "Please select at least one playlist.",
        })

    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:
        g = Mobileclient(session, user_scope.google_token)
        s = SpotifyClient(session, user_scope.spotify_token)

        yield from transfer_playlists(request, s, g, lists)
        return json_response({
            "status": 200,
            "message": "transfer will start.",
        })
Exemplo n.º 7
0
def spotify_login(request):

    data = yield from request.json()

    oauth_token = data.get("oauthToken")
    with ClientSession() as session:
        c = SpotifyClient(session, oauth_token)
        logged_in = yield from c.loggedin()
        if not logged_in:
            return json_response(dict(
                status=400,
                message="login failed.",
            ))
        user_scope.spotify_token = oauth_token

    return json_response(dict(status=200, message="login successful."))
Exemplo n.º 8
0
def spotify_login(request):

    data = yield from request.json()

    oauth_token = data.get("oauthToken")
    with ClientSession() as session:
        c = SpotifyClient(session, oauth_token)
        logged_in = yield from c.loggedin()
        if not logged_in:
            return json_response(dict(
                status=400,
                message="login failed.",
            ))
        user_scope.spotify_token = oauth_token

    return json_response(dict(
        status=200,
        message="login successful."
    ))
Exemplo n.º 9
0
def start():

    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:

        google_email = input("Enter Google email address: ")
        google_pass = getpass("Enter Google password: "******"Invalid Google username/password")
            sys.exit(1)

        user_id = input("Enter Spotify User to copy playlist from: ")
        playlist = input(
            "Enter the User's Spotify playlist you want to copy: ")
        explicit = input("Enter Y if you want to include explicit songs: ")
        if explicit == 'Y':
            content_type = 'E'
        else:
            content_type = 'R'

        uprint("Go to {0} and get an oauth token".format(OAUTH_URL))
        spotify_token = input("Enter Spotify oauth token: ")

        s = SpotifyClient(session, spotify_token, user_id)

        logged_in = yield from s.loggedin()
        if not logged_in:
            uprint("Invalid Spotify token")
            sys.exit(1)

        playlists = yield from s.fetch_spotify_playlists()
        yield from app.transfer_playlists(None, s, g, playlist, content_type,
                                          playlists)
Exemplo n.º 10
0
async def spotify_login(request):

    data = await request.json()

    oauth_token = data.get("oauthToken")
    with ClientSession() as session:
        c = SpotifyClient(session, oauth_token)
        logged_in = await c.loggedin()
        if not logged_in:
            return json_response({"status": 400, "message": "login failed."})
        user_scope.spotify_token = oauth_token

    return json_response({"status": 200, "message": "login successful."})
Exemplo n.º 11
0
def start():

    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:

        google_email = input("Enter Google email address: ")
        google_pass = getpass("Enter Google password: "******"Invalid Google username/password")
            sys.exit(1)

        user_id = input("Enter Spotify User to copy playlist from: ")
        playlist = input("Enter the User's Spotify playlist you want to copy: ")
        explicit = input("Enter Y if you want to include explicit songs: ")
        if explicit == 'Y':
            content_type = 'E'
        else:
            content_type = 'R'

        uprint("Go to {0} and get an oauth token".format(OAUTH_URL))
        spotify_token = input("Enter Spotify oauth token: ")

        s = SpotifyClient(session, spotify_token, user_id)

        logged_in = yield from s.loggedin()
        if not logged_in:
            uprint("Invalid Spotify token")
            sys.exit(1)

        playlists = yield from s.fetch_spotify_playlists()
        yield from app.transfer_playlists(None, s, g, playlist, content_type, playlists)
Exemplo n.º 12
0
async def run():
    # https://developer.spotify.com/web-api/console/get-playlists/
    oauth_token = pathlib.Path(pathlib.Path.home(),
                               "secrets/spotify_access_token.txt")
    with ClientSession() as session:
        c = SpotifyClient(session, oauth_token)
        logged_in = await c.loggedin()
        if not logged_in:
            print("not logged in")
            return
        print("Logged in")

        # playlists = await c.fetch_spotify_playlists()
        # sp_playlist = playlists[0]
        sp_playlist_uri = 'spotify:user:22ujgyiomxbgggsb7mvnorh7q:playlist:3OVXBy5QDsx1jdSHrkAu1L'  # noqa
        pl = await c.fetch_playlist(sp_playlist_uri)
        tracks = pl['tracks']['items']
        for i, sp_track in enumerate(tracks):
            query = SpotifyQuery(i, sp_playlist_uri, sp_track, len(tracks))
            query.search_query()
Exemplo n.º 13
0
async def start():

    sslcontext = ssl.create_default_context(cafile=certifi.where())
    conn = aiohttp.TCPConnector(ssl_context=sslcontext)

    with ClientSession(connector=conn) as session:

        g = Mobileclient(session)
        logged_in = await g.login(google_email, google_pass)
        if not logged_in:
            uprint("Invalid Google username/password")
            sys.exit(1)

        s = SpotifyClient(session, spotify_token)

        logged_in = await s.loggedin()
        if not logged_in:
            uprint("Invalid Spotify token")
            sys.exit(1)

        await test_percent_search(g)
        await test_playlist(s, g)
        return

        # di = await g.fetch_playlists()
        # import pprint
        # pprint.pprint(di['data']['items'])
        #
        # # playlist_id = await g.create_playlist("Test Playlist")
        # playlist_id = "2c02eca1-429e-4ce0-a4a8-819415cdee3a"
        # await g.add_songs_to_playlist(
        #     playlist_id,
        #     ['Twqujxontbfftlzi7hextragxyu'],
        #     # ['ba3a473e-6309-3814-8c05-b8b6619f38f3'],
        # )
        playlists = await s.fetch_spotify_playlists()
        playlists = [l['uri'] for l in playlists]
        await app.transfer_playlists(None, s, g, playlists)