Add alternative names and cover art for soundtracks
Alternative names (#32): - PUT /api/v1/soundtracks/{uuid}/alternative-names replaces a soundtrack's alternative names (trimmed, deduplicated, without the soundtrack's own name). - alternative_names is in the soundtrack and statistics responses. - /find matches them too and shows which name matched. Covers (#12), stored in COVERS_PATH and off when it is not set: - GET, PUT (upload) and DELETE /api/v1/soundtracks/{uuid}/cover, and PUT .../cover/source to pick a SteamGridDB game or AniList anime by ID. Uploaded and picked covers are never replaced automatically. - With STEAMGRIDDB_API_KEY, a background job searches SteamGridDB, then AniList, by name, alternative names and the name without bracketed parts, at startup, after a sync and after names change. Search results are ranked by matching words, so "Civilization IV" gets "Sid Meier's Civilization IV". - cover_modified (Unix seconds) is in the soundtrack and statistics responses, so clients can cache covers. The new columns are added to migration 000006, which is not released yet. Closes #12, closes #32 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f79f51ea4c
commit
bb8de5548d
39 files changed
+2418
-99
No files matched your search
@@ -1,3 +1,11 @@
|
||||
ALTER TABLE soundtrack
|
||||
DROP COLUMN alternative_names,
|
||||
DROP COLUMN cover_file,
|
||||
DROP COLUMN cover_source,
|
||||
DROP COLUMN cover_external_id,
|
||||
DROP COLUMN cover_manual,
|
||||
DROP COLUMN cover_modified,
|
||||
DROP COLUMN cover_checked;
|
||||
DROP TABLE queue_song;
|
||||
DROP TABLE queue;
|
||||
ALTER TABLE soundtrack DROP COLUMN fingerprint;
|
||||
@@ -27,3 +27,17 @@ CREATE TABLE queue_song (
|
||||
added_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
PRIMARY KEY (queue_uuid, song_no)
|
||||
);
|
||||
|
||||
-- Other names a soundtrack is known by, for search and the cover search.
|
||||
ALTER TABLE soundtrack ADD COLUMN alternative_names TEXT[] NOT NULL DEFAULT '{}';
|
||||
|
||||
-- Cover art. cover_file is the image's file name in COVERS_PATH, NULL when there is no
|
||||
-- cover. Manual covers (uploaded or picked) are never replaced by the background job.
|
||||
-- cover_checked is when the job last searched, so soundtracks without a match are not
|
||||
-- searched again for a while.
|
||||
ALTER TABLE soundtrack ADD COLUMN cover_file TEXT NULL;
|
||||
ALTER TABLE soundtrack ADD COLUMN cover_source VARCHAR(20) NULL;
|
||||
ALTER TABLE soundtrack ADD COLUMN cover_external_id TEXT NULL;
|
||||
ALTER TABLE soundtrack ADD COLUMN cover_manual BOOLEAN NOT NULL DEFAULT false;
|
||||
ALTER TABLE soundtrack ADD COLUMN cover_modified TIMESTAMPTZ NULL;
|
||||
ALTER TABLE soundtrack ADD COLUMN cover_checked TIMESTAMPTZ NULL;
|
||||
@@ -65,3 +65,44 @@ SELECT uuid FROM soundtrack WHERE id = $1;
|
||||
|
||||
-- name: AddSoundtrackPlayedByUUID :exec
|
||||
UPDATE soundtrack SET times_played = times_played + 1, last_played = now() WHERE uuid = $1;
|
||||
|
||||
-- name: SetAlternativeNames :one
|
||||
-- Replaces the alternative names. A soundtrack without a cover is searched again with them.
|
||||
UPDATE soundtrack
|
||||
SET alternative_names = sqlc.arg(names)::text[],
|
||||
cover_checked = CASE WHEN cover_file IS NULL THEN NULL ELSE cover_checked END
|
||||
WHERE uuid = sqlc.arg(uuid) AND deleted IS NULL
|
||||
RETURNING *;
|
||||
|
||||
-- name: ListSoundtracksNeedingCover :many
|
||||
-- Active soundtracks without a cover that the job has not searched since checked_before.
|
||||
SELECT uuid, soundtrack_name, alternative_names
|
||||
FROM soundtrack
|
||||
WHERE deleted IS NULL
|
||||
AND cover_file IS NULL
|
||||
AND NOT cover_manual
|
||||
AND (cover_checked IS NULL OR cover_checked < sqlc.arg(checked_before))
|
||||
ORDER BY soundtrack_name;
|
||||
|
||||
-- name: SetCover :exec
|
||||
UPDATE soundtrack
|
||||
SET cover_file = sqlc.arg(file),
|
||||
cover_source = sqlc.arg(source),
|
||||
cover_external_id = sqlc.arg(external_id),
|
||||
cover_manual = sqlc.arg(manual),
|
||||
cover_modified = now(),
|
||||
cover_checked = now()
|
||||
WHERE uuid = sqlc.arg(uuid);
|
||||
|
||||
-- name: MarkCoverChecked :exec
|
||||
UPDATE soundtrack SET cover_checked = now() WHERE uuid = $1;
|
||||
|
||||
-- name: ClearCover :exec
|
||||
-- Removes the cover, so the job searches for one again.
|
||||
UPDATE soundtrack
|
||||
SET cover_file = NULL, cover_source = NULL, cover_external_id = NULL, cover_manual = false,
|
||||
cover_modified = NULL, cover_checked = NULL
|
||||
WHERE uuid = $1;
|
||||
|
||||
-- name: ListCoverFiles :many
|
||||
SELECT cover_file::text FROM soundtrack WHERE cover_file IS NOT NULL;
|
||||
@@ -5,6 +5,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -33,6 +35,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -95,6 +99,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.added,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -121,6 +127,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -148,6 +156,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -188,6 +198,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
|
||||
@@ -59,18 +59,25 @@ type SongList struct {
|
||||
}
|
||||
|
||||
type Soundtrack struct {
|
||||
ID int32 `json:"id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Added time.Time `json:"added"`
|
||||
Deleted *time.Time `json:"deleted"`
|
||||
LastChanged *time.Time `json:"last_changed"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
LastPlayed *time.Time `json:"last_played"`
|
||||
NumberOfSongs int32 `json:"number_of_songs"`
|
||||
Hash string `json:"hash"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
ID int32 `json:"id"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
Added time.Time `json:"added"`
|
||||
Deleted *time.Time `json:"deleted"`
|
||||
LastChanged *time.Time `json:"last_changed"`
|
||||
Path string `json:"path"`
|
||||
TimesPlayed int32 `json:"times_played"`
|
||||
LastPlayed *time.Time `json:"last_played"`
|
||||
NumberOfSongs int32 `json:"number_of_songs"`
|
||||
Hash string `json:"hash"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverFile *string `json:"cover_file"`
|
||||
CoverSource *string `json:"cover_source"`
|
||||
CoverExternalID *string `json:"cover_external_id"`
|
||||
CoverManual bool `json:"cover_manual"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
CoverChecked pgtype.Timestamptz `json:"cover_checked"`
|
||||
}
|
||||
|
||||
type Vgmq struct {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
type Querier interface {
|
||||
@@ -23,6 +24,8 @@ type Querier interface {
|
||||
AddSoundtrackPlayedByUUID(ctx context.Context, argUuid uuid.UUID) error
|
||||
CheckSong(ctx context.Context, arg CheckSongParams) (int64, error)
|
||||
CheckSongWithHash(ctx context.Context, hash string) (int64, error)
|
||||
// Removes the cover, so the job searches for one again.
|
||||
ClearCover(ctx context.Context, argUuid uuid.UUID) error
|
||||
ClearSongs(ctx context.Context) error
|
||||
ClearSongsBySoundtrackId(ctx context.Context, soundtrackID int32) error
|
||||
ClearSoundtracks(ctx context.Context) error
|
||||
@@ -73,14 +76,21 @@ type Querier interface {
|
||||
InsertSongInList(ctx context.Context, arg InsertSongInListParams) error
|
||||
InsertSoundtrack(ctx context.Context, arg InsertSoundtrackParams) (InsertSoundtrackRow, error)
|
||||
InsertSoundtrackWithExistingId(ctx context.Context, arg InsertSoundtrackWithExistingIdParams) error
|
||||
ListCoverFiles(ctx context.Context) ([]string, error)
|
||||
// The song columns are NULL when the song has been removed from the library since.
|
||||
ListQueueSongs(ctx context.Context, queueUuid uuid.UUID) ([]ListQueueSongsRow, error)
|
||||
ListSessions(ctx context.Context) ([]Session, error)
|
||||
// Active soundtracks without a cover that the job has not searched since checked_before.
|
||||
ListSoundtracksNeedingCover(ctx context.Context, checkedBefore pgtype.Timestamptz) ([]ListSoundtracksNeedingCoverRow, error)
|
||||
MarkCoverChecked(ctx context.Context, argUuid uuid.UUID) error
|
||||
MarkSoundtracksDeletedExcept(ctx context.Context, ids []int32) error
|
||||
RemoveBrokenSong(ctx context.Context, arg RemoveBrokenSongParams) error
|
||||
RemoveBrokenSongs(ctx context.Context, uuids []uuid.UUID) error
|
||||
RemoveSoundtrackDeletionDate(ctx context.Context, id int32) error
|
||||
ResetSoundtrackIdSeq(ctx context.Context) (int64, error)
|
||||
// Replaces the alternative names. A soundtrack without a cover is searched again with them.
|
||||
SetAlternativeNames(ctx context.Context, arg SetAlternativeNamesParams) (Soundtrack, error)
|
||||
SetCover(ctx context.Context, arg SetCoverParams) error
|
||||
SetQueueCurrentSong(ctx context.Context, arg SetQueueCurrentSongParams) error
|
||||
SetQueueLastFetched(ctx context.Context, arg SetQueueLastFetchedParams) error
|
||||
SetSoundtrackDeletionDate(ctx context.Context) error
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const addSoundtrackPlayed = `-- name: AddSoundtrackPlayed :exec
|
||||
@@ -29,6 +30,19 @@ func (q *Queries) AddSoundtrackPlayedByUUID(ctx context.Context, argUuid uuid.UU
|
||||
return err
|
||||
}
|
||||
|
||||
const clearCover = `-- name: ClearCover :exec
|
||||
UPDATE soundtrack
|
||||
SET cover_file = NULL, cover_source = NULL, cover_external_id = NULL, cover_manual = false,
|
||||
cover_modified = NULL, cover_checked = NULL
|
||||
WHERE uuid = $1
|
||||
`
|
||||
|
||||
// Removes the cover, so the job searches for one again.
|
||||
func (q *Queries) ClearCover(ctx context.Context, argUuid uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, clearCover, argUuid)
|
||||
return err
|
||||
}
|
||||
|
||||
const clearSoundtracks = `-- name: ClearSoundtracks :exec
|
||||
DELETE FROM soundtrack
|
||||
`
|
||||
@@ -39,7 +53,7 @@ func (q *Queries) ClearSoundtracks(ctx context.Context) error {
|
||||
}
|
||||
|
||||
const findAllSoundtracks = `-- name: FindAllSoundtracks :many
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint, alternative_names, cover_file, cover_source, cover_external_id, cover_manual, cover_modified, cover_checked
|
||||
FROM soundtrack
|
||||
WHERE deleted IS NULL
|
||||
ORDER BY soundtrack_name
|
||||
@@ -67,6 +81,13 @@ func (q *Queries) FindAllSoundtracks(ctx context.Context) ([]Soundtrack, error)
|
||||
&i.Hash,
|
||||
&i.Uuid,
|
||||
&i.Fingerprint,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverFile,
|
||||
&i.CoverSource,
|
||||
&i.CoverExternalID,
|
||||
&i.CoverManual,
|
||||
&i.CoverModified,
|
||||
&i.CoverChecked,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -79,7 +100,7 @@ func (q *Queries) FindAllSoundtracks(ctx context.Context) ([]Soundtrack, error)
|
||||
}
|
||||
|
||||
const getAllSoundtracksIncludingDeleted = `-- name: GetAllSoundtracksIncludingDeleted :many
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint, alternative_names, cover_file, cover_source, cover_external_id, cover_manual, cover_modified, cover_checked
|
||||
FROM soundtrack
|
||||
ORDER BY soundtrack_name
|
||||
`
|
||||
@@ -106,6 +127,13 @@ func (q *Queries) GetAllSoundtracksIncludingDeleted(ctx context.Context) ([]Soun
|
||||
&i.Hash,
|
||||
&i.Uuid,
|
||||
&i.Fingerprint,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverFile,
|
||||
&i.CoverSource,
|
||||
&i.CoverExternalID,
|
||||
&i.CoverManual,
|
||||
&i.CoverModified,
|
||||
&i.CoverChecked,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -129,7 +157,7 @@ func (q *Queries) GetIdBySoundtrackName(ctx context.Context, soundtrackName stri
|
||||
}
|
||||
|
||||
const getSoundtrackById = `-- name: GetSoundtrackById :one
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint, alternative_names, cover_file, cover_source, cover_external_id, cover_manual, cover_modified, cover_checked
|
||||
FROM soundtrack
|
||||
WHERE id = $1
|
||||
AND deleted IS NULL
|
||||
@@ -151,12 +179,19 @@ func (q *Queries) GetSoundtrackById(ctx context.Context, id int32) (Soundtrack,
|
||||
&i.Hash,
|
||||
&i.Uuid,
|
||||
&i.Fingerprint,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverFile,
|
||||
&i.CoverSource,
|
||||
&i.CoverExternalID,
|
||||
&i.CoverManual,
|
||||
&i.CoverModified,
|
||||
&i.CoverChecked,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSoundtrackByUUID = `-- name: GetSoundtrackByUUID :one
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint
|
||||
SELECT id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint, alternative_names, cover_file, cover_source, cover_external_id, cover_manual, cover_modified, cover_checked
|
||||
FROM soundtrack
|
||||
WHERE uuid = $1
|
||||
AND deleted IS NULL
|
||||
@@ -178,6 +213,13 @@ func (q *Queries) GetSoundtrackByUUID(ctx context.Context, argUuid uuid.UUID) (S
|
||||
&i.Hash,
|
||||
&i.Uuid,
|
||||
&i.Fingerprint,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverFile,
|
||||
&i.CoverSource,
|
||||
&i.CoverExternalID,
|
||||
&i.CoverManual,
|
||||
&i.CoverModified,
|
||||
&i.CoverChecked,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -253,6 +295,76 @@ func (q *Queries) InsertSoundtrackWithExistingId(ctx context.Context, arg Insert
|
||||
return err
|
||||
}
|
||||
|
||||
const listCoverFiles = `-- name: ListCoverFiles :many
|
||||
SELECT cover_file::text FROM soundtrack WHERE cover_file IS NOT NULL
|
||||
`
|
||||
|
||||
func (q *Queries) ListCoverFiles(ctx context.Context) ([]string, error) {
|
||||
rows, err := q.db.Query(ctx, listCoverFiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []string
|
||||
for rows.Next() {
|
||||
var cover_file string
|
||||
if err := rows.Scan(&cover_file); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, cover_file)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listSoundtracksNeedingCover = `-- name: ListSoundtracksNeedingCover :many
|
||||
SELECT uuid, soundtrack_name, alternative_names
|
||||
FROM soundtrack
|
||||
WHERE deleted IS NULL
|
||||
AND cover_file IS NULL
|
||||
AND NOT cover_manual
|
||||
AND (cover_checked IS NULL OR cover_checked < $1)
|
||||
ORDER BY soundtrack_name
|
||||
`
|
||||
|
||||
type ListSoundtracksNeedingCoverRow struct {
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
}
|
||||
|
||||
// Active soundtracks without a cover that the job has not searched since checked_before.
|
||||
func (q *Queries) ListSoundtracksNeedingCover(ctx context.Context, checkedBefore pgtype.Timestamptz) ([]ListSoundtracksNeedingCoverRow, error) {
|
||||
rows, err := q.db.Query(ctx, listSoundtracksNeedingCover, checkedBefore)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []ListSoundtracksNeedingCoverRow
|
||||
for rows.Next() {
|
||||
var i ListSoundtracksNeedingCoverRow
|
||||
if err := rows.Scan(&i.Uuid, &i.SoundtrackName, &i.AlternativeNames); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const markCoverChecked = `-- name: MarkCoverChecked :exec
|
||||
UPDATE soundtrack SET cover_checked = now() WHERE uuid = $1
|
||||
`
|
||||
|
||||
func (q *Queries) MarkCoverChecked(ctx context.Context, argUuid uuid.UUID) error {
|
||||
_, err := q.db.Exec(ctx, markCoverChecked, argUuid)
|
||||
return err
|
||||
}
|
||||
|
||||
const markSoundtracksDeletedExcept = `-- name: MarkSoundtracksDeletedExcept :exec
|
||||
UPDATE soundtrack SET deleted=now() WHERE deleted IS NULL AND NOT (id = ANY($1::int[]))
|
||||
`
|
||||
@@ -282,6 +394,77 @@ func (q *Queries) ResetSoundtrackIdSeq(ctx context.Context) (int64, error) {
|
||||
return setval, err
|
||||
}
|
||||
|
||||
const setAlternativeNames = `-- name: SetAlternativeNames :one
|
||||
UPDATE soundtrack
|
||||
SET alternative_names = $1::text[],
|
||||
cover_checked = CASE WHEN cover_file IS NULL THEN NULL ELSE cover_checked END
|
||||
WHERE uuid = $2 AND deleted IS NULL
|
||||
RETURNING id, soundtrack_name, added, deleted, last_changed, path, times_played, last_played, number_of_songs, hash, uuid, fingerprint, alternative_names, cover_file, cover_source, cover_external_id, cover_manual, cover_modified, cover_checked
|
||||
`
|
||||
|
||||
type SetAlternativeNamesParams struct {
|
||||
Names []string `json:"names"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
}
|
||||
|
||||
// Replaces the alternative names. A soundtrack without a cover is searched again with them.
|
||||
func (q *Queries) SetAlternativeNames(ctx context.Context, arg SetAlternativeNamesParams) (Soundtrack, error) {
|
||||
row := q.db.QueryRow(ctx, setAlternativeNames, arg.Names, arg.Uuid)
|
||||
var i Soundtrack
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.SoundtrackName,
|
||||
&i.Added,
|
||||
&i.Deleted,
|
||||
&i.LastChanged,
|
||||
&i.Path,
|
||||
&i.TimesPlayed,
|
||||
&i.LastPlayed,
|
||||
&i.NumberOfSongs,
|
||||
&i.Hash,
|
||||
&i.Uuid,
|
||||
&i.Fingerprint,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverFile,
|
||||
&i.CoverSource,
|
||||
&i.CoverExternalID,
|
||||
&i.CoverManual,
|
||||
&i.CoverModified,
|
||||
&i.CoverChecked,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const setCover = `-- name: SetCover :exec
|
||||
UPDATE soundtrack
|
||||
SET cover_file = $1,
|
||||
cover_source = $2,
|
||||
cover_external_id = $3,
|
||||
cover_manual = $4,
|
||||
cover_modified = now(),
|
||||
cover_checked = now()
|
||||
WHERE uuid = $5
|
||||
`
|
||||
|
||||
type SetCoverParams struct {
|
||||
File *string `json:"file"`
|
||||
Source *string `json:"source"`
|
||||
ExternalID *string `json:"external_id"`
|
||||
Manual bool `json:"manual"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
}
|
||||
|
||||
func (q *Queries) SetCover(ctx context.Context, arg SetCoverParams) error {
|
||||
_, err := q.db.Exec(ctx, setCover,
|
||||
arg.File,
|
||||
arg.Source,
|
||||
arg.ExternalID,
|
||||
arg.Manual,
|
||||
arg.Uuid,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const setSoundtrackDeletionDate = `-- name: SetSoundtrackDeletionDate :exec
|
||||
UPDATE soundtrack SET deleted=now() WHERE deleted IS NULL
|
||||
`
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const countLibrary = `-- name: CountLibrary :one
|
||||
@@ -37,6 +38,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -59,12 +62,14 @@ ORDER BY g.soundtrack_name
|
||||
`
|
||||
|
||||
type GetAllSoundtracksWithSongsRow struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Every soundtrack with its songs, by name
|
||||
@@ -82,6 +87,8 @@ func (q *Queries) GetAllSoundtracksWithSongs(ctx context.Context) ([]GetAllSound
|
||||
&i.SoundtrackUuid,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverModified,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
@@ -101,6 +108,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -123,12 +132,14 @@ LIMIT $1
|
||||
`
|
||||
|
||||
type GetLastPlayedSoundtracksRow struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Last played soundtracks (most recently played)
|
||||
@@ -146,6 +157,8 @@ func (q *Queries) GetLastPlayedSoundtracks(ctx context.Context, limit int32) ([]
|
||||
&i.SoundtrackUuid,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverModified,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
@@ -223,6 +236,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -246,12 +261,14 @@ LIMIT $1
|
||||
`
|
||||
|
||||
type GetLeastPlayedSoundtracksWithSongsRow struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Least played soundtracks with their songs
|
||||
@@ -269,6 +286,8 @@ func (q *Queries) GetLeastPlayedSoundtracksWithSongs(ctx context.Context, limit
|
||||
&i.SoundtrackUuid,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverModified,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
@@ -346,6 +365,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -369,12 +390,14 @@ LIMIT $1
|
||||
`
|
||||
|
||||
type GetMostPlayedSoundtracksWithSongsRow struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Most played soundtracks with their songs
|
||||
@@ -392,6 +415,8 @@ func (q *Queries) GetMostPlayedSoundtracksWithSongs(ctx context.Context, limit i
|
||||
&i.SoundtrackUuid,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverModified,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
@@ -411,6 +436,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.added,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -432,12 +459,14 @@ ORDER BY g.soundtrack_name
|
||||
`
|
||||
|
||||
type GetNeverPlayedSoundtracksRow struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
Added time.Time `json:"added"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
Added time.Time `json:"added"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Soundtracks that have never been played (times_played = 0)
|
||||
@@ -455,6 +484,8 @@ func (q *Queries) GetNeverPlayedSoundtracks(ctx context.Context) ([]GetNeverPlay
|
||||
&i.SoundtrackUuid,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverModified,
|
||||
&i.Added,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
@@ -474,6 +505,8 @@ SELECT
|
||||
g.uuid as soundtrack_uuid,
|
||||
g.soundtrack_name,
|
||||
g.times_played as soundtrack_played,
|
||||
g.alternative_names,
|
||||
g.cover_modified,
|
||||
g.last_played as soundtrack_last_played,
|
||||
COALESCE(
|
||||
json_agg(
|
||||
@@ -496,12 +529,14 @@ LIMIT $1
|
||||
`
|
||||
|
||||
type GetOldestPlayedSoundtracksRow struct {
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
SoundtrackID int32 `json:"soundtrack_id"`
|
||||
SoundtrackUuid uuid.UUID `json:"soundtrack_uuid"`
|
||||
SoundtrackName string `json:"soundtrack_name"`
|
||||
SoundtrackPlayed int32 `json:"soundtrack_played"`
|
||||
AlternativeNames []string `json:"alternative_names"`
|
||||
CoverModified pgtype.Timestamptz `json:"cover_modified"`
|
||||
SoundtrackLastPlayed *time.Time `json:"soundtrack_last_played"`
|
||||
Songs []byte `json:"songs"`
|
||||
}
|
||||
|
||||
// Oldest played soundtracks (least recently played, but has been played at least once)
|
||||
@@ -519,6 +554,8 @@ func (q *Queries) GetOldestPlayedSoundtracks(ctx context.Context, limit int32) (
|
||||
&i.SoundtrackUuid,
|
||||
&i.SoundtrackName,
|
||||
&i.SoundtrackPlayed,
|
||||
&i.AlternativeNames,
|
||||
&i.CoverModified,
|
||||
&i.SoundtrackLastPlayed,
|
||||
&i.Songs,
|
||||
); err != nil {
|
||||
|
||||
Reference in new issue
Block a user