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)
def get(self): args = search_route_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) resp = extend_search(resp) return success_response(resp)
def get_underground_trending(request, args, strategy): offset, limit = format_offset(args), format_limit(args, TRENDING_LIMIT) current_user_id = args.get("user_id") args = {'limit': limit, 'offset': offset} # If user ID, let _get_underground_trending # handle caching + limit + offset if current_user_id: decoded = decode_string_id(current_user_id) args["current_user_id"] = decoded trending = _get_underground_trending(args, strategy) else: # If no user ID, fetch all cached tracks # and perform pagination here, passing # no args so we get the full list of tracks. key = get_trending_cache_key(to_dict(request.args), request.path) trending = use_redis_cache( key, TRENDING_TTL_SEC, lambda: _get_underground_trending({}, strategy)) trending = trending[offset:limit + offset] return trending
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)
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)
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)
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)
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)