Exemplo n.º 1
0
    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
Exemplo n.º 2
0
 def get(self, id: str):
     args = pagination_parser.parse_args()
     decoded_id = decode_with_abort(id, ns)
     args["user_id"] = decoded_id
     support = get_support_received_by_user(args)
     support = list(map(extend_supporter, support))
     return success_response(support)
Exemplo n.º 3
0
    def get(self, id):
        decoded_id = decode_with_abort(id, ns)
        args = pagination_with_current_user_parser.parse_args()

        current_user_id = get_current_user_id(args)

        offset = format_offset(args)
        limit = format_limit(args)

        args = {
            "current_user_id": current_user_id,
            "with_users": True,
            "filter_deleted": True,
            "limit": limit,
            "offset": offset,
        }
        reposts = get_repost_feed_for_user(decoded_id, args)
        for repost in reposts:
            if "playlist_id" in repost:
                repost["tracks"] = get_tracks_for_playlist(
                    repost["playlist_id"], current_user_id
                )
        activities = list(map(extend_activity, reposts))

        return success_response(activities)
Exemplo n.º 4
0
 def get(self):
     args = associated_wallet_route_parser.parse_args()
     user_id = decode_with_abort(args.get("id"), ns)
     wallets = get_associated_user_wallet({"user_id": user_id})
     return success_response(
         {"wallets": wallets["eth"], "sol_wallets": wallets["sol"]}
     )
Exemplo n.º 5
0
 def get(self, user_id):
     """Fetch most used tags in a user's tracks."""
     decoded_id = decode_with_abort(user_id, ns)
     args = tags_route_parser.parse_args()
     limit = format_limit(args)
     tags = get_top_user_track_tags({'user_id': decoded_id, 'limit': limit})
     return success_response(tags)
Exemplo n.º 6
0
 def get(self, id):
     args = related_artist_route_parser.parse_args()
     limit = get_default_max(args.get("limit"), 10, 100)
     current_user_id = get_current_user_id(args)
     decoded_id = decode_with_abort(id, full_ns)
     users = get_related_artists(decoded_id, current_user_id, limit)
     users = list(map(extend_user, users))
     return success_response(users)
Exemplo n.º 7
0
 def get(self, playlist_id):
     """Fetch a playlist."""
     playlist_id = decode_with_abort(playlist_id, ns)
     args = {"playlist_id": [playlist_id], "with_users": True}
     playlists = get_playlists(args)
     playlists = list(map(extend_playlist, playlists))
     response = success_response(playlists)
     return response
Exemplo n.º 8
0
 def get(self, id: str):
     args = pagination_with_current_user_parser.parse_args()
     decoded_id = decode_with_abort(id, full_ns)
     current_user_id = get_current_user_id(args)
     args["user_id"] = decoded_id
     args["current_user_id"] = current_user_id
     support = get_support_sent_by_user(args)
     support = list(map(extend_supporting, support))
     return success_response(support)
Exemplo n.º 9
0
 def get(self, user_id):
     """Fetch a single user."""
     decoded_id = decode_with_abort(user_id, ns)
     args = {"id": [decoded_id]}
     users = get_users(args)
     if not users:
         abort_not_found(user_id, ns)
     user = extend_user(users[0])
     return success_response(user)
Exemplo n.º 10
0
 def get(self, track_id):
     """Fetch a track."""
     decoded_id = decode_with_abort(track_id, ns)
     args = {"id": [decoded_id], "with_users": True, "filter_deleted": True}
     tracks = get_tracks(args)
     if not tracks:
         abort_not_found(track_id, ns)
     single_track = extend_track(tracks[0])
     return success_response(single_track)
Exemplo n.º 11
0
 def get(self, playlist_id):
     """Fetch tracks within a playlist."""
     decoded_id = decode_with_abort(playlist_id, ns)
     args = {"playlist_id": decoded_id, "with_users": True}
     playlist_tracks = get_playlist_tracks(args)
     if not playlist_tracks:
         abort_not_found(playlist_id, ns)
     tracks = list(map(extend_track, playlist_tracks))
     return success_response(tracks)
Exemplo n.º 12
0
 def get(self, user_id):
     """Fetch a list of tracks for a user."""
     decoded_id = decode_with_abort(user_id, ns)
     args = {
         "user_id": decoded_id,
         "with_users": True,
         "filter_deleted": True
     }
     tracks = get_tracks(args)
     tracks = list(map(extend_track, tracks))
     return success_response(tracks)
