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 transform_tracks(tracks, users_by_id, current_user): tracks_out = [] for track in tracks: track = populate_track_or_playlist_metadata_es(track, current_user) track = extend_track(track) tracks_out.append(track) return tracks_out
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)
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)
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)