construct subsonic models elsewhere
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||
// we are browsing by folder, but the subsonic docs show sub <artist> elements
|
||||
// for this, so we're going to return root directories as "artists"
|
||||
var folders []*model.Folder
|
||||
var folders []model.Folder
|
||||
c.DB.Where("parent_id = ?", 1).Find(&folders)
|
||||
var indexMap = make(map[rune]*subsonic.Index)
|
||||
var indexes []*subsonic.Index
|
||||
@@ -28,10 +28,8 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) {
|
||||
indexMap[i] = index
|
||||
indexes = append(indexes, index)
|
||||
}
|
||||
index.Artists = append(index.Artists, &subsonic.Artist{
|
||||
ID: folder.ID,
|
||||
Name: folder.Name,
|
||||
})
|
||||
index.Artists = append(index.Artists,
|
||||
makeArtistFromFolder(&folder))
|
||||
}
|
||||
sub := subsonic.NewResponse()
|
||||
sub.Indexes = &subsonic.Indexes{
|
||||
@@ -48,61 +46,42 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
childrenObj := []*subsonic.Child{}
|
||||
var cFolder model.Folder
|
||||
c.DB.First(&cFolder, id)
|
||||
var folder model.Folder
|
||||
c.DB.First(&folder, id)
|
||||
//
|
||||
// start looking for child folders in the current dir
|
||||
var folders []*model.Folder
|
||||
// start looking for child childFolders in the current dir
|
||||
var childFolders []model.Folder
|
||||
c.DB.
|
||||
Where("parent_id = ?", id).
|
||||
Find(&folders)
|
||||
for _, folder := range folders {
|
||||
childrenObj = append(childrenObj, &subsonic.Child{
|
||||
Parent: cFolder.ID,
|
||||
ID: folder.ID,
|
||||
Title: folder.Name,
|
||||
IsDir: true,
|
||||
CoverID: folder.CoverID,
|
||||
})
|
||||
Find(&childFolders)
|
||||
for _, c := range childFolders {
|
||||
childrenObj = append(childrenObj,
|
||||
makeChildFromFolder(&c, &folder))
|
||||
}
|
||||
//
|
||||
// start looking for child tracks in the current dir
|
||||
var tracks []*model.Track
|
||||
// start looking for child childTracks in the current dir
|
||||
var childTracks []model.Track
|
||||
c.DB.
|
||||
Where("folder_id = ?", id).
|
||||
Preload("Album").
|
||||
Order("title").
|
||||
Find(&tracks)
|
||||
for _, track := range tracks {
|
||||
Find(&childTracks)
|
||||
for _, c := range childTracks {
|
||||
if getStrParam(r, "c") == "Jamstash" {
|
||||
// jamstash thinks it can't play flacs
|
||||
track.ContentType = "audio/mpeg"
|
||||
track.Suffix = "mp3"
|
||||
c.ContentType = "audio/mpeg"
|
||||
c.Suffix = "mp3"
|
||||
}
|
||||
childrenObj = append(childrenObj, &subsonic.Child{
|
||||
ID: track.ID,
|
||||
Album: track.Album.Title,
|
||||
Artist: track.Artist,
|
||||
ContentType: track.ContentType,
|
||||
CoverID: cFolder.CoverID,
|
||||
Duration: 0,
|
||||
IsDir: false,
|
||||
Parent: cFolder.ID,
|
||||
Path: track.Path,
|
||||
Size: track.Size,
|
||||
Suffix: track.Suffix,
|
||||
Title: track.Title,
|
||||
Track: track.TrackNumber,
|
||||
Type: "music",
|
||||
})
|
||||
childrenObj = append(childrenObj,
|
||||
makeChildFromTrack(&c, &folder))
|
||||
}
|
||||
//
|
||||
// respond section
|
||||
sub := subsonic.NewResponse()
|
||||
sub.Directory = &subsonic.Directory{
|
||||
ID: cFolder.ID,
|
||||
Parent: cFolder.ParentID,
|
||||
Name: cFolder.Name,
|
||||
ID: folder.ID,
|
||||
Parent: folder.ParentID,
|
||||
Name: folder.Name,
|
||||
Children: childrenObj,
|
||||
}
|
||||
respond(w, r, sub)
|
||||
@@ -152,28 +131,18 @@ func (c *Controller) GetAlbumList(w http.ResponseWriter, r *http.Request) {
|
||||
))
|
||||
return
|
||||
}
|
||||
var folders []*model.Folder
|
||||
var folders []model.Folder
|
||||
q.
|
||||
Where("folders.has_tracks = 1").
|
||||
Offset(getIntParamOr(r, "offset", 0)).
|
||||
Limit(getIntParamOr(r, "size", 10)).
|
||||
Preload("Parent").
|
||||
Find(&folders)
|
||||
listObj := []*subsonic.Album{}
|
||||
for _, folder := range folders {
|
||||
listObj = append(listObj, &subsonic.Album{
|
||||
ID: folder.ID,
|
||||
Title: folder.Name,
|
||||
Album: folder.Name,
|
||||
CoverID: folder.CoverID,
|
||||
ParentID: folder.ParentID,
|
||||
IsDir: true,
|
||||
Artist: folder.Parent.Name,
|
||||
})
|
||||
}
|
||||
sub := subsonic.NewResponse()
|
||||
sub.Albums = &subsonic.Albums{
|
||||
List: listObj,
|
||||
sub.Albums = &subsonic.Albums{}
|
||||
for _, folder := range folders {
|
||||
sub.Albums.List = append(sub.Albums.List,
|
||||
makeAlbumFromFolder(&folder))
|
||||
}
|
||||
respond(w, r, sub)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user