media

package
v0.9.18 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FilmStudio     studioKind = "film"
	Music          studioKind = "music"
	Game           studioKind = "game"
	TV             studioKind = "tv"
	Publishing     studioKind = "publishing"
	VisualArtOther studioKind = "visual_art_other"
	Unknown        studioKind = "unknown"
)

Variables

View Source
var BookKeys = []string{
	"media_id", "title", "authors",
	"genres", "edition", "languages",
}

Functions

func GetGenres

func GetGenres[G GenresOrGenreNames](
	ms *Storage,

	ctx context.Context,
	kind string,
	all bool,
	columns ...string,
) (G, error)

GetGenres returns all genres for specified media type. parameter all specifies whether to return all genres or only top-level ones. variadic argument columns specifies which columns to return. In HTTP layer, columns are specified either in the JSON request body (as an array of strings) The name column can also be accessed with `names_only` boolean query parameter. Fetching of all genres is specified by the `all` query parameter (which does not require a value).

Types

type ActorCast

type ActorCast struct {
	CastID   int64 `json:"castID" db:"cast_id,pk,unique"`
	PersonID int64 `json:"personID" db:"person_id,pk"`
}

type Album

type Album struct {
	MediaID      *uuid.UUID     `json:"media_id" db:"media_id,pk,unique"`
	Name         string         `json:"name" db:"name"`
	AlbumArtists []AlbumArtist  `json:"album_artists" db:"album_artists"`
	ImagePaths   pq.StringArray `json:"image_paths,omitempty"` // we make use of a junction table that utilizes the image IDs
	ReleaseDate  time.Time      `json:"release_date" db:"release_date"`
	Genres       []Genre        `json:"genres,omitempty" db:"genres"`
	//	Studio       Studio                       `json:"studio,omitempty" db:"studio"`
	Keywords []Keyword    `json:"keywords,omitempty" db:"keywords"`
	Duration sql.NullTime `json:"duration,omitempty" db:"duration"`
	Tracks   []Track      `json:"tracks,omitempty" db:"tracks"`
}

type AlbumArtist

type AlbumArtist struct {
	ID         uuid.UUID `json:"artist" db:"artist,pk,unique"`
	Name       string    `json:"name" db:"-"` // must perform a join operation to get the name
	ArtistType string    `json:"artist_type" db:"artist_type" validate:"required,oneof=individual group"`
}

junction table media.album_artists

type Book

type Book struct {
	MediaID         *uuid.UUID     `json:"media_id" db:"media_id,pk,unique"`
	Title           string         `json:"title" db:"title"`
	Authors         []Person       `json:"author" db:"author"`
	Publisher       Studio         `json:"publisher" db:"publisher"`
	PublicationDate sql.NullTime   `json:"publication_date" db:"publication_date"`
	Genres          []Genre        `json:"genres" db:"genres"`
	Keywords        pq.StringArray `json:"keywords,omitempty" db:"keywords,omitempty"`
	Languages       []string       `json:"languages" db:"languages"`
	Pages           int16          `json:"pages" db:"pages"`
	ISBN            sql.NullString `json:"isbn,omitempty" db:"isbn,unique,omitempty"`
	ASIN            sql.NullString `json:"asin,omitempty" db:"asin,unique,omitempty"`
	Cover           sql.NullString `json:"cover,omitempty" db:"cover,omitempty"`
	Summary         string         `json:"summary" db:"summary"`
}

type BookValues

type BookValues interface {
	[]string | string | int16 | time.Time | []Person
}

type Cast

type Cast struct {
	ID        int64    `json:"ID" db:"cast_id,pk,unique"`
	Actors    []Person `json:"actors" db:"actors"`
	Directors []Person `json:"directors" db:"directors"`
}

type Details

type Details struct {
	Kind string      `json:"kind" db:"kind"`
	Data interface{} `json:"details" db:"details"`
}

type DirectorCast

type DirectorCast struct {
	CastID   int64 `json:"castID" db:"cast_id,pk,unique"`
	PersonID int64 `json:"personID" db:"person_id,pk"`
}

type Episode