Exemplo n.º 13
0
    def get(self, track_id):
        args = full_track_parser.parse_args()
        decoded_id = decode_with_abort(track_id, full_ns)
        current_user_id = get_current_user_id(args)
        if args.get("show_unlisted"):
            url_title, handle = args.get("url_title"), args.get("handle")
            if not (url_title and handle):
                full_ns.abort(
                    400, "Unlisted tracks require url_title and handle")
            return get_unlisted_track(decoded_id, url_title, handle, current_user_id, full_ns)

        return get_single_track(decoded_id, current_user_id, full_ns)
Exemplo n.º 14
0
    def get(self, playlist_id):
        """Fetch a playlist."""
        playlist_id = decode_with_abort(playlist_id, full_ns)
        args = full_playlist_parser.parse_args()
        current_user_id = get_current_user_id(args)

        playlist = get_playlist(playlist_id, current_user_id)
        if playlist:
            tracks = get_tracks_for_playlist(playlist_id, current_user_id)
            playlist["tracks"] = tracks
        response = success_response([playlist] if playlist else [])
        return response
Exemplo n.º 15
0
    def get(self, id: str):
        args = get_challenges_route_parser.parse_args()
        show_historical = args.get("show_historical")
        decoded_id = decode_with_abort(id, ns)
        db = get_db_read_replica()

        with db.scoped_session() as session:
            bus = setup_challenge_bus()
            challenges = get_challenges(decoded_id, show_historical, session, bus)
            challenges = list(map(extend_challenge_response, challenges))

            return success_response(challenges)
Exemplo n.º 16
0
 def get(self, playlist_id):
     args = playlist_reposts_route_parser.parse_args()
     decoded_id = decode_with_abort(playlist_id, full_ns)
     limit = get_default_max(args.get('limit'), 10, 100)
     offset = get_default_max(args.get('offset'), 0)
     current_user_id = get_current_user_id(args)
     args = {
         'repost_playlist_id': decoded_id,
         'current_user_id': current_user_id,
         'limit': limit,
         'offset': offset
     }
     users = get_reposters_for_playlist(args)
     users = list(map(extend_user, users))
     return success_response(users)
Exemplo n.º 17
0
 def get(self, id):
     args = pagination_with_current_user_parser.parse_args()
     decoded_id = decode_with_abort(id, ns)
     current_user_id = get_current_user_id(args)
     offset = format_offset(args)
     limit = format_limit(args)
     get_tracks_args = GetUserListeningHistoryArgs(
         user_id=decoded_id,
         current_user_id=current_user_id,
         limit=limit,
         offset=offset,
     )
     track_history = get_user_listening_history(get_tracks_args)
     tracks = list(map(extend_activity, track_history))
     return success_response(tracks)
Exemplo n.º 18
0
 def get(self, id):
     decoded_id = decode_with_abort(id, full_ns)
     args = pagination_with_current_user_parser.parse_args()
     limit = get_default_max(args.get("limit"), 10, 100)
     offset = get_default_max(args.get("offset"), 0)
     current_user_id = get_current_user_id(args)
     args = {
         "follower_user_id": decoded_id,
         "current_user_id": current_user_id,
         "limit": limit,
         "offset": offset,
     }
     users = get_followees_for_user(args)
     users = list(map(extend_user, users))
     return success_response(users)
Exemplo n.º 19
0
    def get(self, track_id):
        decoded_id = decode_with_abort(track_id, full_ns)
        request_args = remixing_parser.parse_args()
        current_user_id = get_current_user_id(request_args)

        args = {
            "with_users": True,
            "track_id": decoded_id,
            "current_user_id": current_user_id,
            "limit": format_limit(request_args),
            "offset": format_offset(request_args)
        }
        tracks = get_remix_track_parents(args)
        tracks = list(map(extend_track, tracks))
        return success_response(tracks)
Exemplo n.º 20
0
    def get(self, track_id):
        decoded_id = decode_with_abort(track_id, full_ns)
        request_args = pagination_with_current_user_parser.parse_args()
        current_user_id = get_current_user_id(request_args)

        args = {
            "with_users": True,
            "track_id": decoded_id,
            "current_user_id": current_user_id,
            "limit": format_limit(request_args, default_limit=10),
            "offset": format_offset(request_args),
        }
        response = get_remixes_of(args)
        response["tracks"] = list(map(extend_track, response["tracks"]))
        return success_response(response)
