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)
    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)
Exemple #3
0
 def get(self):
     """Gets the top 100 trending (most popular) tracks on Audius"""
     args = trending_parser.parse_args()
     time = args.get("time") if args.get("time") is not None else 'week'
     args = {
         'time': time,
         'genre': args.get("genre", None),
         'with_users': True
     }
     tracks = get_trending_tracks(args)
     tracks = list(map(extend_track, tracks))
     return success_response(tracks)
def get_single_track(track_id, current_user_id, endpoint_ns):
    args = {
        "id": [track_id],
        "with_users": True,
        "filter_deleted": True,
        "current_user_id": current_user_id,
    }
    tracks = get_tracks(args)
    if not tracks:
        abort_not_found(track_id, endpoint_ns)
    single_track = extend_track(tracks[0])
    return success_response(single_track)
Exemple #5
0
 def get(self):
     args = metrics_route_parser.parse_args()
     logger.info(
         f"getting cached route metrics at {args.get('start_time')} before parsing"
     )
     start_time = parse_unix_epoch_param_non_utc(args.get("start_time"))
     logger.info(f"getting cached route metrics at {start_time} UTC")
     deduped_metrics = get_redis_route_metrics(start_time)
     summed_metrics = get_summed_unique_metrics(start_time)
     metrics = {'deduped': deduped_metrics, 'summed': summed_metrics}
     response = success_response(metrics)
     return response
    def get(self):
        args = verify_token_parser.parse_args()
        # 1. Break JWT into parts
        token_parts = args["token"].split(".")
        if not len(token_parts) == 3:
            abort_bad_request_param("token", ns)

        # 2. Decode the signature
        try:
            signature = base64.urlsafe_b64decode(token_parts[2] + "==")
        except Exception:
            ns.abort(400, "The JWT signature could not be decoded.")

        signature = signature.decode()
        base64_header = token_parts[0]
        base64_payload = token_parts[1]
        message = f"{base64_header}.{base64_payload}"

        # 3. Recover message from signature
        web3 = web3_provider.get_web3()

        wallet = None
        encoded_message = encode_defunct(text=message)
        try:
            wallet = web3.eth.account.recover_message(
                encoded_message,
                signature=signature,
            )
        except Exception:
            ns.abort(
                404, "The JWT signature is invalid - wallet could not be recovered."
            )
        if not wallet:
            ns.abort(
                404, "The JWT signature is invalid - wallet could not be recovered."
            )

        # 4. Check that user from payload matches the user from the wallet from the signature
        try:
            stringified_payload = base64.urlsafe_b64decode(base64_payload + "==")
            payload = json.loads(stringified_payload)
        except Exception:
            ns.abort(400, "JWT payload could not be decoded.")

        wallet_user_id = get_user_with_wallet(wallet)
        if not wallet_user_id or wallet_user_id != payload["userId"]:
            ns.abort(
                404,
                "The JWT signature is invalid - the wallet does not match the user.",
            )

        # 5. Send back the decoded payload
        return success_response(payload)
Exemple #7
0
    def get(self, version):
        trending_track_versions = trending_strategy_factory.get_versions_for_type(TrendingType.TRACKS).keys()
        version_list = list(filter(lambda v: v.name == version, trending_track_versions))
        if not version_list:
            abort_bad_path_param('version', full_ns)

        args = full_recommended_track_parser.parse_args()
        limit = format_limit(args, default_limit=DEFAULT_RECOMMENDED_LIMIT)
        args['limit'] = max(TRENDING_LIMIT, limit)
        strategy = trending_strategy_factory.get_strategy(TrendingType.TRACKS, version_list[0])
        full_recommended_tracks = get_full_recommended_tracks(request, args, strategy)
        return success_response(full_recommended_tracks[:limit])
Exemple #8
0
 def get(self, time_range):
     """Gets trailing app name metrics from matview"""
     if time_range not in valid_trailing_time_periods:
         abort_bad_request_param('time_range', ns)
     parsed = trailing_app_name_parser.parse_args()
     args = {
         "limit": parsed.get("limit", 10),
         "time_range": time_range
     }
     metrics = get_trailing_app_metrics(args)
     response = success_response(metrics)
     return response
 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)
    def get(self, version):
        trending_track_versions = trending_strategy_factory.get_versions_for_type(
            TrendingType.TRACKS).keys()
        version_list = list(
            filter(lambda v: v.name == version, trending_track_versions))
        if not version_list:
            abort_bad_path_param("version", full_ns)

        args = full_trending_parser.parse_args()
        strategy = trending_strategy_factory.get_strategy(
            TrendingType.TRACKS, version_list[0])
        trending_tracks = get_full_trending(request, args, strategy)
        return success_response(trending_tracks)
Exemple #11
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)
Exemple #12
0
    def get(self):
        """List all the app names"""
        args = metrics_app_name_list_parser.parse_args()
        if args.get('limit') is None:
            args['limit'] = 100
        else:
            args['limit'] = min(args.get('limit'), 100)
        if args.get('offset') is None:
            args['offset'] = 0

        app_names = get_app_names(args)
        response = success_response(app_names)
        return response
    def get(self, version):
        underground_trending_versions = trending_strategy_factory.get_versions_for_type(
            TrendingType.UNDERGROUND_TRACKS).keys()
        version_list = list(
            filter(lambda v: v.name == version, underground_trending_versions))
        if not version_list:
            abort_bad_path_param("version", full_ns)

        args = pagination_with_current_user_parser.parse_args()
        strategy = trending_strategy_factory.get_strategy(
            TrendingType.UNDERGROUND_TRACKS, version_list[0])
        trending_tracks = get_underground_trending(request, args, strategy)
        return success_response(trending_tracks)
