Rendering out leaf nodes for tracks

This commit is contained in:
Rob Emery 2025-01-18 17:44:57 +00:00
parent bd7df889bb
commit cdb40ecd3e

View File

@ -119,7 +119,10 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
albumResponse, _ := cds.ds.Album(cds.ctx).Get(album) albumResponse, _ := cds.ds.Album(cds.ctx).Get(album)
log.Debug(fmt.Sprintf("Album Returned: %+v for %s", albumResponse, album)) log.Debug(fmt.Sprintf("Album Returned: %+v for %s", albumResponse, album))
basePath := path.Join("/Music/Artists", matchResults["Artist"], matchResults["ArtistAlbum"]) basePath := path.Join("/Music/Artists", matchResults["Artist"], matchResults["ArtistAlbum"])
return cds.doAlbum(albumResponse, basePath, ret, host)
tracks, _ := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"album_id": albumResponse.ID}})
return cds.doMediaFiles(tracks, basePath, ret, host)
} else if matchResults["Artist"] != "" { } else if matchResults["Artist"] != "" {
log.Debug(fmt.Sprintf("Artist Get an Artist: %s", matchResults["Artist"])) log.Debug(fmt.Sprintf("Artist Get an Artist: %s", matchResults["Artist"]))
@ -152,9 +155,10 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
//TODO //TODO
} else if matchResults["AlbumTitle"] != "" { } else if matchResults["AlbumTitle"] != "" {
log.Debug("AlbumTitle MATCH") log.Debug("AlbumTitle MATCH")
x, _ := cds.ds.Album(cds.ctx).Get(matchResults["AlbumTitle"]) albumResponse, _ := cds.ds.Album(cds.ctx).Get(matchResults["AlbumTitle"])
basePath := "/Music/Albums" basePath := path.Join("/Music/Albums", matchResults["AlbumTitle"])
return cds.doAlbum(x, basePath, ret, host) tracks, _ := cds.ds.MediaFile(cds.ctx).GetAll(model.QueryOptions{Filters: squirrel.Eq{"album_id": albumResponse.ID}})
return cds.doMediaFiles(tracks, basePath, ret, host)
} else { } else {
log.Debug("albumRegex else MATCH") log.Debug("albumRegex else MATCH")
indexes, err := cds.ds.Album(cds.ctx).GetAllWithoutGenres() indexes, err := cds.ds.Album(cds.ctx).GetAllWithoutGenres()
@ -201,7 +205,7 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
} }
} else if matchResults, err := recentRegex.Groups(o.Path); err == nil { } else if matchResults, err := recentRegex.Groups(o.Path); err == nil {
log.Debug("recent MATCH") log.Debug("recent MATCH")
fmt.Printf("%+v",matchResults) fmt.Printf("%+v", matchResults)
} else if matchResults, err := playlistRegex.Groups(o.Path); err == nil { } else if matchResults, err := playlistRegex.Groups(o.Path); err == nil {
log.Debug("Playlist MATCH") log.Debug("Playlist MATCH")
if _, exists := matchResults["PlaylistTrack"]; exists { if _, exists := matchResults["PlaylistTrack"]; exists {
@ -209,7 +213,7 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
} else if playlist, exists := matchResults["Playlist"]; exists { } else if playlist, exists := matchResults["Playlist"]; exists {
log.Debug("Playlist only MATCH") log.Debug("Playlist only MATCH")
x, xerr := cds.ds.Playlist(cds.ctx).Get(playlist) x, xerr := cds.ds.Playlist(cds.ctx).Get(playlist)
log.Debug(fmt.Sprintf("Playlist: %+v", x), xerr) log.Debug(fmt.Sprintf("Playlist: %+v", x), xerr)
} else { } else {
log.Debug("Playlist else MATCH") log.Debug("Playlist else MATCH")
indexes, err := cds.ds.Playlist(cds.ctx).GetAll() indexes, err := cds.ds.Playlist(cds.ctx).GetAll()
@ -227,27 +231,40 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
return ret, nil return ret, nil
} }
} }
/* /*
deluan deluan
Today at 18:30 Today at 18:30
ds.Album(ctx).GetAll(FIlter: Eq{"albumArtistId": artistID}) ds.Album(ctx).GetAll(FIlter: Eq{"albumArtistId": artistID})
Or something like that 😛 Or something like that 😛
Mintsoft Mintsoft
Today at 18:30 Today at 18:30
For other examples, how do I know what the right magic string for "albumArtistId" is? For other examples, how do I know what the right magic string for "albumArtistId" is?
kgarner7 kgarner7
Today at 18:31 Today at 18:31
album_artist_id album_artist_id
Look at the model structs names Look at the model structs names
deluan deluan
Today at 18:31 Today at 18:31
This is a limitation of Squirrel. It is string based. YOu have to use the name of the columns in the DB This is a limitation of Squirrel. It is string based. YOu have to use the name of the columns in the DB
*/ */
return return
}
func (cds *contentDirectoryService) doMediaFiles(tracks model.MediaFiles, basePath string, ret []interface{}, host string) ([]interface{}, error) {
//TODO flesh object out with actually useful metadata about the track
for _, track := range tracks {
child := object{
Path: path.Join(basePath, track.Title),
Id: path.Join(basePath, track.ID),
}
ret = append(ret, cds.cdsObjectToUpnpavObject(child, false, host))
}
return ret, nil
} }
func (cds *contentDirectoryService) doAlbum(album *model.Album, basepath string, ret []interface{}, host string) ([]interface{}, error) { func (cds *contentDirectoryService) doAlbum(album *model.Album, basepath string, ret []interface{}, host string) ([]interface{}, error) {
@ -257,9 +274,9 @@ func (cds *contentDirectoryService) doAlbum(album *model.Album, basepath string,
func (cds *contentDirectoryService) doAlbums(albums model.Albums, basepath string, ret []interface{}, host string) ([]interface{}, error) { func (cds *contentDirectoryService) doAlbums(albums model.Albums, basepath string, ret []interface{}, host string) ([]interface{}, error) {
for _, album := range albums { for _, album := range albums {
child := object { child := object{
Path: path.Join(basepath, album.Name), Path: path.Join(basepath, album.Name),
Id: path.Join(basepath, album.ID), Id: path.Join(basepath, album.ID),
} }
ret = append(ret, cds.cdsObjectToUpnpavObject(child, true, host)) ret = append(ret, cds.cdsObjectToUpnpavObject(child, true, host))
} }