Esempio n. 1
0
def spotify_play_song(request, authorization_id):
    uri = request.get_json()[
        "spotify_id"
    ]  # Spotify handles search so we get a spotify id for free. Other music services will have to use the isrc, ean, or upc to find and play the song
    _queue_song_job, _unpause_if_paused_job = str(uuid.uuid4()), str(uuid.uuid4())
    async_messenger.send(
        "authorizer.make_authorized_request",
        {
            "http_verb": "post",
            "url": f"https://api.spotify.com/v1/me/player/queue?uri={uri}",
            "authorization_id": authorization_id,
            "key": _queue_song_job,
            "expires_in": 60 * 60,
        },
    )
    async_messenger.send(
        "authorizer.make_authorized_request",
        {
            "http_verb": "put",
            "url": "https://api.spotify.com/v1/me/player/play",
            "authorization_id": authorization_id,
            "key": _unpause_if_paused_job,
            "expires_in": 60 * 60,
        },
    )
Esempio n. 2
0
def create_spotify_authorization(code):
    key = str(uuid.uuid4())
    async_messenger.send(
        "authorizer.create_authorization",
        {"code": code, "key": key, "service": "spotify"},
    )

    authorization_id = redis_wait(r, key)
    if not authorization_id:
        raise TimeoutError("0Z9MI")
    return authorization_id
Esempio n. 3
0
def find_or_create_spotify_user(authorization_id):
    key = str(uuid.uuid4())
    async_messenger.send(
        "authorizer.make_authorized_request",
        {
            "http_verb": "get",
            "url": "https://api.spotify.com/v1/me",
            "authorization_id": authorization_id,
            "queue": "user.create_or_update_user",
            "kwargs": {"ebc_host_user": key},
        },
    )
    user_id = redis_wait(r, key)
    if not user_id:
        raise TimeoutError("L9RBU")
    return user_id
Esempio n. 4
0
    def decorated_function(*args, **kwargs):
        ebc_host_auth = request.cookies.get("EBC_HOST_AUTH")
        service = request.cookies.get("EBC_HOST_SERVICE")
        job_id = str(uuid.uuid4())

        authorization_id = r.get(ebc_host_auth) if ebc_host_auth else None
        if authorization_id:
            async_messenger.send(
                "authorizer.refresh_authorization",
                {
                    "authorization_id": authorization_id,
                    "job_id": job_id,
                    "service": service,
                },
            )
            if redis_wait(r, job_id):
                return f(*args, **kwargs)

        response = make_response(redirect("/rooms"))
        response.set_cookie("EBC_HOST_AUTH", "", expires=0)
        response.set_cookie("EBC_HOST_USER", "", expires=0)
        response.set_cookie("EBC_HOST_SERVICE", "", expires=0)
        return response
Esempio n. 5
0
def spotify_create_play(guid, request):
    # Universal ids, these are nullable
    isrc = request.get_json()["isrc"]
    upc = request.get_json()["upc"]
    ean = request.get_json()["ean"]

    spotify_id = request.get_json()["spotify_id"]

    room_code = request.get_json()["room_code"]

    _record_play_job = str(uuid.uuid4())
    async_messenger.send(
        "player.create_play",
        {
            "guid": guid,
            "isrc": isrc,
            "upc": upc,
            "ean": ean,
            "spotify_id": spotify_id,
            "room_code": room_code,
            "key": _record_play_job,
            "expires_in": 60 * 60,
        },
    )
Esempio n. 6
0
def record_queue_response_helper(resp_dict, queue, kwargs):
    merged_dict = {**kwargs, **resp_dict}
    async_messenger.send(queue, merged_dict)