type Episode struct {
	MediaID   *uuid.UUID    `json:"media_id" db:"media_id,pk,unique"`
	ShowID    *uuid.UUID    `json:"show_id" db:"show_id,pk,unique"`
	SeasonID  *uuid.UUID    `json:"season_id" db:"season_id,pk,unique"`
	Number    uint16        `json:"number" db:"number,autoinc"`
	Title     string        `json:"title" db:"title"`
	Season    uint16        `json:"season" db:"season"`
	Episode   uint16        `json:"episode" db:"episode"`
	AirDate   time.Time     `json:"air_date" db:"air_date"`
	Duration  time.Duration `json:"duration" db:"duration"`
	Languages []string      `json:"languages" db:"languages"`
	Plot      string        `json:"plot" db:"plot"`
}

type Film

type Film struct {
	MediaID     *uuid.UUID     `json:"media_id" db:"media_id,pk,unique"`
	Title       string         `json:"title" db:"title"`
	Cast        Cast           `json:"cast"` // this data is stored in the people schema, so no db tag
	ReleaseDate sql.NullTime   `json:"release_date" db:"release_date"`
	Duration    sql.NullTime   `json:"duration" db:"duration"`
	Synopsis    sql.NullString `json:"synopsis" db:"synopsis"`
	// TODO: check if nullFloat64 is the right type for this
	Rating sql.NullFloat64 `json:"rating"` // stored in the reviews.rating table, can be queried with a join on media ID
}

nolint:musttag

func (*Film) GetPosterPath

func (f *Film) GetPosterPath(id uuid.UUID) string

type Genre

type Genre struct {
	ID          int64              `json:"id" db:"id,pk,autoinc"`
	Kinds       pq.StringArray     `json:"kind" db:"kind" enum:"music,film,tv,book,game" example:"music"`
	Name        string             `json:"name" db:"name" example:"Black Metal"`
	Description []GenreDescription `json:"description,omitempty" db:"-"`
	//	DescLong    string   `json:"desc_long" db:"desc_long"`
	Characteristics []string `json:"keywords" db:"-" example:"['dark', 'gloomy', 'atmospheric', 'raw', 'underproduced']"`
	ParentGenreID   *int64   `json:"parent_genre,omitempty" db:"parent,omitempty"`
	Children        []int64  `json:"children,omitempty" db:"children,omitempty"`
}

Genre does not have a UUID due to parent-child relationships

type GenreCharacteristics

type GenreCharacteristics struct {
	ID         int64          `json:"id" db:"id,pk,autoinc"`
	Name       string         `json:"name" db:"name"`
	Descripion sql.NullString `json:"description,omitempty" db:"description"`
}

type GenreDescription

type GenreDescription struct {
	GenreID     int64  `json:"genre_id" db:"genre_id" example:"2958"`
	Language    string `json:"language" db:"language" example:"en"`
	Description string `` /* 251-byte string literal not displayed */
}

type GenresOrGenreNames

type GenresOrGenreNames interface {
	[]Genre | []string
}

type Group

type Group struct {
	ID              uuid.UUID      `json:"id,omitempty" db:"id"`
	Locations       []places.Place `json:"locations,omitempty" db:"locations"`
	Name            string         `json:"name" db:"name"`
	Active          bool           `json:"active,omitempty" db:"active"`
	Formed          sql.NullTime   `json:"formed,omitempty" db:"formed"`
	Disbanded       sql.NullTime   `json:"disbanded,omitempty" db:"disbanded"`
	Website         sql.NullString `json:"website,omitempty" db:"website"`
	Photos          []string       `json:"photos,omitempty" db:"photos"`
	Works           []*uuid.UUID   `json:"works,omitempty" db:"works"`
	Members         []Person       `json:"members,omitempty" db:"members"`
	PrimaryGenre    Genre          `json:"primary_genre,omitempty" db:"primary_genre_id"`
	SecondaryGenres []Genre        `json:"genres,omitempty" db:"genres"`
	Kind            string         `json:"kind,omitempty" db:"kind"` // Orchestra, Choir, Ensemble, Collective, etc.
	Added           time.Time      `json:"added" db:"added"`
	Modified        sql.NullTime   `json:"modified,omitempty" db:"modified"`
	Wikipedia       sql.NullString `json:"wikipedia,omitempty" db:"wikipedia"`
	Bandcamp        sql.NullString `json:"bandcamp,omitempty" db:"bandcamp"`
	Soundcloud      sql.NullString `json:"soundcloud,omitempty" db:"soundcloud"`
	Bio             sql.NullString `json:"bio,omitempty" db:"bio"`
}

