feat(smart): smart playlists made for everybody, without making them
- A fixed set that is there with no setup: recently added, never played, most played, not heard for a while, high quality files and long tracks. The rules are the same for everyone and are worked out on each one's own library and history, like the mixes; nothing is stored, so they follow the library.
- GET /smart-playlists/suggested, GET /smart-playlists/suggested/{key}/tracks and POST /smart-playlists/suggested/{key}/playlist.
- The Smart playlists page begins with them, with names and descriptions in the language of the page. A suggested one can be played, shuffled again, kept as a playlist, or made one's own: a copy of its rules opens in the editor.
This commit is contained in:
parent
b598842c6d
commit
17f70d582d
2 changed files with 920 additions and 28 deletions
183
web/src/api/schema.d.ts
vendored
183
web/src/api/schema.d.ts
vendored
|
|
@ -962,6 +962,78 @@ export interface paths {
|
|||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/smart-playlists/suggested": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* The smart playlists Sonda makes for you
|
||||
* @description A fixed set that is there without anybody making it, the same rules for everyone and worked out on your
|
||||
* own library and history: `recently-added`, `never-played`, `most-played`, `forgotten` (played once, but not
|
||||
* in the last 90 days), `high-quality` (bitrate of 900 kbps or more) and `long-tracks` (6 minutes or more).
|
||||
* Nothing is stored for them. A client says their names in its own language from the `key`. To change one,
|
||||
* make a smart playlist of your own from its rules with `POST /smart-playlists`.
|
||||
*/
|
||||
get: operations["listSuggestedSmartPlaylists"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/smart-playlists/suggested/{key}/tracks": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
/** @description A key from `GET /smart-playlists/suggested`. */
|
||||
key: components["parameters"]["SuggestedKey"];
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* The songs of a suggested smart playlist, now
|
||||
* @description Works the rules out for you, as `GET /smart-playlists/{id}/tracks` does for yours. With the random order
|
||||
* the songs stay the same all day, and another `variant` gives other ones.
|
||||
*/
|
||||
get: operations["getSuggestedSmartPlaylistTracks"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/smart-playlists/suggested/{key}/playlist": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
/** @description A key from `GET /smart-playlists/suggested`. */
|
||||
key: components["parameters"]["SuggestedKey"];
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
get?: never;
|
||||
put?: never;
|
||||
/**
|
||||
* Keep a suggested smart playlist as a playlist
|
||||
* @description Makes a playlist of your own with the songs that `variant` gives now, in the same order. It is a copy,
|
||||
* and is yours to edit. The body is optional; without a name the playlist is called by the `key`.
|
||||
*/
|
||||
post: operations["saveSuggestedSmartPlaylist"];
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/smart-playlists/{id}": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
|
|
@ -2312,6 +2384,16 @@ export interface components {
|
|||
min_duration_sec?: number;
|
||||
max_duration_sec?: number;
|
||||
};
|
||||
SuggestedSmartPlaylist: {
|
||||
/** @enum {string} */
|
||||
key: "recently-added" | "never-played" | "most-played" | "forgotten" | "high-quality" | "long-tracks";
|
||||
rules: components["schemas"]["SmartRules"];
|
||||
sort: components["schemas"]["SmartSort"];
|
||||
limit: number;
|
||||
};
|
||||
SuggestedSmartPlaylistList: {
|
||||
items: components["schemas"]["SuggestedSmartPlaylist"][];
|
||||
};
|
||||
/**
|
||||
* @description A tie always goes to the lower song id.
|
||||
* @enum {string}
|
||||
|
|
@ -2727,6 +2809,15 @@ export interface components {
|
|||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description No such suggested smart playlist (`suggested_not_found`). */
|
||||
SuggestedNotFound: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
/** @description No such smart playlist, or it is somebody else's (`smart_playlist_not_found`). */
|
||||
SmartPlaylistNotFound: {
|
||||
headers: {
|
||||
|
|
@ -2788,6 +2879,8 @@ export interface components {
|
|||
/** @description Page size. 50 when absent or 0; values above 200 are lowered to 200. */
|
||||
Limit: number;
|
||||
Offset: number;
|
||||
/** @description A key from `GET /smart-playlists/suggested`. */
|
||||
SuggestedKey: "recently-added" | "never-played" | "most-played" | "forgotten" | "high-quality" | "long-tracks";
|
||||
/** @description `favourites`, `rediscover`, `unheard` or `genre:<name>` (percent-encoded). */
|
||||
MixId: string;
|
||||
/** @description Only items with a playable file in this library. */
|
||||
|
|
@ -4344,6 +4437,96 @@ export interface operations {
|
|||
401: components["responses"]["Unauthorized"];
|
||||
};
|
||||
};
|
||||
listSuggestedSmartPlaylists: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description The suggested smart playlists. */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["SuggestedSmartPlaylistList"];
|
||||
};
|
||||
};
|
||||
401: components["responses"]["Unauthorized"];
|
||||
};
|
||||
};
|
||||
getSuggestedSmartPlaylistTracks: {
|
||||
parameters: {
|
||||
query?: {
|
||||
/** @description Other songs for the random order, from 0 (the songs of the day) up. */
|
||||
variant?: number;
|
||||
};
|
||||
header?: never;
|
||||
path: {
|
||||
/** @description A key from `GET /smart-playlists/suggested`. */
|
||||
key: components["parameters"]["SuggestedKey"];
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description The songs. */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["SmartTracks"];
|
||||
};
|
||||
};
|
||||
400: components["responses"]["InvalidInput"];
|
||||
401: components["responses"]["Unauthorized"];
|
||||
404: components["responses"]["SuggestedNotFound"];
|
||||
};
|
||||
};
|
||||
saveSuggestedSmartPlaylist: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path: {
|
||||
/** @description A key from `GET /smart-playlists/suggested`. */
|
||||
key: components["parameters"]["SuggestedKey"];
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: {
|
||||
content: {
|
||||
"application/json": components["schemas"]["SaveSmartPlaylist"];
|
||||
};
|
||||
};
|
||||
responses: {
|
||||
/** @description The playlist. */
|
||||
201: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Playlist"];
|
||||
};
|
||||
};
|
||||
400: components["responses"]["InvalidInput"];
|
||||
401: components["responses"]["Unauthorized"];
|
||||
404: components["responses"]["SuggestedNotFound"];
|
||||
409: components["responses"]["PlaylistLimit"];
|
||||
/** @description The rules give no songs to save (`smart_playlist_empty`). */
|
||||
422: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["Error"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
getSmartPlaylist: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
|
|
|
|||
|
|
@ -51,6 +51,40 @@ export function useSmartPreview(input: SmartInput) {
|
|||
})
|
||||
}
|
||||
|
||||
/** A smart playlist that Sonda makes for everybody: a key (its name comes from the texts of the page) and its rules. */
|
||||
export interface SuggestedSmart extends SmartInput {
|
||||
key: string
|
||||
}
|
||||
|
||||
/** The smart playlists that are there without making them. */
|
||||
export function useSuggested() {
|
||||
return useQuery({
|
||||
queryKey: ['smart-suggested'],
|
||||
queryFn: () => api.get<{ items: SuggestedSmart[] }>('/smart-playlists/suggested').then((r) => r.items),
|
||||
staleTime: 10 * 60_000,
|
||||
})
|
||||
}
|
||||
|
||||
/** The songs of a suggested one now. The songs on screen stay until the next ones arrive. */
|
||||
export function useSuggestedTracks(key: string, variant: number) {
|
||||
return useQuery({
|
||||
queryKey: ['smart-suggested-tracks', key, variant],
|
||||
queryFn: () =>
|
||||
api.get<{ variant: number; tracks: Track[] }>(`/smart-playlists/suggested/${encodeURIComponent(key)}/tracks`, variant > 0 ? { variant } : undefined),
|
||||
placeholderData: keepPreviousData,
|
||||
})
|
||||
}
|
||||
|
||||
/** Keeps the songs of a suggested one on screen as a normal playlist of mine. */
|
||||
export function useSaveSuggested() {
|
||||
const client = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ key, ...body }: { key: string; name: string; variant: number }) =>
|
||||
api.post<Playlist>(`/smart-playlists/suggested/${encodeURIComponent(key)}/playlist`, body),
|
||||
onSuccess: () => refreshPlaylists(client),
|
||||
})
|
||||
}
|
||||
|
||||
/** The genres of the library with their songs, the biggest first. */
|
||||
export function useGenres() {
|
||||
return useQuery({
|
||||
|
|
|
|||
Loading…
Reference in a new issue