Exemplo n.º 21
0
 def get(self, user_id):
     decoded_id = decode_with_abort(user_id, full_ns)
     args = following_route_parser.parse_args()
     limit = get_default_max(args.get('limit'), 10, 100)
     offset = get_default_max(args.get('offset'), 0)
     current_user_id = get_current_user_id(args)
     args = {
         'follower_user_id': decoded_id,
         'current_user_id': current_user_id,
         'limit': limit,
         'offset': offset
     }
     users = get_followees_for_user(args)
     users = list(map(extend_user, users))
     return success_response(users)
Exemplo n.º 22
0
    def get(self, track_id):
        args = track_favorites_route_parser.parse_args()
        decoded_id = decode_with_abort(track_id, full_ns)
        limit = get_default_max(args.get('limit'), 10, 100)
        offset = get_default_max(args.get('offset'), 0)
        current_user_id = get_current_user_id(args)

        args = {
            'save_track_id': decoded_id,
            'current_user_id': current_user_id,
            'limit': limit,
            'offset': offset
        }
        users = get_savers_for_track(args)
        users = list(map(extend_user, users))

        return success_response(users)
Exemplo n.º 23
0
    def get(self, user_id):
        """Fetch favorited tracks for a user."""
        args = favorite_route_parser.parse_args()
        decoded_id = decode_with_abort(user_id, ns)
        current_user_id = get_current_user_id(args)

        offset = format_offset(args)
        limit = format_limit(args)
        get_tracks_args = {
            "filter_deleted": False,
            "user_id": decoded_id,
            "current_user_id": current_user_id,
            "limit": limit,
            "offset": offset,
            "with_users": True
        }
        track_saves = get_save_tracks(get_tracks_args)
        tracks = list(map(extend_activity, track_saves))
        return success_response(tracks)
Exemplo n.º 24
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
Exemplo n.º 25
0
    def get(self, user_id):
        decoded_id = decode_with_abort(user_id, ns)
        args = user_reposts_route_parser.parse_args()

        current_user_id = get_current_user_id(args)

        offset = format_offset(args)
        limit = format_limit(args)

        args = {
            "user_id": decoded_id,
            "current_user_id": current_user_id,
            "with_users": True,
            "filter_deleted": True,
            "limit": limit,
            "offset": offset
        }
        reposts = get_repost_feed_for_user(decoded_id, args)
        activities = list(map(extend_activity, reposts))

        return success_response(activities)
Exemplo n.º 26
0
    def get(self, user_id):
        """Fetch a list of tracks for a user."""
        decoded_id = decode_with_abort(user_id, ns)
        args = user_tracks_route_parser.parse_args()

        current_user_id = get_current_user_id(args)

        sort = args.get("sort", None)
        offset = format_offset(args)
        limit = format_limit(args)

        args = {
            "user_id": decoded_id,
            "current_user_id": current_user_id,
            "with_users": True,
            "filter_deleted": True,
            "sort": sort,
            "limit": limit,
            "offset": offset
        }
        tracks = get_tracks(args)
        tracks = list(map(extend_track, tracks))
        return success_response(tracks)
Exemplo n.º 27
0
    def get(self, challenge_id: str):
        args = attest_parser.parse_args(strict=True)
        user_id: str = args["user_id"]
        oracle_address: str = args["oracle"]
        specifier: str = args["specifier"]
        decoded_user_id = decode_with_abort(user_id, ns)
        db = get_db_read_replica()
        with db.scoped_session() as session:
            try:
                owner_wallet, signature = get_attestation(
                    session,
                    user_id=decoded_user_id,
                    oracle_address=oracle_address,
                    specifier=specifier,
                    challenge_id=challenge_id,
                )

                return success_response({
                    "owner_wallet": owner_wallet,
                    "attestation": signature
                })
            except AttestationError as e:
                abort(400, e)
                return None
Exemplo n.º 28
0
 def get(self, playlist_id):
     """Fetch a playlist."""
     playlist_id = decode_with_abort(playlist_id, ns)
     playlist = get_playlist(playlist_id, None)
     response = success_response([playlist] if playlist else [])
     return response
Exemplo n.º 29
0
 def get(self, playlist_id):
     """Fetch tracks within a playlist."""
     decoded_id = decode_with_abort(playlist_id, ns)
     tracks = get_tracks_for_playlist(decoded_id)
     return success_response(tracks)
Exemplo n.º 30
0
 def get(self, track_id):
     """Fetch a track."""
     decoded_id = decode_with_abort(track_id, ns)
     return get_single_track(decoded_id, None, ns)