Files
music-agregator/internal/release/release.go
T

219 lines
3.7 KiB
Go

package release
import (
pb "homelab.lan/music-agregator/gen/music_agregator/indexer/v1"
)
type Type int
const (
TypeUnknown Type = iota
TypeAlbum
TypeEP
TypeSingle
TypeDiscography
TypeCollection
TypeCompilation
TypeSoundtrack
TypeLive
TypeBootleg
)
func (t Type) String() string {
switch t {
case TypeAlbum:
return "album"
case TypeEP:
return "ep"
case TypeSingle:
return "single"
case TypeDiscography:
return "discography"
case TypeCollection:
return "collection"
case TypeCompilation:
return "compilation"
case TypeSoundtrack:
return "soundtrack"
case TypeLive:
return "live"
case TypeBootleg:
return "bootleg"
default:
return "unknown"
}
}
func (t Type) Priority() int {
switch t {
case TypeAlbum, TypeEP, TypeSingle:
return 1
case TypeLive:
return 2
case TypeSoundtrack:
return 3
case TypeCollection:
return 4
case TypeDiscography:
return 5
case TypeCompilation:
return 6
case TypeBootleg:
return 7
default:
return 99
}
}
type AudioFormat int
const (
FormatUnknown AudioFormat = iota
FormatFLAC
FormatMP3
FormatAAC
FormatAPE
FormatWavPack
FormatALAC
FormatOGG
FormatWAV
)
func (f AudioFormat) String() string {
switch f {
case FormatFLAC:
return "FLAC"
case FormatMP3:
return "MP3"
case FormatAAC:
return "AAC"
case FormatAPE:
return "APE"
case FormatWavPack:
return "WavPack"
case FormatALAC:
return "ALAC"
case FormatOGG:
return "OGG"
case FormatWAV:
return "WAV"
default:
return "unknown"
}
}
func (f AudioFormat) IsLossless() bool {
switch f {
case FormatFLAC, FormatAPE, FormatWavPack, FormatALAC, FormatWAV:
return true
default:
return false
}
}
type Source int
const (
SourceUnknown Source = iota
SourceCD
SourceWEB
SourceVinyl
SourceCassette
SourceDVD
SourceBluRay
)
func (s Source) String() string {
switch s {
case SourceCD:
return "CD"
case SourceWEB:
return "WEB"
case SourceVinyl:
return "Vinyl"
case SourceCassette:
return "Cassette"
case SourceDVD:
return "DVD"
case SourceBluRay:
return "BluRay"
default:
return "unknown"
}
}
type Release struct {
RawTitle string
Artist string
Album string
Year int
YearEnd int
Type Type
Genres []string
Format AudioFormat
Source Source
Bitrate string
BitDepth int
SampleRate int
RipType string
ReleaseCount int
Tags []string
Label string
CatalogNum string
InfoHash string
TrackCount int
TrackNames []string
AudioFileCount int
TotalAudioSize int64
HasCoverArt bool
HasCueSheet bool
HasRipLog bool
ParsedSuccessfully bool
ParseErrors []string
}
func (r *Release) IsDiscography() bool {
return r.Type == TypeDiscography || r.Type == TypeCollection
}
func (r *Release) IsSingleRelease() bool {
return r.Type == TypeAlbum || r.Type == TypeEP || r.Type == TypeSingle
}
func (r *Release) HasYearRange() bool {
return r.YearEnd > 0 && r.YearEnd != r.Year
}
func (r *Release) ToProto() *pb.Release {
if r == nil {
return nil
}
return &pb.Release{
RawTitle: r.RawTitle,
Artist: r.Artist,
Album: r.Album,
Year: int32(r.Year),
YearEnd: int32(r.YearEnd),
Type: r.Type.String(),
Genres: r.Genres,
Format: r.Format.String(),
Source: r.Source.String(),
Bitrate: r.Bitrate,
BitDepth: int32(r.BitDepth),
SampleRate: int32(r.SampleRate),
RipType: r.RipType,
ReleaseCount: int32(r.ReleaseCount),
Tags: r.Tags,
Label: r.Label,
CatalogNum: r.CatalogNum,
ParsedSuccessfully: r.ParsedSuccessfully,
ParseErrors: r.ParseErrors,
}
}