move the id type into spec
This commit is contained in:
@@ -3,42 +3,41 @@ package spec
|
||||
import (
|
||||
"path"
|
||||
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/params"
|
||||
"go.senan.xyz/gonic/server/db"
|
||||
)
|
||||
|
||||
func NewAlbumByFolder(f *db.Album) *Album {
|
||||
a := &Album{
|
||||
Artist: f.Parent.RightPath,
|
||||
ID: params.IDAlbum(f.ID),
|
||||
ID: f.SID(),
|
||||
IsDir: true,
|
||||
ParentID: params.IDAlbum(f.ParentID),
|
||||
ParentID: f.ParentSID(),
|
||||
Title: f.RightPath,
|
||||
TrackCount: f.ChildCount,
|
||||
}
|
||||
if f.Cover != "" {
|
||||
a.CoverID = f.ID
|
||||
a.CoverID = f.SID()
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func NewTCAlbumByFolder(f *db.Album) *TrackChild {
|
||||
trCh := &TrackChild{
|
||||
ID: params.IDAlbum(f.ID),
|
||||
ID: f.SID(),
|
||||
IsDir: true,
|
||||
Title: f.RightPath,
|
||||
ParentID: params.IDAlbum(f.ParentID),
|
||||
ParentID: f.ParentSID(),
|
||||
CreatedAt: f.UpdatedAt,
|
||||
}
|
||||
if f.Cover != "" {
|
||||
trCh.CoverID = f.ID
|
||||
trCh.CoverID = f.SID()
|
||||
}
|
||||
return trCh
|
||||
}
|
||||
|
||||
func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
|
||||
trCh := &TrackChild{
|
||||
ID: params.IDTrack(t.ID),
|
||||
ID: t.SID(),
|
||||
ContentType: t.MIME(),
|
||||
Suffix: t.Ext(),
|
||||
Size: t.Size,
|
||||
@@ -51,7 +50,7 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
|
||||
parent.RightPath,
|
||||
t.Filename,
|
||||
),
|
||||
ParentID: params.IDAlbum(parent.ID),
|
||||
ParentID: parent.SID(),
|
||||
Duration: t.Length,
|
||||
Bitrate: t.Bitrate,
|
||||
IsDir: false,
|
||||
@@ -59,7 +58,7 @@ func NewTCTrackByFolder(t *db.Track, parent *db.Album) *TrackChild {
|
||||
CreatedAt: t.CreatedAt,
|
||||
}
|
||||
if parent.Cover != "" {
|
||||
trCh.CoverID = parent.ID
|
||||
trCh.CoverID = parent.SID()
|
||||
}
|
||||
if t.Album != nil {
|
||||
trCh.Album = t.Album.RightPath
|
||||
@@ -73,7 +72,7 @@ func NewArtistByFolder(f *db.Album) *Artist {
|
||||
// from an "album" where
|
||||
// maybe TODO: rename the Album model to Folder
|
||||
return &Artist{
|
||||
ID: params.IDAlbum(f.ID),
|
||||
ID: f.SID(),
|
||||
Name: f.RightPath,
|
||||
AlbumCount: f.ChildCount,
|
||||
}
|
||||
@@ -81,13 +80,13 @@ func NewArtistByFolder(f *db.Album) *Artist {
|
||||
|
||||
func NewDirectoryByFolder(f *db.Album, children []*TrackChild) *Directory {
|
||||
dir := &Directory{
|
||||
ID: f.ID,
|
||||
ID: f.SID(),
|
||||
Name: f.RightPath,
|
||||
Children: children,
|
||||
}
|
||||
// don't show the root dir as a parent
|
||||
if f.ParentID != 1 {
|
||||
dir.ParentID = f.ParentID
|
||||
dir.ParentID = f.ParentSID()
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
func NewAlbumByTags(a *db.Album, artist *db.Artist) *Album {
|
||||
ret := &Album{
|
||||
Created: a.ModifiedAt,
|
||||
ID: a.ID,
|
||||
ID: a.SID(),
|
||||
Name: a.TagTitle,
|
||||
Year: a.TagYear,
|
||||
TrackCount: a.ChildCount,
|
||||
@@ -18,21 +18,21 @@ func NewAlbumByTags(a *db.Album, artist *db.Artist) *Album {
|
||||
ret.Genre = a.TagGenre.Name
|
||||
}
|
||||
if a.Cover != "" {
|
||||
ret.CoverID = a.ID
|
||||
ret.CoverID = a.SID()
|
||||
}
|
||||
if artist != nil {
|
||||
ret.Artist = artist.Name
|
||||
ret.ArtistID = artist.ID
|
||||
ret.ArtistID = artist.SID()
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
|
||||
ret := &TrackChild{
|
||||
ID: t.ID,
|
||||
ID: t.SID(),
|
||||
ContentType: t.MIME(),
|
||||
Suffix: t.Ext(),
|
||||
ParentID: t.AlbumID,
|
||||
ParentID: t.AlbumSID(),
|
||||
CreatedAt: t.CreatedAt,
|
||||
Size: t.Size,
|
||||
Title: t.TagTitle,
|
||||
@@ -45,16 +45,16 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
|
||||
t.Filename,
|
||||
),
|
||||
Album: album.TagTitle,
|
||||
AlbumID: album.ID,
|
||||
AlbumID: album.SID(),
|
||||
Duration: t.Length,
|
||||
Bitrate: t.Bitrate,
|
||||
Type: "music",
|
||||
}
|
||||
if album.Cover != "" {
|
||||
ret.CoverID = album.ID
|
||||
ret.CoverID = album.SID()
|
||||
}
|
||||
if album.TagArtist != nil {
|
||||
ret.ArtistID = album.TagArtist.ID
|
||||
ret.ArtistID = album.TagArtist.SID()
|
||||
}
|
||||
// replace tags that we're present
|
||||
if ret.Title == "" {
|
||||
@@ -71,7 +71,7 @@ func NewTrackByTags(t *db.Track, album *db.Album) *TrackChild {
|
||||
|
||||
func NewArtistByTags(a *db.Artist) *Artist {
|
||||
return &Artist{
|
||||
ID: a.ID,
|
||||
ID: a.SID(),
|
||||
Name: a.Name,
|
||||
AlbumCount: a.AlbumCount,
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.senan.xyz/gonic/server/ctrlsubsonic/specid"
|
||||
"go.senan.xyz/gonic/version"
|
||||
)
|
||||
|
||||
@@ -90,15 +91,15 @@ type Albums struct {
|
||||
|
||||
type Album struct {
|
||||
// common
|
||||
ID string `xml:"id,attr,omitempty" json:"id"`
|
||||
CoverID int `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty,string"`
|
||||
ArtistID string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||
ID specid.ID `xml:"id,attr,omitempty" json:"id"`
|
||||
CoverID specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||
ArtistID specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||
// browsing by folder (eg. getAlbumList)
|
||||
Title string `xml:"title,attr" json:"title"`
|
||||
Album string `xml:"album,attr" json:"album"`
|
||||
ParentID string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
IsDir bool `xml:"isDir,attr,omitempty" json:"isDir,omitempty"`
|
||||
Title string `xml:"title,attr" json:"title"`
|
||||
Album string `xml:"album,attr" json:"album"`
|
||||
ParentID specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
IsDir bool `xml:"isDir,attr,omitempty" json:"isDir,omitempty"`
|
||||
// browsing by tags (eg. getAlbumList2)
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
TrackCount int `xml:"songCount,attr" json:"songCount"`
|
||||
@@ -119,19 +120,19 @@ type TracksByGenre struct {
|
||||
|
||||
type TrackChild struct {
|
||||
Album string `xml:"album,attr,omitempty" json:"album,omitempty"`
|
||||
AlbumID string `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
||||
AlbumID specid.ID `xml:"albumId,attr,omitempty" json:"albumId,omitempty"`
|
||||
Artist string `xml:"artist,attr,omitempty" json:"artist,omitempty"`
|
||||
ArtistID string `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||
ArtistID specid.ID `xml:"artistId,attr,omitempty" json:"artistId,omitempty"`
|
||||
Bitrate int `xml:"bitRate,attr,omitempty" json:"bitRate,omitempty"`
|
||||
ContentType string `xml:"contentType,attr,omitempty" json:"contentType,omitempty"`
|
||||
CoverID int `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty,string"`
|
||||
CoverID specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||
CreatedAt time.Time `xml:"created,attr,omitempty" json:"created,omitempty"`
|
||||
Duration int `xml:"duration,attr,omitempty" json:"duration,omitempty"`
|
||||
Genre string `xml:"genre,attr,omitempty" json:"genre,omitempty"`
|
||||
ID string `xml:"id,attr,omitempty" json:"id,omitempty"`
|
||||
ID specid.ID `xml:"id,attr,omitempty" json:"id,omitempty"`
|
||||
IsDir bool `xml:"isDir,attr" json:"isDir"`
|
||||
IsVideo bool `xml:"isVideo,attr" json:"isVideo"`
|
||||
ParentID string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
ParentID specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
Path string `xml:"path,attr,omitempty" json:"path,omitempty"`
|
||||
Size int `xml:"size,attr,omitempty" json:"size,omitempty"`
|
||||
Suffix string `xml:"suffix,attr,omitempty" json:"suffix,omitempty"`
|
||||
@@ -147,11 +148,11 @@ type Artists struct {
|
||||
}
|
||||
|
||||
type Artist struct {
|
||||
ID string `xml:"id,attr,omitempty" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
CoverID int `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty,string"`
|
||||
AlbumCount int `xml:"albumCount,attr" json:"albumCount"`
|
||||
Albums []*Album `xml:"album,omitempty" json:"album,omitempty"`
|
||||
ID specid.ID `xml:"id,attr,omitempty" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
CoverID specid.ID `xml:"coverArt,attr,omitempty" json:"coverArt,omitempty"`
|
||||
AlbumCount int `xml:"albumCount,attr" json:"albumCount"`
|
||||
Albums []*Album `xml:"album,omitempty" json:"album,omitempty"`
|
||||
}
|
||||
|
||||
type Indexes struct {
|
||||
@@ -166,8 +167,8 @@ type Index struct {
|
||||
}
|
||||
|
||||
type Directory struct {
|
||||
ID string `xml:"id,attr,omitempty" json:"id"`
|
||||
ParentID string `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
ID specid.ID `xml:"id,attr,omitempty" json:"id"`
|
||||
ParentID specid.ID `xml:"parent,attr,omitempty" json:"parent,omitempty"`
|
||||
Name string `xml:"name,attr,omitempty" json:"name"`
|
||||
Starred string `xml:"starred,attr,omitempty" json:"starred,omitempty"`
|
||||
Children []*TrackChild `xml:"child,omitempty" json:"child,omitempty"`
|
||||
@@ -178,7 +179,7 @@ type MusicFolders struct {
|
||||
}
|
||||
|
||||
type MusicFolder struct {
|
||||
ID string `xml:"id,attr,omitempty" json:"id,omitempty"`
|
||||
ID int `xml:"id,attr,omitempty" json:"id,omitempty"`
|
||||
Name string `xml:"name,attr,omitempty" json:"name,omitempty"`
|
||||
}
|
||||
|
||||
@@ -238,9 +239,9 @@ type Playlist struct {
|
||||
}
|
||||
|
||||
type SimilarArtist struct {
|
||||
ID string `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
ID specid.ID `xml:"id,attr" json:"id"`
|
||||
Name string `xml:"name,attr" json:"name"`
|
||||
AlbumCount int `xml:"albumCount,attr,omitempty" json:"albumCount,omitempty"`
|
||||
}
|
||||
|
||||
type ArtistInfo struct {
|
||||
|
||||
Reference in New Issue
Block a user