Exemplo n.º 1
0
    def get(self):
        args = pagination_with_current_user_parser.parse_args()
        current_user_id = get_current_user_id(args)

        top_users = get_top_users(current_user_id)
        users = list(map(extend_user, top_users))
        return success_response(users)
Exemplo n.º 2
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.º 3
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.º 4
0
 def get(self, id: str):
     args = pagination_parser.parse_args()
     decoded_id = decode_with_abort(id, ns)
     current_user_id = get_current_user_id(args)
     args["user_id"] = decoded_id
     args["current_user_id"] = current_user_id
     support = get_support_received_by_user(args)
     support = list(map(extend_supporter, support))
     return success_response(support)
Exemplo n.º 5
0
 def get(self):
     args = track_remixables_route_parser.parse_args()
     args = {
         "current_user_id": get_current_user_id(args),
         "limit": get_default_max(args.get("limit"), 25, 100),
         "with_users": args.get("with_users", False),
     }
     tracks = get_remixable_tracks(args)
     tracks = list(map(extend_track, tracks))
     return success_response(tracks)
Exemplo n.º 6
0
    def get(self, handle):
        args = full_user_handle_parser.parse_args()
        current_user_id = get_current_user_id(args)

        args = {"handle": handle, "current_user_id": current_user_id}
        users = get_users(args)
        if not users:
            abort_not_found(handle, ns)
        user = extend_user(users[0])
        return success_response(user)
Exemplo n.º 7
0
 def get(self):
     request_args = best_new_releases_parser.parse_args()
     window = request_args.get("window")
     args = {
         "with_users": request_args.get("with_users"),
         "limit": format_limit(request_args, 100),
         "user_id": get_current_user_id(request_args),
     }
     tracks = get_top_followee_windowed("track", window, args)
     tracks = list(map(extend_track, tracks))
     return success_response(tracks)
Exemplo n.º 8
0
 def get(self):
     request_args = most_loved_parser.parse_args()
     args = {
         "with_users": request_args.get("with_users"),
         "limit": format_limit(request_args,
                               max_limit=100,
                               default_limit=25),
         "user_id": get_current_user_id(request_args),
     }
     tracks = get_top_followee_saves("track", args)
     tracks = list(map(extend_track, tracks))
     return success_response(tracks)
Exemplo n.º 9
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.º 10
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.º 11
0
 def get(self):
     request_args = under_the_radar_parser.parse_args()
     args = {
         "tracks_only": request_args.get("tracks_only"),
         "with_users": request_args.get("with_users"),
         "limit": format_limit(request_args, 100, 25),
         "offset": format_offset(request_args),
         "user_id": get_current_user_id(request_args),
         "filter": request_args.get("filter"),
     }
     feed_results = get_feed(args)
     feed_results = list(map(extend_track, feed_results))
     return success_response(feed_results)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
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.º 14
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.º 15
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.º 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, 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.º 18
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.º 19
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.º 20
0
    def get(self):
        args = full_search_parser.parse_args()
        offset = format_offset(args)
        limit = format_limit(args)
        current_user_id = get_current_user_id(args)

        search_args = {
            "is_auto_complete": False,
            "kind": args.get("kind", "all"),
            "query": args.get("query"),
            "current_user_id": current_user_id,
            "with_users": True,
            "limit": limit,
            "offset": offset,
            "only_downloadable": False,
        }
        resp = search(search_args)
        return success_response(resp)
Exemplo n.º 21
0
    def get(self):
        args = get_undisbursed_challenges_route_parser.parse_args()
        decoded_id = get_current_user_id(args)
        db = get_db_read_replica()

        with db.scoped_session() as session:
            undisbursed_challenges = get_undisbursed_challenges(
                session,
                {
                    "user_id": decoded_id,
                    "limit": args["limit"],
                    "offset": args["offset"],
                    "completed_blocknumber": args["completed_blocknumber"],
                },
            )
            undisbursed_challenges = list(
                map(extend_undisbursed_challenge, undisbursed_challenges))
            return success_response(undisbursed_challenges)
Exemplo n.º 22
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.º 23
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.º 24
0
    def get(self, handle):
        args = user_reposts_route_parser.parse_args()

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

        args = {
            "handle": handle,
            "current_user_id": current_user_id,
            "with_users": True,
            "filter_deleted": True,
            "limit": limit,
            "offset": offset
        }
        reposts = get_repost_feed_for_user(None, 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.º 25
0
    def get(self, handle):
        """Fetch a list of tracks for a user."""
        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 = {
            "handle": handle,
            "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.º 26
0
    def get(self, id, authed_user_id=None):
        decoded_id = decode_with_abort(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,
            "authed_user_id": authed_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):
        """
        Get Users/Tracks/Playlists/Albums that best match the search query

        Same as search but optimized for quicker response at the cost of some entity information.
        """
        args = full_search_parser.parse_args()
        offset = format_offset(args)
        limit = format_limit(args)
        current_user_id = get_current_user_id(args)

        search_args = {
            "is_auto_complete": True,
            "kind": args.get("kind", "all"),
            "query": args.get("query"),
            "current_user_id": current_user_id,
            "with_users": False,
            "limit": limit,
            "offset": offset,
            "only_downloadable": False,
        }
        resp = search(search_args)
        return success_response(resp)
Exemplo n.º 28
0
    def get(self, user_id):
        user_id = decode_with_abort(user_id, ns)
        args = full_user_parser.parse_args()
        current_user_id = get_current_user_id(args)

        return get_single_user(user_id, current_user_id)