func (*Group) Validate

func (g *Group) Validate() error

type GroupedArtists

type GroupedArtists struct {
	Individual []Person `json:"individual,omitempty" db:"individual"`
	Group      []Group  `json:"group,omitempty" db:"group"`
}

type Keyword

type Keyword struct {
	ID         int32           `json:"id" db:"id,pk"`
	Keyword    string          `json:"keyword" db:"keyword"`
	TotalStars int32           `json:"stars" db:"total_stars"`
	VoteCount  int32           `json:"vote_count" db:"vote_count"`
	AvgScore   sql.NullFloat64 `json:"avg_score" db:"avg_score"`
}

type KeywordStorage

type KeywordStorage struct {
	// contains filtered or unexported fields
}

func NewKeywordStorage

func NewKeywordStorage(db *sqlx.DB, log *zerolog.Logger) *KeywordStorage

func (*KeywordStorage) AddKeyword

func (ks *KeywordStorage) AddKeyword(ctx context.Context, keyword string, mediaID uuid.UUID) (err error)

func (*KeywordStorage) CastVote

func (ks *KeywordStorage) CastVote(ctx context.Context, k Keyword) error

func (*KeywordStorage) GetAll

func (ks *KeywordStorage) GetAll(ctx context.Context) (keywords []Keyword, err error)

func (*KeywordStorage) GetKeyword

func (ks *KeywordStorage) GetKeyword(ctx context.Context, keyword string, mediaID uuid.UUID) (k Keyword, err error)

func (*KeywordStorage) GetKeywordByID

func (ks *KeywordStorage) GetKeywordByID(ctx context.Context, id int32) (k Keyword, err error)

func (*KeywordStorage) GetKeywords

func (ks *KeywordStorage) GetKeywords(ctx context.Context, mediaID uuid.UUID) (keywords []Keyword, err error)

func (*KeywordStorage) RemoveVote

func (ks *KeywordStorage) RemoveVote(ctx context.Context, k Keyword) error

type KeywordStorer

type KeywordStorer interface {
	CastVote(ctx context.Context, k Keyword) error
	RemoveVote(ctx context.Context, k Keyword) error
	AddKeyword(ctx context.Context, k Keyword) error
	GetKeyword(ctx context.Context, mediaID uuid.UUID) (Keyword, error)
	GetKeywords(ctx context.Context, mediaID uuid.UUID) ([]Keyword, error)
}

type Media

type Media struct {
	ID       uuid.UUID     `json:"id" db:"id,pk,unique"`
	Title    string        `json:"title" db:"title"`
	Kind     string        `json:"kind" db:"kind"`
	Created  time.Time     `json:"keywords,omitempty" db:"created"`
	Creator  sql.NullInt32 `json:"creator,omitempty" db:"creator"`
	Creators []Person      `json:"creators,omitempty"` // no db tag, we're using a junction table
	Added    time.Time     `json:"added,omitempty" db:"added"`
	Modified sql.NullTime  `json:"modified,omitempty" db:"modified"`
}

nolint:musttag // false positive, can only annotate fields, not types

type MediaObject

type MediaObject interface {
	Book | Album | Track | TVShow | Season | Episode
}

type PeopleStorage

type PeopleStorage struct {
	// contains filtered or unexported fields
}

func NewPeopleStorage

func NewPeopleStorage(newConn *pgxpool.Pool, dbConn *sqlx.DB, logger *zerolog.Logger) *PeopleStorage

func (*PeopleStorage) GetArtistsByName

func (p *PeopleStorage) GetArtistsByName(ctx context.Context, name string) (persons []Person, groups []Group, err error)

func (*PeopleStorage) GetGroup

