def get_unlisted_track(track_id, url_title, handle, current_user_id,
                       endpoint_ns):
    args = {
        "identifiers": [{
            "handle": handle,
            "url_title": url_title,
            "id": track_id
        }],
        "filter_deleted": False,
        "with_users": True,
        "current_user_id": current_user_id
    }
    tracks = get_tracks_including_unlisted(args)
    if not tracks:
        abort_not_found(track_id, endpoint_ns)
    single_track = extend_track(tracks[0])
    return success_response(single_track)
Exemple #2
0
    def get(self, track_id):
        """
        Get the track's streamable mp3 file.

        This endpoint accepts the Range header for streaming.
        https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
        """
        decoded_id = decode_with_abort(track_id, ns)
        args = {"track_id": decoded_id}
        creator_nodes = get_track_user_creator_node(args)
        if creator_nodes is None:
            abort_not_found(track_id, ns)
        creator_nodes = creator_nodes.split(',')
        if not creator_nodes:
            abort_not_found(track_id, ns)

        primary_node = creator_nodes[0]
        stream_url = urljoin(primary_node, 'tracks/stream/{}'.format(track_id))

        return stream_url
    def get(self, track_id):
        """
        Get the streamable MP3 file of a track

        This endpoint accepts the Range header for streaming.
        https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
        """
        decoded_id = decode_with_abort(track_id, ns)
        args = {"track_id": decoded_id}
        creator_nodes = get_track_user_creator_node(args)
        if creator_nodes is None:
            abort_not_found(track_id, ns)
        creator_nodes = creator_nodes.split(",")
        if not creator_nodes:
            abort_not_found(track_id, ns)

        # before redirecting to content node,
        # make sure the track isn't deleted and the user isn't deactivated
        args = {
            "id": [decoded_id],
            "with_users": True,
        }
        tracks = get_tracks(args)
        track = tracks[0]
        if track["is_delete"] or track["user"]["is_deactivated"]:
            abort_not_found(track_id, ns)

        primary_node = creator_nodes[0]
        stream_url = urljoin(primary_node, f"tracks/stream/{track_id}")

        return stream_url
    def get(self):
        """
        Resolves and redirects a provided Audius app URL to the API resource URL it represents.

        This endpoint allows you to lookup and access API resources when you only know the
        audius.co URL.
        Tracks, Playlists, and Users are supported.
        """
        args = resolve_route_parser.parse_args()
        url = args.get("url")
        if not url:
            abort_bad_request_param("url", ns)
        try:
            db = db_session.get_db_read_replica()
            with db.scoped_session() as session:
                resolved_url = resolve_url(session, url)
                if not resolved_url:
                    return abort_not_found(url, ns)

                return redirect(resolved_url, code=302)

        except Exception as e:
            logger.warning(e)
            abort_not_found(url, ns)
    def get(self):
        args = full_track_route_parser.parse_args()
        slug, handle = args.get("slug"), args.get("handle")
        routes = args.get("route")
        permalinks = args.get("permalink")
        current_user_id = get_current_user_id(args)
        ids = args.get("id")

        routes = (routes or []) + (permalinks or [])
        if not ((slug and handle) or routes or ids):
            full_ns.abort(400, "Expected query param 'permalink' or 'id'")
        elif ids and (routes or (slug and handle)):
            full_ns.abort(
                400,
                "Ambiguous query params: Expected one of 'id', 'permalink' but not both",
            )
        routes_parsed = routes if routes else []
        try:
            routes_parsed = parse_routes(routes_parsed)
        except IndexError:
            abort_bad_request_param("permalink", full_ns)
        if slug and handle:
            routes_parsed.append({"handle": handle, "slug": slug})
        if ids:
            tracks = get_tracks({
                "with_users": True,
                "id": decode_ids_array(ids),
                "current_user_id": current_user_id,
            })
        else:
            tracks = get_tracks({
                "with_users": True,
                "routes": routes_parsed,
                "current_user_id": current_user_id,
            })
        if not tracks:
            if handle and slug:
                abort_not_found(f"{handle}/{slug}", full_ns)
            elif routes:
                abort_not_found(routes, full_ns)
            else:
                abort_not_found(ids, full_ns)

        # For backwards compatibility, the old handle/slug route returned an object, not an array
        if handle and slug:
            tracks = extend_track(tracks[0])
        else:
            tracks = [extend_track(track) for track in tracks]
        return success_response(tracks)