Exemple #14
0
    def get(self):
        args = full_trending_parser.parse_args()
        offset = format_offset(args)
        limit = format_limit(args, TRENDING_LIMIT)
        key = self.get_cache_key()

        # Attempt to use the cached tracks list
        if args['user_id'] is not None:
            full_trending = get_trending(args)
        else:
            full_trending = use_redis_cache(key, TRENDING_TTL_SEC,
                                            lambda: get_trending(args))
        trending = full_trending[offset:limit + offset]
        return success_response(trending)
    def get(self):
        args = full_random_track_parser.parse_args()
        limit = format_limit(args, default_limit=DEFAULT_RANDOM_LIMIT)
        args['limit'] = max(TRENDING_LIMIT, limit)
        key = self.get_cache_key()

        # Attempt to use the cached tracks list
        if args['user_id'] is not None:
            full_random = get_random_tracks(args)
        else:
            full_random = use_redis_cache(key, TRENDING_TTL_SEC,
                                          lambda: get_random_tracks(args))
        random = full_random[:limit]
        return success_response(random)
    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)
    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)
 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)
Exemple #19
0
    def get(self, time_range):
        """Gets aggregated route metrics based on time range and bucket size"""
        if time_range not in valid_bucket_sizes:
            abort_bad_path_param('time_range', ns)

        args = aggregate_route_metrics_parser.parse_args()
        valid_buckets = valid_bucket_sizes[time_range]
        bucket_size = args.get("bucket_size") or valid_buckets[0]

        if bucket_size not in valid_buckets:
            abort_bad_request_param('bucket_size', ns)

        metrics = get_aggregate_route_metrics(time_range, bucket_size)
        response = success_response(metrics)
        return response
Exemple #20
0
 def get(self, app_name):
     """Get the app name metrics"""
     args = metrics_app_name_parser.parse_args()
     if args.get('limit') is None:
         args['limit'] = 48
     else:
         args['limit'] = min(args.get('limit'), 48)
     try:
         args['start_time'] = datetime.utcfromtimestamp(args['start_time'])
     except:
         return api_helpers.error_response(
             'Poorly formated start_time parameter', 400)
     app_name_metrics = get_app_name_metrics(app_name, args)
     response = success_response(app_name_metrics)
     return response
Exemple #21
0
    def get(self):
        args = top_genre_users_route_parser.parse_args()
        limit = get_default_max(args.get('limit'), 10, 100)
        offset = get_default_max(args.get('offset'), 0)

        get_top_genre_users_args = {
            'limit': limit,
            'offset': offset,
            'with_users': True
        }
        if args['genre'] is not None:
            get_top_genre_users_args['genre'] = args['genre']
        top_users = get_top_genre_users(get_top_genre_users_args)
        users = list(map(extend_user, top_users['users']))
        return success_response(users)
Exemple #22
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)
 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)
    def get(self):
        args = top_genre_users_route_parser.parse_args()
        limit = get_default_max(args.get("limit"), 10, 100)
        offset = get_default_max(args.get("offset"), 0)

        get_top_genre_users_args = {
            "limit": limit,
            "offset": offset,
            "with_users": True,
        }
        if args["genre"] is not None:
            get_top_genre_users_args["genre"] = args["genre"]
        top_users = get_top_genre_users(get_top_genre_users_args)
        users = list(map(extend_user, top_users["users"]))
        return success_response(users)
 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)
Exemple #26
0
 def get(self, app_name):
     """Get the app name metrics"""
     args = metrics_app_name_parser.parse_args()
     if args.get('limit') is None:
         args['limit'] = 48
     else:
         args['limit'] = min(args.get('limit'), 48)
     try:
         args['start_time'] = parse_unix_epoch_param(
             args.get('start_time'), 0)
     except:
         abort_bad_request_param('start_time', ns)
     app_name_metrics = get_app_name_metrics(app_name, args)
     response = success_response(app_name_metrics)
     return response
Exemple #27
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)
Exemple #28
0
 def get(self):
     """Search for a playlist."""
     args = search_parser.parse_args()
     query = args["query"]
     search_args = {
         "query": query,
         "kind": SearchKind.playlists.name,
         "is_auto_complete": False,
         "current_user_id": None,
         "with_users": True,
         "limit": 10,
         "offset": 0
     }
     response = search(search_args)
     playlists = list(map(extend_playlist, response["playlists"]))
     return success_response(playlists)
 def get(self):
     args = search_parser.parse_args()
     query = args["query"]
     if not query:
         abort_bad_request_param("query", ns)
     search_args = {
         "query": query,
         "kind": SearchKind.users.name,
         "is_auto_complete": False,
         "current_user_id": None,
         "with_users": True,
         "limit": 10,
         "offset": 0,
     }
     response = search(search_args)
     return success_response(response)
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)