func (p *PeopleStorage) GetGroup(ctx context.Context, id int32) (Group, error)

func (*PeopleStorage) GetGroupName

func (p *PeopleStorage) GetGroupName(ctx context.Context, id int32) (Group, error)

func (*PeopleStorage) GetID

func (p *PeopleStorage) GetID(ctx context.Context, name, kind string) (id int32, err error)

func (*PeopleStorage) GetPerson

func (p *PeopleStorage) GetPerson(ctx context.Context, id int64) (Person, error)

func (*PeopleStorage) GetPersonNames

func (p *PeopleStorage) GetPersonNames(ctx context.Context, id int32) (Person, error)

func (*PeopleStorage) GetStudio

func (p *PeopleStorage) GetStudio(ctx context.Context, id int32) (*Studio, error)

type Person

type Person struct {
	ID         uuid.UUID      `json:"id,omitempty" db:"id,pk,unique" swaggertype:"string" example:"12345678-90ab-cdef-9876-543210fedcba"`
	Name       string         `json:"name,omitempty" db:"-"` // helper field for complete name
	FirstName  string         `json:"first_name" db:"first_name" example:"Karol"`
	OtherNames pq.StringArray `json:"other_names,omitempty" db:"other_names" example:"['Jan Paweł II']"`
	LastName   string         `json:"last_name" db:"last_name" example:"Wojtyła"`
	NickNames  pq.StringArray `json:"nick_names,omitempty" db:"nick_names" example:"['pawlacz', 'jan pawulon']"`
	Roles      pq.StringArray `json:"roles,omitempty" db:"roles"`
	Works      []*uuid.UUID   `json:"works,omitempty" db:"works"`
	Birth      sql.NullTime   `json:"birth,omitempty" db:"birth"` // DOB can also be unknown
	Death      sql.NullTime   `json:"death,omitempty" db:"death" example:"2005-04-02T21:37:00Z"`
	Website    sql.NullString `json:"website,omitempty" db:"website" example:"https://www.vatican.va/content/john-paul-ii/en.html"`
	Bio        sql.NullString `json:"bio,omitempty" db:"bio" example:"wojtyła disco dance"`
	Photos     pq.StringArray `json:"photos,omitempty" db:"photos"`
	Hometown   places.Place   `json:"hometown,omitempty" db:"hometown"`
	Residence  places.Place   `json:"residence,omitempty" db:"residence"`
	Added      time.Time      `json:"added,omitempty" db:"added"`
	Modified   sql.NullTime   `json:"modified,omitempty" db:"modified"`
}

type Season

type Season struct {
	MediaID  *uuid.UUID `json:"media_id" db:"media_id,pk,unique"`
	ShowID   *uuid.UUID `json:"show_id" db:"show_id,pk,unique"`
	Number   uint8      `json:"number" db:"number"`
	Episodes []Episode  `json:"episodes" db:"episodes"`
}

type SimplifiedMedia

type SimplifiedMedia struct {
	Title       string `json:"title" db:"title"`
	Kind        string `json:"kind" db:"kind"`
	ImageSource string `json:"image_source" db:"source"`
}

used in search

type Storage

type Storage struct {
	Log *zerolog.Logger

	Ps *PeopleStorage
	// contains filtered or unexported fields
}

func NewStorage

func NewStorage(newDB *pgxpool.Pool, db *sqlx.DB, l *zerolog.Logger) *Storage

func (*Storage) Add

func (ms *Storage) Add(ctx context.Context, props *Media) (mediaID *uuid.UUID, err error)

Add is a generic method that adds an object to the media.media table. It needs to be run BEFORE the object is added to its respective table, since it needs the media ID to be generated first.

func (*Storage) AddBook

func (ms *Storage) AddBook(
	ctx context.Context,
	book *Book,
	publisher *Studio,
) error

func (*Storage) AddCast

func (ms *Storage) AddCast(ctx context.Context, mediaID uuid.UUID, actors, directors []Person) (castID int64, err error)

func (*Storage) AddCreators

func (ms *Storage) AddCreators(ctx context.Context, id uuid.UUID, creators []Person) error

func (*Storage) AddFilm

