Пример #1
0
def get_full_trending_playlists(request, args, strategy):
    offset, limit = format_offset(args), format_limit(args, TRENDING_LIMIT)
    current_user_id, time = args.get("user_id"), args.get("time", "week")
    time = "week" if time not in ["week", "month", "year"] else time

    # If we have a user_id, we call into `get_trending_playlist`
    # which fetches the cached unpopulated tracks and then
    # populates metadata. Otherwise, just
    # retrieve the last cached value.
    #
    # If current_user_id,
    # apply limit + offset inside the cached calculation.
    # Otherwise, apply it here.
    if current_user_id:
        args = {
            'time': time,
            'with_tracks': True,
            'limit': limit,
            'offset': offset
        }
        decoded = decode_string_id(current_user_id)
        args["current_user_id"] = decoded
        playlists = get_trending_playlists(args, strategy)
    else:
        args = {
            'time': time,
            'with_tracks': True,
        }
        key = get_trending_cache_key(to_dict(request.args), request.path)
        playlists = use_redis_cache(
            key, TRENDING_TTL_SEC,
            lambda: get_trending_playlists(args, strategy))
        playlists = playlists[offset:limit + offset]

    return playlists
Пример #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)
Пример #3
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)
Пример #4
0
    def get(self, time_range):
        """Gets aggregated app 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_app_metrics_parser.parse_args()
        limit = format_limit(args, max_limit=100)
        metrics = get_aggregate_app_metrics(time_range, limit)
        response = success_response(metrics)
        return response
Пример #5
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)
Пример #6
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])
Пример #7
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)
Пример #8
0
def get_full_trending(request, args, strategy):
    offset = format_offset(args)
    limit = format_limit(args, TRENDING_LIMIT)
    key = get_trending_cache_key(to_dict(request.args), request.path)

    # Attempt to use the cached tracks list
    if args['user_id'] is not None:
        full_trending = get_trending(args, strategy)
    else:
        full_trending = use_redis_cache(key, TRENDING_TTL_SEC,
                                        lambda: get_trending(args, strategy))
    trending_tracks = full_trending[offset:limit + offset]
    return trending_tracks
Пример #9
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)
Пример #10
0
    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)
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
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)
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
Пример #19
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)
Пример #20
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)
Пример #21
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)
Пример #22
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)
Пример #23
0
 def get(self):
     args = random_track_parser.parse_args()
     limit = format_limit(args, default_limit=DEFAULT_RANDOM_LIMIT)
     args['limit'] = max(TRENDING_LIMIT, limit)
     tracks = get_random_tracks(args)
     return success_response(tracks[:limit])