Add common go types

This commit is contained in:
Olli 2026-02-26 10:38:28 +01:00
commit af4fc2fb64
4 changed files with 414 additions and 0 deletions

122
internal/common/song.go Normal file
View file

@ -0,0 +1,122 @@
package common
import (
"slices"
"time"
)
type Song struct {
artists []string
title string
file string
albumartists []string
track string
length uint64
date string
lastModified time.Time
}
func NewSong(artist string, title string, file string) *Song {
song := Song{
artists: []string{artist},
title: title,
file: file,
}
return &song
}
func (s *Song) AddArtist(artist string) {
s.artists = append(s.artists, artist)
}
func (s *Song) AddAlbumartist(artist string) {
s.albumartists = append(s.albumartists, artist)
}
func (s *Song) SongArtists() []string {
if len(s.albumartists) > 0 {
songArtists := []string{}
for _, artist := range s.artists {
if !slices.Contains(s.albumartists, artist) {
songArtists = append(songArtists, artist)
}
}
return songArtists
}
return []string{}
}
func (s *Song) AlbumArtists() []string {
if len(s.albumartists) > 0 {
return s.albumartists
}
return s.artists
}
func (s *Song) Title() string {
return s.title
}
func (s *Song) File() string {
return s.file
}
func (s *Song) SetTrack(track string) {
s.track = track
}
func (s *Song) Track() string {
return s.track
}
func (s *Song) SetLength(length uint64) {
s.length = length
}
func (s *Song) Length() uint64 {
return s.length
}
func (s *Song) SetDate(date string) {
s.date = date
}
func (s *Song) Date() string {
return s.date
}
func (s *Song) SetLastModified(lastModified time.Time) {
s.lastModified = lastModified
}
func (s *Song) LastModified() time.Time {
return s.lastModified
}
type PlaylistSong struct {
*Song
id string
pos uint64
}
func NewPlaylistSong(song *Song, id string, pos uint64) *PlaylistSong {
playlistSong := &PlaylistSong{
Song: song,
id: id,
pos: pos,
}
return playlistSong
}
func (t *PlaylistSong) ID() string {
return t.id
}
func (t *PlaylistSong) Pos() uint64 {
return t.pos
}