func (ms *Storage) AddFilm(ctx context.Context, film *Film) error

func (*Storage) Delete

func (ms *Storage) Delete(ctx context.Context, mediaID uuid.UUID) error

func (*Storage) Get

func (ms *Storage) Get(ctx context.Context, id uuid.UUID) (media Media, err error)

Get scans into a complete Media struct In most cases though, all we need is an intermediate, partial instance with the UUID and Kind fields to be passed to GetDetails

func (*Storage) GetAlbumTrackIDs

func (ms *Storage) GetAlbumTrackIDs(ctx context.Context, albumID uuid.UUID) ([]uuid.UUID, error)

func (*Storage) GetAlbumTracks

func (ms *Storage) GetAlbumTracks(ctx context.Context, albumID uuid.UUID) ([]Track, error)

GetAlbumTracks retrieves the full metadata of given album's tracks based on the album ID

func (*Storage) GetAll

func (ms *Storage) GetAll() ([]*interface{}, error)

func (*Storage) GetCast

func (ms *Storage) GetCast(ctx context.Context, mediaID uuid.UUID) (cast Cast, err error)

func (*Storage) GetDetails

func (ms *Storage) GetDetails(
	ctx context.Context,
	mediaKind string,
	id uuid.UUID,
) (interface{}, error)

func (*Storage) GetGenre

func (ms *Storage) GetGenre(ctx context.Context, kind, lang, name string) (genre *Genre, err error)

func (*Storage) GetImagePath

func (ms *Storage) GetImagePath(ctx context.Context, id uuid.UUID) (path string, err error)

func (*Storage) GetKind

func (ms *Storage) GetKind(ctx context.Context, id uuid.UUID) (string, error)

func (*Storage) GetRandom

func (ms *Storage) GetRandom(ctx context.Context, count int, blacklistKinds ...string) (
	mwks map[uuid.UUID]string, err error,
)

mwks - media IDs with their corresponding kind

func (*Storage) Update

func (ms *Storage) Update(ctx context.Context, key string, value interface{}, mediaID uuid.UUID) error

func (*Storage) UpdateFilm

func (ms *Storage) UpdateFilm(ctx context.Context, film *Film) error

type Storer

type Storer[T any] interface {
	Get(ctx context.Context, key string) (T, error)
	GetAll() ([]T, error)
	Add(ctx context.Context, db *sqlx.DB, props Media) (uuid.UUID, error)
	Update(ctx context.Context, key string, value T) error
	Delete(ctx context.Context, key string) error
}

type Studio

type Studio struct {
	ID      int32        `json:"id" db:"id,pk,serial,unique"`
	Name    string       `json:"name" db:"name"`
	Active  bool         `json:"active" db:"active"`
	City    *places.City `json:"city,omitempty" db:"city"`
	Artists []Person     `json:"artists,omitempty" db:"artists"`
	Works   Media        `json:"works,omitempty" db:"works"`
	Kinds   []studioKind `json:"kinds,omitempty" db:"kinds"`
}

type StudioKind

type StudioKind interface {
	// contains filtered or unexported methods
}

type TVShow

type TVShow struct {
	MediaID *uuid.UUID `json:"media_id" db:"media_id,pk,unique"`
	Title   string     `json:"title" db:"title"`
	Cast    Cast       `json:"cast" db:"cast"`
	Year    int        `json:"year" db:"year"`
	Active  bool       `json:"active" db:"active"`
	Seasons []Season   `json:"seasons" db:"seasons"`
	Studio  Studio     `json:"studio" db:"studio"`
}

type Track

type Track struct {
	MediaID *uuid.UUID `json:"media_id" db:"media_id,pk,unique"`
	Name    string     `json:"name" db:"name"`
	AlbumID *uuid.UUID `json:"album_id" db:"album"`
	//		Artists   mo.Either[[]Person, []Group] `json:"artists" db:"artists"`
	Duration time.Time `json:"duration" db:"duration"`
	Lyrics   string    `json:"lyrics,omitempty" db:"lyrics"`
	Number   int16     `json:"track_number" db:"track_number"`
}

Jump to

Keyboard shortcuts

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