catalog

package
v0.1.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package catalog manages the internal metadata of the catalog of music the user has submitted listens for. This includes artists, releases (album, single, ep, etc), and tracks, as well as ingesting listens submitted both via the API(s) and other methods.

Index

Constants

View Source
const (
	ImageSourceUserUpload = "User Upload"
)

Variables

This section is empty.

Functions

func AssociateAlbum

func AssociateAlbum(ctx context.Context, d db.DB, opts AssociateAlbumOpts) (*models.Album, error)

func AssociateArtists

func AssociateArtists(ctx context.Context, d db.DB, opts AssociateArtistsOpts) ([]*models.Artist, error)

func AssociateTrack

func AssociateTrack(ctx context.Context, d db.DB, opts AssociateTrackOpts) (*models.Track, error)

func CompressAndSaveImage

func CompressAndSaveImage(ctx context.Context, filename string, size ImageSize, body io.Reader) error

Compresses an image to the specified size, then saves it to the correct cache folder.

func DeleteImage

func DeleteImage(filename uuid.UUID) error

func DownloadAndCacheImage

func DownloadAndCacheImage(ctx context.Context, id uuid.UUID, url string, size ImageSize) error

DownloadAndCacheImage downloads an image from the given URL, then calls CompressAndSaveImage.

func GetImageSize

func GetImageSize(size ImageSize) int

func ParseArtists

func ParseArtists(artist string, title string, addlSeparators []*regexp.Regexp) []string

ParseArtists extracts all contributing artist names from the artist and title strings

func PruneOrphanedImages

func PruneOrphanedImages(ctx context.Context, store db.DB) error

Finds any images in all image_cache folders and deletes them if they are not associated with an album or artist.

func SourceImageDir

func SourceImageDir() string

func SubmitListen

func SubmitListen(ctx context.Context, store db.DB, opts SubmitListenOpts) error

func ValidateImageURL

func ValidateImageURL(url string) error

ValidateImageURL checks if the URL points to a valid image by performing a HEAD request.

Types

type ArtistMbidMap

type ArtistMbidMap struct {
	Artist string
	Mbid   uuid.UUID
}

type AssociateAlbumOpts

type AssociateAlbumOpts struct {
	Artists           []*models.Artist
	ReleaseMbzID      uuid.UUID
	ReleaseGroupMbzID uuid.UUID
	ReleaseName       string
	TrackName         string // required
	Mbzc              mbz.MusicBrainzCaller
	SkipCacheImage    bool
	ImageURL          string
}

type AssociateArtistsOpts

type AssociateArtistsOpts struct {
	ArtistMbzIDs  []uuid.UUID
	ArtistNames   []string
	ArtistMbidMap []ArtistMbidMap
	ArtistName    string
	TrackTitle    string
	Mbzc          mbz.MusicBrainzCaller

	SkipCacheImage bool
}

type AssociateTrackOpts

type AssociateTrackOpts struct {
	ArtistIDs  []int32
	AlbumID    int32
	TrackMbzID uuid.UUID
	TrackName  string
	Duration   int32
	Mbzc       mbz.MusicBrainzCaller
}

type GetListensOpts

type GetListensOpts struct {
	ArtistID       int32
	ReleaseGroupID int32
	TrackID        int32
	Limit          int
}

type ImageSize

type ImageSize string
const (
	ImageSizeSmall  ImageSize = "small"
	ImageSizeMedium ImageSize = "medium"
	ImageSizeLarge  ImageSize = "large"
	// imageSizeXL     ImageSize = "xl"
	ImageSizeFull ImageSize = "full"

	ImageCacheDir = "image_cache"
)

func ImageSourceSize

func ImageSourceSize() (size ImageSize)

func ParseImageSize

func ParseImageSize(size string) (ImageSize, error)

type SaveListenOpts

type SaveListenOpts struct {
	TrackID int32
	Time    time.Time
	UserID  int32
	Client  string
}

type SubmitListenOpts

type SubmitListenOpts struct {
	// When true, skips registering the listen and only associates or creates the
	// artist, release, release group, and track in DB
	SkipSaveListen bool

	// When true, skips caching the images and only stores the image url in the db
	SkipCacheImage bool

	MbzCaller          mbz.MusicBrainzCaller
	ArtistNames        []string
	Artist             string
	ArtistMbzIDs       []uuid.UUID
	ArtistMbidMappings []ArtistMbidMap
	TrackTitle         string
	RecordingMbzID     uuid.UUID
	Duration           int32 // in seconds
	ReleaseTitle       string
	ReleaseMbzID       uuid.UUID
	ReleaseGroupMbzID  uuid.UUID
	Time               time.Time

	UserID       int32
	Client       string
	IsNowPlaying bool

	// When true, checks for existing listens within +/- 60s window for the same track
	DeduplicateFuzzy bool

	// Optional: Direct URL to image to use if no other image is found
	ImageURL string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL