diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..1dcfc2b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,32 @@ +linters: + enable-all: true + disable: + - gochecknoglobals + - gochecknoinits + +issues: + exclude-rules: + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + - text: "weak cryptographic primitive" + linters: + - gosec + - path: model/model.go + linters: + - lll + - path: server/handler/ + source: "next http.HandlerFunc" + linters: + - interfacer + - path: server/handler/ + source: "session.Save" + linters: + - errcheck + - path: server/handler/ + source: "w.Write" + linters: + - errcheck diff --git a/cmd/scanner/main.go b/cmd/scanner/main.go index cfa0b65..54e5619 100644 --- a/cmd/scanner/main.go +++ b/cmd/scanner/main.go @@ -14,7 +14,6 @@ import ( const ( programName = "gonic" - programVar = "GONIC" ) func main() { diff --git a/cmd/server/main.go b/cmd/server/main.go index ce85ee4..5da9a3a 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -52,6 +52,8 @@ func main() { *musicPath, *listenAddr, ) + s.SetupAdmin() + s.SetupSubsonic() log.Printf("starting server at %s", *listenAddr) if err := s.ListenAndServe(); err != nil { log.Fatalf("error starting server: %v\n", err) diff --git a/gen_handler_tests b/gen_handler_tests new file mode 100755 index 0000000..f965dfd --- /dev/null +++ b/gen_handler_tests @@ -0,0 +1,29 @@ +#!/bin/sh + +# by folder +curl "http://localhost:6969/rest/getAlbumList.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=alphabeticalByArtist" | jq > server/handler/test_data/test_get_album_list_alpha_artist +curl "http://localhost:6969/rest/getAlbumList.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=alphabeticalByName" | jq > server/handler/test_data/test_get_album_list_alpha_name +curl "http://localhost:6969/rest/getAlbumList.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=alphabeticalByName" | jq > server/handler/test_data/test_get_album_list_two_alpha_name +curl "http://localhost:6969/rest/getAlbumList.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=newest" | jq > server/handler/test_data/test_get_album_list_newest +curl "http://localhost:6969/rest/getAlbumList.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=random" | jq > server/handler/test_data/test_get_album_list_random +curl "http://localhost:6969/rest/search2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&query=13" | jq > server/handler/test_data/test_search_two_q_13 +curl "http://localhost:6969/rest/search2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&query=ani" | jq > server/handler/test_data/test_search_two_q_ani +curl "http://localhost:6969/rest/search2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&query=cert" | jq > server/handler/test_data/test_search_two_q_cert +curl 'http://localhost:6969/rest/getIndexes.view?c=Jamstash&p=admin&u=admin&v=1.9.0&f=json' | jq > server/handler/test_data/test_get_indexes_no_args +curl 'http://localhost:6969/rest/getMusicDirectory.view?c=Jamsstash&id=2&p=admin&u=admin&v=1.9.0&f=json' | jq > server/handler/test_data/test_get_music_directory_without_tracks +curl 'http://localhost:6969/rest/getMusicDirectory.view?c=Jamsstash&id=3&p=admin&u=admin&v=1.9.0&f=json' | jq > server/handler/test_data/test_get_music_directory_with_tracks + +# by tags +curl "http://localhost:6969/rest/getAlbum.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&id=2" | jq > server/handler/test_data/test_get_album_without_cover +curl "http://localhost:6969/rest/getAlbum.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&id=3" | jq > server/handler/test_data/test_get_album_with_cover +curl "http://localhost:6969/rest/getAlbumList2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=alphabeticalByArtist" | jq > server/handler/test_data/test_get_album_list_two_alpha_artist +curl "http://localhost:6969/rest/getAlbumList2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=alphabeticalByName" | jq > server/handler/test_data/test_get_album_list_two_alpha_name +curl "http://localhost:6969/rest/getAlbumList2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=newest" | jq > server/handler/test_data/test_get_album_list_two_newest +curl "http://localhost:6969/rest/getAlbumList2.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&type=random" | jq > server/handler/test_data/test_get_album_list_two_random +curl "http://localhost:6969/rest/getArtist.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&id=1" | jq > server/handler/test_data/test_get_artist_id_one +curl "http://localhost:6969/rest/getArtist.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&id=2" | jq > server/handler/test_data/test_get_artist_id_two +curl "http://localhost:6969/rest/getArtist.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&id=3" | jq > server/handler/test_data/test_get_artist_id_three +curl "http://localhost:6969/rest/getArtists.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0" | jq > server/handler/test_data/test_get_artists_no_args +curl "http://localhost:6969/rest/search3.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&query=13" | jq > server/handler/test_data/test_search_three_q_13 +curl "http://localhost:6969/rest/search3.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&query=ani" | jq > server/handler/test_data/test_search_three_q_ani +curl "http://localhost:6969/rest/search3.view?c=Jamstash&f=json&p=admin&u=admin&v=1.9.0&query=cert" | jq > server/handler/test_data/test_search_three_q_cert diff --git a/mime/mime.go b/mime/mime.go new file mode 100644 index 0000000..bad4d30 --- /dev/null +++ b/mime/mime.go @@ -0,0 +1,9 @@ +package mime + +var Types = map[string]string{ + "mp3": "audio/mpeg", + "flac": "audio/x-flac", + "aac": "audio/x-aac", + "m4a": "audio/m4a", + "ogg": "audio/ogg", +} diff --git a/model/model.go b/model/model.go index 954d57c..c8a3215 100644 --- a/model/model.go +++ b/model/model.go @@ -1,31 +1,26 @@ package model import ( + "path" "time" -) -// q: what in tarnation are the `IsNew`s for? -// a: it's a bit of a hack - but we set a models IsNew to true if -// we just filled it in for the first time, so when it comes -// time to insert them (post children callback) we can check for -// that bool being true - since it won't be true if it was already -// in the db + "github.com/sentriz/gonic/mime" +) type Artist struct { IDBase - Name string `gorm:"not null; unique_index"` - Folders []Folder + Name string `gorm:"not null; unique_index"` + Albums []Album `gorm:"foreignkey:TagArtistID"` } type Track struct { IDBase CrudBase - Folder Folder - FolderID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"` + Album Album + AlbumID int `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"` Filename string `gorm:"not null; unique_index:idx_folder_filename" sql:"default: null"` Artist Artist ArtistID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"` - ContentType string `gorm:"not null" sql:"default: null"` Duration int `gorm:"not null" sql:"default: null"` Size int `gorm:"not null" sql:"default: null"` Bitrate int `gorm:"not null" sql:"default: null"` @@ -38,6 +33,19 @@ type Track struct { TagYear int `sql:"default: null"` } +func (t *Track) Ext() string { + longExt := path.Ext(t.Filename) + if len(longExt) < 1 { + return "" + } + return longExt[1:] +} + +func (t *Track) MIME() string { + ext := t.Ext() + return mime.Types[ext] +} + type User struct { IDBase CrudBase @@ -55,25 +63,26 @@ type Setting struct { type Play struct { IDBase - User User - UserID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"` - Folder Folder - FolderID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"` - Time time.Time `sql:"default: null"` - Count int + User User + UserID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES users(id) ON DELETE CASCADE"` + Album Album + AlbumID int `gorm:"not null; index" sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"` + Time time.Time `sql:"default: null"` + Count int } -type Folder struct { +type Album struct { IDBase CrudBase - Path string `gorm:"not null; unique_index" sql:"default: null"` - Parent *Folder - ParentID int `sql:"default: null; type:int REFERENCES folders(id) ON DELETE CASCADE"` - AlbumArtist Artist - AlbumArtistID int `gorm:"index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"` - AlbumTitle string `gorm:"index" sql:"default: null"` - AlbumYear int `sql:"default: null"` - Cover string `sql:"default: null"` - Tracks []Track - IsNew bool `gorm:"-"` + LeftPath string `gorm:"unique_index:idx_left_path_right_path"` + RightPath string `gorm:"not null; unique_index:idx_left_path_right_path" sql:"default: null"` + Parent *Album + ParentID int `sql:"default: null; type:int REFERENCES albums(id) ON DELETE CASCADE"` + Cover string `sql:"default: null"` + TagArtist Artist + TagArtistID int `gorm:"index" sql:"default: null; type:int REFERENCES artists(id) ON DELETE CASCADE"` + TagTitle string `gorm:"index" sql:"default: null"` + TagYear int `sql:"default: null"` + Tracks []Track + IsNew bool `gorm:"-"` } diff --git a/scanner/scanner.go b/scanner/scanner.go index b817803..f8642fa 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -33,7 +33,7 @@ func New(db *gorm.DB, musicPath string) *Scanner { } } -func (s *Scanner) curFolder() *model.Folder { +func (s *Scanner) curFolder() *model.Album { return s.curFolders.Peek() } @@ -45,6 +45,26 @@ func (s *Scanner) curFolderID() int { return peek.ID } +func (s *Scanner) MigrateDB() error { + defer logElapsed(time.Now(), "migrating database") + s.tx = s.db.Begin() + defer s.tx.Commit() + s.tx.AutoMigrate( + model.Artist{}, + model.Track{}, + model.User{}, + model.Setting{}, + model.Play{}, + model.Album{}, + ) + s.tx.FirstOrCreate(&model.User{}, model.User{ + Name: "admin", + Password: "admin", + IsAdmin: true, + }) + return nil +} + func (s *Scanner) Start() error { if atomic.LoadInt32(&IsScanning) == 1 { return errors.New("already scanning") @@ -82,38 +102,22 @@ func (s *Scanner) startScan() error { func (s *Scanner) startClean() error { defer logElapsed(time.Now(), "cleaning database") - var tracks []model.Track - s.tx. + var tracks []*model.Track + err := s.tx. Select("id"). - Find(&tracks) + Find(&tracks). + Error + if err != nil { + return errors.Wrap(err, "scanning tracks") + } var deleted int for _, track := range tracks { _, ok := s.seenTracks[track.ID] if !ok { - s.tx.Delete(&track) + s.tx.Delete(track) deleted++ } } log.Printf("removed %d tracks\n", deleted) return nil } - -func (s *Scanner) MigrateDB() error { - defer logElapsed(time.Now(), "migrating database") - s.tx = s.db.Begin() - defer s.tx.Commit() - s.tx.AutoMigrate( - model.Artist{}, - model.Track{}, - model.User{}, - model.Setting{}, - model.Play{}, - model.Folder{}, - ) - s.tx.FirstOrCreate(&model.User{}, model.User{ - Name: "admin", - Password: "admin", - IsAdmin: true, - }) - return nil -} diff --git a/scanner/folder_stack.go b/scanner/stack.go similarity index 68% rename from scanner/folder_stack.go rename to scanner/stack.go index ca9381b..f567ae9 100644 --- a/scanner/folder_stack.go +++ b/scanner/stack.go @@ -7,13 +7,13 @@ import ( "github.com/sentriz/gonic/model" ) -type folderStack []*model.Folder +type folderStack []*model.Album -func (s *folderStack) Push(v *model.Folder) { +func (s *folderStack) Push(v *model.Album) { *s = append(*s, v) } -func (s *folderStack) Pop() *model.Folder { +func (s *folderStack) Pop() *model.Album { l := len(*s) if l == 0 { return nil @@ -23,7 +23,7 @@ func (s *folderStack) Pop() *model.Folder { return r } -func (s *folderStack) Peek() *model.Folder { +func (s *folderStack) Peek() *model.Album { l := len(*s) if l == 0 { return nil @@ -34,7 +34,7 @@ func (s *folderStack) Peek() *model.Folder { func (s *folderStack) String() string { paths := make([]string, len(*s)) for i, folder := range *s { - paths[i] = folder.Path + paths[i] = folder.LeftPath } return fmt.Sprintf("[%s]", strings.Join(paths, " ")) } diff --git a/scanner/utilities.go b/scanner/utilities.go index 70f88a2..ed2fdd0 100644 --- a/scanner/utilities.go +++ b/scanner/utilities.go @@ -7,27 +7,19 @@ import ( "github.com/pkg/errors" ) -var mimeTypes = map[string]string{ - "mp3": "audio/mpeg", - "flac": "audio/x-flac", - "aac": "audio/x-aac", - "m4a": "audio/m4a", - "ogg": "audio/ogg", -} - var coverFilenames = map[string]struct{}{ - "cover.png": struct{}{}, - "cover.jpg": struct{}{}, - "cover.jpeg": struct{}{}, - "folder.png": struct{}{}, - "folder.jpg": struct{}{}, - "folder.jpeg": struct{}{}, - "album.png": struct{}{}, - "album.jpg": struct{}{}, - "album.jpeg": struct{}{}, - "front.png": struct{}{}, - "front.jpg": struct{}{}, - "front.jpeg": struct{}{}, + "cover.png": {}, + "cover.jpg": {}, + "cover.jpeg": {}, + "folder.png": {}, + "folder.jpg": {}, + "folder.jpeg": {}, + "album.png": {}, + "album.jpg": {}, + "album.jpeg": {}, + "front.png": {}, + "front.jpg": {}, + "front.jpeg": {}, } func readTags(path string) (tag.Metadata, error) { diff --git a/scanner/walk.go b/scanner/walk.go index 8543401..2deccdb 100644 --- a/scanner/walk.go +++ b/scanner/walk.go @@ -10,20 +10,16 @@ import ( "github.com/karrick/godirwalk" "github.com/pkg/errors" + "github.com/sentriz/gonic/mime" "github.com/sentriz/gonic/model" ) type item struct { - // - // common - fullPath string - relPath string - filename string - stat os.FileInfo - // - // track only - ext string - mime string + fullPath string + relPath string + directory string + filename string + stat os.FileInfo } func (s *Scanner) callbackItem(fullPath string, info *godirwalk.Dirent) error { @@ -35,12 +31,13 @@ func (s *Scanner) callbackItem(fullPath string, info *godirwalk.Dirent) error { if err != nil { return errors.Wrap(err, "getting relative path") } - _, filename := path.Split(relPath) + directory, filename := path.Split(relPath) it := &item{ - fullPath: fullPath, - relPath: relPath, - filename: filename, - stat: stat, + fullPath: fullPath, + relPath: relPath, + directory: directory, + filename: filename, + stat: stat, } if info.IsDir() { return s.handleFolder(it) @@ -50,9 +47,7 @@ func (s *Scanner) callbackItem(fullPath string, info *godirwalk.Dirent) error { return nil } ext := path.Ext(filename)[1:] - if mime, ok := mimeTypes[ext]; ok { - it.ext = ext - it.mime = mime + if _, ok := mime.Types[ext]; ok { return s.handleTrack(it) } return nil @@ -71,9 +66,12 @@ func (s *Scanner) callbackPost(fullPath string, info *godirwalk.Dirent) error { } func (s *Scanner) handleFolder(it *item) error { - var folder model.Folder + var folder model.Album err := s.tx. - Where("path = ?", it.relPath). + Where(model.Album{ + LeftPath: it.directory, + RightPath: it.filename, + }). First(&folder). Error if !gorm.IsRecordNotFoundError(err) && @@ -82,7 +80,8 @@ func (s *Scanner) handleFolder(it *item) error { s.curFolders.Push(&folder) return nil } - folder.Path = it.relPath + folder.LeftPath = it.directory + folder.RightPath = it.filename s.tx.Save(&folder) folder.IsNew = true s.curFolders.Push(&folder) @@ -95,7 +94,7 @@ func (s *Scanner) handleTrack(it *item) error { var track model.Track err := s.tx. Where(model.Track{ - FolderID: s.curFolderID(), + AlbumID: s.curFolderID(), Filename: it.filename, }). First(&track). @@ -107,9 +106,8 @@ func (s *Scanner) handleTrack(it *item) error { return nil } track.Filename = it.filename - track.ContentType = it.mime track.Size = int(it.stat.Size()) - track.FolderID = s.curFolderID() + track.AlbumID = s.curFolderID() track.Duration = -1 track.Bitrate = -1 tags, err := readTags(it.fullPath) @@ -128,7 +126,8 @@ func (s *Scanner) handleTrack(it *item) error { // // set album artist basics var artist model.Artist - err = s.tx.Where("name = ?", tags.AlbumArtist()). + err = s.tx. + Where("name = ?", tags.AlbumArtist()). First(&artist). Error if gorm.IsRecordNotFoundError(err) { @@ -143,8 +142,8 @@ func (s *Scanner) handleTrack(it *item) error { if !s.curFolder().IsNew { return nil } - s.curFolder().AlbumTitle = tags.Album() - s.curFolder().AlbumYear = tags.Year() - s.curFolder().AlbumArtistID = artist.ID + s.curFolder().TagTitle = tags.Album() + s.curFolder().TagYear = tags.Year() + s.curFolder().TagArtistID = artist.ID return nil } diff --git a/server/handler/construct_sub_by_folder.go b/server/handler/construct_sub_by_folder.go index 3c23eb9..883a272 100644 --- a/server/handler/construct_sub_by_folder.go +++ b/server/handler/construct_sub_by_folder.go @@ -1,15 +1,17 @@ package handler import ( + "path" + "github.com/sentriz/gonic/model" "github.com/sentriz/gonic/server/subsonic" ) -func makeChildFromFolder(f *model.Folder, parent *model.Folder) *subsonic.Track { +func makeChildFromFolder(f *model.Album, parent *model.Album) *subsonic.Track { child := &subsonic.Track{ ID: f.ID, - Title: f.Name, - CoverID: f.CoverID, + CoverID: f.ID, + Title: f.RightPath, IsDir: true, } if parent != nil { @@ -18,48 +20,52 @@ func makeChildFromFolder(f *model.Folder, parent *model.Folder) *subsonic.Track return child } -func makeChildFromTrack(t *model.Track, parent *model.Folder) *subsonic.Track { +func makeChildFromTrack(t *model.Track, parent *model.Album) *subsonic.Track { return &subsonic.Track{ ID: t.ID, - Album: t.Album.Title, - Artist: t.TrackArtist, - ContentType: t.ContentType, - Path: t.Path, + Album: t.Album.RightPath, + ContentType: t.MIME(), + Suffix: t.Ext(), Size: t.Size, - Suffix: t.Suffix, - Title: t.Title, - TrackNumber: t.TrackNumber, - ParentID: parent.ID, - CoverID: parent.CoverID, - Duration: 0, - IsDir: false, - Type: "music", + Artist: t.TagTrackArtist, + Title: t.TagTitle, + TrackNumber: t.TagTrackNumber, + Path: path.Join( + parent.LeftPath, + parent.RightPath, + t.Filename, + ), + ParentID: parent.ID, + CoverID: parent.ID, + Duration: 0, + IsDir: false, + Type: "music", } } -func makeAlbumFromFolder(f *model.Folder) *subsonic.Album { +func makeAlbumFromFolder(f *model.Album) *subsonic.Album { return &subsonic.Album{ ID: f.ID, - Title: f.Name, - CoverID: f.CoverID, + Title: f.RightPath, + CoverID: f.ID, ParentID: f.ParentID, - Artist: f.Parent.Name, + Artist: f.Parent.RightPath, IsDir: true, } } -func makeArtistFromFolder(f *model.Folder) *subsonic.Artist { +func makeArtistFromFolder(f *model.Album) *subsonic.Artist { return &subsonic.Artist{ ID: f.ID, - Name: f.Name, + Name: f.RightPath, } } -func makeDirFromFolder(f *model.Folder, children []*subsonic.Track) *subsonic.Directory { +func makeDirFromFolder(f *model.Album, children []*subsonic.Track) *subsonic.Directory { return &subsonic.Directory{ ID: f.ID, Parent: f.ParentID, - Name: f.Name, + Name: f.RightPath, Children: children, } } diff --git a/server/handler/construct_sub_by_tags.go b/server/handler/construct_sub_by_tags.go index f00df7c..db3ebd5 100644 --- a/server/handler/construct_sub_by_tags.go +++ b/server/handler/construct_sub_by_tags.go @@ -1,6 +1,8 @@ package handler import ( + "path" + "github.com/sentriz/gonic/model" "github.com/sentriz/gonic/server/subsonic" ) @@ -8,9 +10,9 @@ import ( func makeAlbumFromAlbum(a *model.Album, artist *model.Artist) *subsonic.Album { return &subsonic.Album{ ID: a.ID, - Name: a.Title, + Name: a.TagTitle, Created: a.CreatedAt, - CoverID: a.CoverID, + CoverID: a.ID, Artist: artist.Name, ArtistID: artist.ID, } @@ -19,20 +21,24 @@ func makeAlbumFromAlbum(a *model.Album, artist *model.Artist) *subsonic.Album { func makeTrackFromTrack(t *model.Track, album *model.Album) *subsonic.Track { return &subsonic.Track{ ID: t.ID, - Title: t.Title, - Artist: t.TrackArtist, - TrackNumber: t.TrackNumber, - ContentType: t.ContentType, - Path: t.Path, - ParentID: t.FolderID, - Suffix: t.Suffix, + ContentType: t.MIME(), + Suffix: t.Ext(), + ParentID: t.AlbumID, CreatedAt: t.CreatedAt, Size: t.Size, - Album: album.Title, - AlbumID: album.ID, - ArtistID: album.Artist.ID, - CoverID: album.CoverID, - Type: "music", + Title: t.TagTitle, + Artist: t.TagTrackArtist, + TrackNumber: t.TagTrackNumber, + Path: path.Join( + album.LeftPath, + album.RightPath, + t.Filename, + ), + Album: album.TagTitle, + AlbumID: album.ID, + ArtistID: album.TagArtist.ID, + CoverID: album.ID, + Type: "music", } } diff --git a/server/handler/handler.go b/server/handler/handler.go index 4505cfd..bb6197c 100644 --- a/server/handler/handler.go +++ b/server/handler/handler.go @@ -25,7 +25,9 @@ type Controller struct { func (c *Controller) GetSetting(key string) string { var setting model.Setting - c.DB.Where("key = ?", key).First(&setting) + c.DB. + Where("key = ?", key). + First(&setting) return setting.Value } diff --git a/server/handler/handler_admin.go b/server/handler/handler_admin.go index 12a79b3..d041c4d 100644 --- a/server/handler/handler_admin.go +++ b/server/handler/handler_admin.go @@ -128,7 +128,10 @@ func (c *Controller) ServeChangePassword(w http.ResponseWriter, r *http.Request) return } var user model.User - err := c.DB.Where("name = ?", username).First(&user).Error + err := c.DB. + Where("name = ?", username). + First(&user). + Error if gorm.IsRecordNotFoundError(err) { http.Error(w, "couldn't find a user with that name", 400) return @@ -142,7 +145,9 @@ func (c *Controller) ServeChangePasswordDo(w http.ResponseWriter, r *http.Reques session := r.Context().Value(contextSessionKey).(*sessions.Session) username := r.URL.Query().Get("user") var user model.User - c.DB.Where("name = ?", username).First(&user) + c.DB. + Where("name = ?", username). + First(&user) passwordOne := r.FormValue("password_one") passwordTwo := r.FormValue("password_two") err := validatePasswords(passwordOne, passwordTwo) @@ -164,7 +169,10 @@ func (c *Controller) ServeDeleteUser(w http.ResponseWriter, r *http.Request) { return } var user model.User - err := c.DB.Where("name = ?", username).First(&user).Error + err := c.DB. + Where("name = ?", username). + First(&user). + Error if gorm.IsRecordNotFoundError(err) { http.Error(w, "couldn't find a user with that name", 400) return @@ -177,7 +185,9 @@ func (c *Controller) ServeDeleteUser(w http.ResponseWriter, r *http.Request) { func (c *Controller) ServeDeleteUserDo(w http.ResponseWriter, r *http.Request) { username := r.URL.Query().Get("user") var user model.User - c.DB.Where("name = ?", username).First(&user) + c.DB. + Where("name = ?", username). + First(&user) c.DB.Delete(&user) http.Redirect(w, r, "/admin/home", http.StatusSeeOther) } diff --git a/server/handler/handler_admin_utils_test.go b/server/handler/handler_admin_utils_test.go index bf2f086..1d08566 100644 --- a/server/handler/handler_admin_utils_test.go +++ b/server/handler/handler_admin_utils_test.go @@ -22,7 +22,9 @@ func TestFirstExisting(t *testing.T) { "default"}, } for _, tc := range cases { + tc := tc // pin t.Run(tc.name, func(t *testing.T) { + t.Parallel() actu := firstExisting(tc.or, tc.values...) if actu != tc.exp { t.Errorf("expected %q, got %q", tc.exp, actu) diff --git a/server/handler/handler_sub_by_folder.go b/server/handler/handler_sub_by_folder.go index 4b0c98c..c49bba4 100644 --- a/server/handler/handler_sub_by_folder.go +++ b/server/handler/handler_sub_by_folder.go @@ -19,12 +19,14 @@ import ( // under the root directory func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) { - var folders []model.Folder - c.DB.Where("parent_id = 1").Find(&folders) + var folders []model.Album + c.DB. + Where("parent_id = 1"). + Find(&folders) var indexMap = make(map[rune]*subsonic.Index) var indexes []*subsonic.Index for _, folder := range folders { - i := indexOf(folder.Name) + i := indexOf(folder.RightPath) index, ok := indexMap[i] if !ok { index = &subsonic.Index{ @@ -37,7 +39,7 @@ func (c *Controller) GetIndexes(w http.ResponseWriter, r *http.Request) { index.Artists = append(index.Artists, makeArtistFromFolder(&folder)) } - sort.Slice(indexes[:], func(i, j int) bool { + sort.Slice(indexes, func(i, j int) bool { return indexes[i].Name < indexes[j].Name }) sub := subsonic.NewResponse() @@ -55,11 +57,11 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) { return } childrenObj := []*subsonic.Track{} - var folder model.Folder + var folder model.Album c.DB.First(&folder, id) // // start looking for child childFolders in the current dir - var childFolders []model.Folder + var childFolders []model.Album c.DB. Where("parent_id = ?", id). Find(&childFolders) @@ -71,18 +73,18 @@ func (c *Controller) GetMusicDirectory(w http.ResponseWriter, r *http.Request) { // start looking for child childTracks in the current dir var childTracks []model.Track c.DB. - Where("folder_id = ?", id). + Where("album_id = ?", id). Preload("Album"). - Order("title"). + Order("filename"). Find(&childTracks) for _, c := range childTracks { + toAppend := makeChildFromTrack(&c, &folder) if getStrParam(r, "c") == "Jamstash" { // jamstash thinks it can't play flacs - c.ContentType = "audio/mpeg" - c.Suffix = "mp3" + toAppend.ContentType = "audio/mpeg" + toAppend.Suffix = "mp3" } - childrenObj = append(childrenObj, - makeChildFromTrack(&c, &folder)) + childrenObj = append(childrenObj, toAppend) } // // respond section @@ -103,16 +105,16 @@ func (c *Controller) GetAlbumList(w http.ResponseWriter, r *http.Request) { switch listType { case "alphabeticalByArtist": q = q.Joins(` - JOIN folders AS parent_folders - ON folders.parent_id = parent_folders.id`) - q = q.Order("parent_folders.name") + JOIN albums AS parent_albums + ON albums.parent_id = parent_albums.id`) + q = q.Order("parent_albums.right_path") case "alphabeticalByName": - q = q.Order("name") + q = q.Order("right_path") case "frequent": user := r.Context().Value(contextUserKey).(*model.User) q = q.Joins(` JOIN plays - ON folders.id = plays.folder_id AND plays.user_id = ?`, + ON albums.id = plays.album_id AND plays.user_id = ?`, user.ID) q = q.Order("plays.count DESC") case "newest": @@ -123,7 +125,7 @@ func (c *Controller) GetAlbumList(w http.ResponseWriter, r *http.Request) { user := r.Context().Value(contextUserKey).(*model.User) q = q.Joins(` JOIN plays - ON folders.id = plays.folder_id AND plays.user_id = ?`, + ON albums.id = plays.album_id AND plays.user_id = ?`, user.ID) q = q.Order("plays.time DESC") default: @@ -131,9 +133,9 @@ func (c *Controller) GetAlbumList(w http.ResponseWriter, r *http.Request) { "unknown value `%s` for parameter 'type'", listType) return } - var folders []model.Folder + var folders []model.Album q. - Where("folders.has_tracks = 1"). + Where("albums.tag_artist_id IS NOT NULL"). Offset(getIntParamOr(r, "offset", 0)). Limit(getIntParamOr(r, "size", 10)). Preload("Parent"). @@ -158,9 +160,9 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) { results := &subsonic.SearchResultTwo{} // // search "artists" - var artists []model.Folder + var artists []model.Album c.DB. - Where("parent_id = 1 AND name LIKE ?", query). + Where("parent_id = 1 AND right_path LIKE ?", query). Offset(getIntParamOr(r, "artistOffset", 0)). Limit(getIntParamOr(r, "artistCount", 20)). Find(&artists) @@ -170,10 +172,10 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) { } // // search "albums" - var albums []model.Folder + var albums []model.Album c.DB. Preload("Parent"). - Where("has_tracks = 1 AND name LIKE ?", query). + Where("tag_artist_id IS NOT NULL AND right_path LIKE ?", query). Offset(getIntParamOr(r, "albumOffset", 0)). Limit(getIntParamOr(r, "albumCount", 20)). Find(&albums) @@ -185,14 +187,14 @@ func (c *Controller) SearchTwo(w http.ResponseWriter, r *http.Request) { // search tracks var tracks []model.Track c.DB. - Preload("Folder"). - Where("title LIKE ?", query). + Preload("Album"). + Where("filename LIKE ?", query). Offset(getIntParamOr(r, "songOffset", 0)). Limit(getIntParamOr(r, "songCount", 20)). Find(&tracks) for _, t := range tracks { results.Tracks = append(results.Tracks, - makeChildFromTrack(&t, &t.Folder)) + makeChildFromTrack(&t, &t.Album)) } // sub := subsonic.NewResponse() diff --git a/server/handler/handler_sub_by_folder_test.go b/server/handler/handler_sub_by_folder_test.go index 803be0d..01c57fe 100644 --- a/server/handler/handler_sub_by_folder_test.go +++ b/server/handler/handler_sub_by_folder_test.go @@ -9,7 +9,7 @@ import ( func TestGetIndexes(t *testing.T) { testQueryCases(t, testController.GetIndexes, []*queryCase{ - {url.Values{"id": []string{"2"}}, "id_two", false}, + {url.Values{}, "no_args", false}, }) } diff --git a/server/handler/handler_sub_by_tags.go b/server/handler/handler_sub_by_tags.go index f2bbc36..35e3741 100644 --- a/server/handler/handler_sub_by_tags.go +++ b/server/handler/handler_sub_by_tags.go @@ -31,7 +31,7 @@ func (c *Controller) GetArtists(w http.ResponseWriter, r *http.Request) { index.Artists = append(index.Artists, makeArtistFromArtist(&artist)) } - sort.Slice(indexes.List[:], func(i, j int) bool { + sort.Slice(indexes.List, func(i, j int) bool { return indexes.List[i].Name < indexes.List[j].Name }) sub := subsonic.NewResponse() @@ -66,9 +66,9 @@ func (c *Controller) GetAlbum(w http.ResponseWriter, r *http.Request) { } var album model.Album err = c.DB. - Preload("Artist"). + Preload("TagArtist"). Preload("Tracks", func(db *gorm.DB) *gorm.DB { - return db.Order("tracks.track_number") + return db.Order("tracks.tag_track_number") }). First(&album, id). Error @@ -77,7 +77,7 @@ func (c *Controller) GetAlbum(w http.ResponseWriter, r *http.Request) { return } sub := subsonic.NewResponse() - sub.Album = makeAlbumFromAlbum(&album, &album.Artist) + sub.Album = makeAlbumFromAlbum(&album, &album.TagArtist) for _, track := range album.Tracks { sub.Album.Tracks = append(sub.Album.Tracks, makeTrackFromTrack(&track, &album)) @@ -98,16 +98,16 @@ func (c *Controller) GetAlbumListTwo(w http.ResponseWriter, r *http.Request) { case "alphabeticalByArtist": q = q.Joins(` JOIN artists - ON albums.artist_id = artists.id`) + ON albums.tag_artist_id = artists.id`) q = q.Order("artists.name") case "alphabeticalByName": - q = q.Order("title") + q = q.Order("tag_title") case "byYear": q = q.Where( - "year BETWEEN ? AND ?", + "tag_year BETWEEN ? AND ?", getIntParamOr(r, "fromYear", 1800), getIntParamOr(r, "toYear", 2200)) - q = q.Order("year") + q = q.Order("tag_year") case "frequent": user := r.Context().Value(contextUserKey).(*model.User) q = q.Joins(` @@ -133,15 +133,16 @@ func (c *Controller) GetAlbumListTwo(w http.ResponseWriter, r *http.Request) { } var albums []model.Album q. + Where("albums.tag_artist_id IS NOT NULL"). Offset(getIntParamOr(r, "offset", 0)). Limit(getIntParamOr(r, "size", 10)). - Preload("Artist"). + Preload("TagArtist"). Find(&albums) sub := subsonic.NewResponse() sub.AlbumsTwo = &subsonic.Albums{} for _, album := range albums { sub.AlbumsTwo.List = append(sub.AlbumsTwo.List, - makeAlbumFromAlbum(&album, &album.Artist)) + makeAlbumFromAlbum(&album, &album.TagArtist)) } respond(w, r, sub) } @@ -171,21 +172,21 @@ func (c *Controller) SearchThree(w http.ResponseWriter, r *http.Request) { // search "albums" var albums []model.Album c.DB. - Preload("Artist"). - Where("title LIKE ?", query). + Preload("TagArtist"). + Where("tag_title LIKE ?", query). Offset(getIntParamOr(r, "albumOffset", 0)). Limit(getIntParamOr(r, "albumCount", 20)). Find(&albums) for _, a := range albums { results.Albums = append(results.Albums, - makeAlbumFromAlbum(&a, &a.Artist)) + makeAlbumFromAlbum(&a, &a.TagArtist)) } // // search tracks var tracks []model.Track c.DB. Preload("Album"). - Where("title LIKE ?", query). + Where("tag_title LIKE ?", query). Offset(getIntParamOr(r, "songOffset", 0)). Limit(getIntParamOr(r, "songCount", 20)). Find(&tracks) diff --git a/server/handler/handler_sub_common.go b/server/handler/handler_sub_common.go index 1cf0eb7..1536f2d 100644 --- a/server/handler/handler_sub_common.go +++ b/server/handler/handler_sub_common.go @@ -8,6 +8,7 @@ import ( "time" "unicode" + "github.com/jinzhu/gorm" "github.com/rainycape/unidecode" "github.com/sentriz/gonic/model" @@ -32,15 +33,20 @@ func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) { return } var track model.Track - c.DB. + err = c.DB. Preload("Album"). - Preload("Folder"). - First(&track, id) - if track.Path == "" { + First(&track, id). + Error + if gorm.IsRecordNotFoundError(err) { respondError(w, r, 70, "media with id `%d` was not found", id) return } - absPath := path.Join(c.MusicPath, track.Path) + absPath := path.Join( + c.MusicPath, + track.Album.LeftPath, + track.Album.RightPath, + track.Filename, + ) file, err := os.Open(absPath) if err != nil { respondError(w, r, 0, "error while streaming media: %v", err) @@ -52,11 +58,12 @@ func (c *Controller) Stream(w http.ResponseWriter, r *http.Request) { // after we've served the file, mark the album as played user := r.Context().Value(contextUserKey).(*model.User) play := model.Play{ - AlbumID: track.Album.ID, - FolderID: track.Folder.ID, - UserID: user.ID, + AlbumID: track.Album.ID, + UserID: user.ID, } - c.DB.Where(play).First(&play) + c.DB. + Where(play). + First(&play) play.Time = time.Now() // for getAlbumList?type=recent play.Count++ // for getAlbumList?type=frequent c.DB.Save(&play) @@ -68,9 +75,26 @@ func (c *Controller) GetCoverArt(w http.ResponseWriter, r *http.Request) { respondError(w, r, 10, "please provide an `id` parameter") return } - var cover model.Cover - c.DB.First(&cover, id) - w.Write(cover.Image) + var folder model.Album + err = c.DB. + Select("id, path, cover"). + First(&folder, id). + Error + if gorm.IsRecordNotFoundError(err) { + respondError(w, r, 10, "could not find a cover with that id") + return + } + if folder.Cover == "" { + respondError(w, r, 10, "no cover found for that folder") + return + } + absPath := path.Join( + c.MusicPath, + folder.RightPath, + folder.LeftPath, + folder.Cover, + ) + http.ServeFile(w, r, absPath) } func (c *Controller) GetLicence(w http.ResponseWriter, r *http.Request) { diff --git a/server/handler/test_data/db b/server/handler/test_data/db index 08b6859..8249c95 100644 Binary files a/server/handler/test_data/db and b/server/handler/test_data/db differ diff --git a/server/handler/test_data/test_get_album_list_alpha_artist b/server/handler/test_data/test_get_album_list_alpha_artist index 6f839ef..0a232b9 100644 --- a/server/handler/test_data/test_get_album_list_alpha_artist +++ b/server/handler/test_data/test_get_album_list_alpha_artist @@ -6,7 +6,7 @@ "album": [ { "id": 6, - "coverArt": 2, + "coverArt": 6, "artist": "13th Floor Lowervators", "title": "(1967) Easter Nowhere", "parent": 5, @@ -15,7 +15,7 @@ }, { "id": 7, - "coverArt": 3, + "coverArt": 7, "artist": "13th Floor Lowervators", "title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators", "parent": 5, @@ -24,7 +24,7 @@ }, { "id": 3, - "coverArt": 1, + "coverArt": 3, "artist": "A Certain Ratio", "title": "(1994) The Graveyard and the Ballroom", "parent": 2, @@ -33,6 +33,7 @@ }, { "id": 4, + "coverArt": 4, "artist": "A Certain Ratio", "title": "(1981) To Each.", "parent": 2, @@ -41,7 +42,7 @@ }, { "id": 11, - "coverArt": 4, + "coverArt": 11, "artist": "There", "title": "(2010) Anika", "parent": 10, diff --git a/server/handler/test_data/test_get_album_list_alpha_name b/server/handler/test_data/test_get_album_list_alpha_name index bf4aa19..f6a3fa6 100644 --- a/server/handler/test_data/test_get_album_list_alpha_name +++ b/server/handler/test_data/test_get_album_list_alpha_name @@ -6,7 +6,7 @@ "album": [ { "id": 7, - "coverArt": 3, + "coverArt": 7, "artist": "13th Floor Lowervators", "title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators", "parent": 5, @@ -15,7 +15,7 @@ }, { "id": 6, - "coverArt": 2, + "coverArt": 6, "artist": "13th Floor Lowervators", "title": "(1967) Easter Nowhere", "parent": 5, @@ -24,6 +24,7 @@ }, { "id": 4, + "coverArt": 4, "artist": "A Certain Ratio", "title": "(1981) To Each.", "parent": 2, @@ -32,7 +33,7 @@ }, { "id": 3, - "coverArt": 1, + "coverArt": 3, "artist": "A Certain Ratio", "title": "(1994) The Graveyard and the Ballroom", "parent": 2, @@ -41,7 +42,7 @@ }, { "id": 11, - "coverArt": 4, + "coverArt": 11, "artist": "There", "title": "(2010) Anika", "parent": 10, diff --git a/server/handler/test_data/test_get_album_list_newest b/server/handler/test_data/test_get_album_list_newest index d862150..cdeff1a 100644 --- a/server/handler/test_data/test_get_album_list_newest +++ b/server/handler/test_data/test_get_album_list_newest @@ -6,7 +6,7 @@ "album": [ { "id": 11, - "coverArt": 4, + "coverArt": 11, "artist": "There", "title": "(2010) Anika", "parent": 10, @@ -15,7 +15,7 @@ }, { "id": 7, - "coverArt": 3, + "coverArt": 7, "artist": "13th Floor Lowervators", "title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators", "parent": 5, @@ -24,7 +24,7 @@ }, { "id": 6, - "coverArt": 2, + "coverArt": 6, "artist": "13th Floor Lowervators", "title": "(1967) Easter Nowhere", "parent": 5, @@ -33,6 +33,7 @@ }, { "id": 4, + "coverArt": 4, "artist": "A Certain Ratio", "title": "(1981) To Each.", "parent": 2, @@ -41,7 +42,7 @@ }, { "id": 3, - "coverArt": 1, + "coverArt": 3, "artist": "A Certain Ratio", "title": "(1994) The Graveyard and the Ballroom", "parent": 2, diff --git a/server/handler/test_data/test_get_album_list_random b/server/handler/test_data/test_get_album_list_random index 4da4f24..b8427e9 100644 --- a/server/handler/test_data/test_get_album_list_random +++ b/server/handler/test_data/test_get_album_list_random @@ -4,44 +4,45 @@ "version": "1.9.0", "albumList": { "album": [ - { - "id": 11, - "coverArt": 4, - "artist": "There", - "title": "(2010) Anika", - "parent": 10, - "isDir": true, - "created": "0001-01-01T00:00:00Z" - }, - { - "id": 6, - "coverArt": 2, - "artist": "13th Floor Lowervators", - "title": "(1967) Easter Nowhere", - "parent": 5, - "isDir": true, - "created": "0001-01-01T00:00:00Z" - }, - { - "id": 4, - "artist": "A Certain Ratio", - "title": "(1981) To Each.", - "parent": 2, - "isDir": true, - "created": "0001-01-01T00:00:00Z" - }, { "id": 3, - "coverArt": 1, + "coverArt": 3, "artist": "A Certain Ratio", "title": "(1994) The Graveyard and the Ballroom", "parent": 2, "isDir": true, "created": "0001-01-01T00:00:00Z" }, + { + "id": 11, + "coverArt": 11, + "artist": "There", + "title": "(2010) Anika", + "parent": 10, + "isDir": true, + "created": "0001-01-01T00:00:00Z" + }, + { + "id": 4, + "coverArt": 4, + "artist": "A Certain Ratio", + "title": "(1981) To Each.", + "parent": 2, + "isDir": true, + "created": "0001-01-01T00:00:00Z" + }, + { + "id": 6, + "coverArt": 6, + "artist": "13th Floor Lowervators", + "title": "(1967) Easter Nowhere", + "parent": 5, + "isDir": true, + "created": "0001-01-01T00:00:00Z" + }, { "id": 7, - "coverArt": 3, + "coverArt": 7, "artist": "13th Floor Lowervators", "title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators", "parent": 5, diff --git a/server/handler/test_data/test_get_album_list_two_alpha_artist b/server/handler/test_data/test_get_album_list_two_alpha_artist index ca74905..e6e10a1 100644 --- a/server/handler/test_data/test_get_album_list_two_alpha_artist +++ b/server/handler/test_data/test_get_album_list_two_alpha_artist @@ -5,43 +5,44 @@ "albumList2": { "album": [ { - "id": 3, - "coverArt": 2, + "id": 6, + "coverArt": 6, "artistId": 2, "artist": "13th Floor Elevators", "name": "Easter Everywhere", - "created": "2019-05-28T20:59:03.010415595+01:00" + "created": "2019-06-05T16:00:10.556862345+01:00" }, { - "id": 4, - "coverArt": 3, + "id": 7, + "coverArt": 7, "artistId": 2, "artist": "13th Floor Elevators", "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "created": "2019-05-28T20:59:03.022922683+01:00" + "created": "2019-06-05T16:00:10.560355528+01:00" }, { - "id": 1, - "coverArt": 1, + "id": 3, + "coverArt": 3, "artistId": 1, "artist": "A Certain Ratio", "name": "The Graveyard and the Ballroom", - "created": "2019-05-28T20:59:02.988372626+01:00" + "created": "2019-06-05T16:00:10.54747823+01:00" }, { - "id": 2, + "id": 4, + "coverArt": 4, "artistId": 1, "artist": "A Certain Ratio", "name": "To Each...", - "created": "2019-05-28T20:59:02.995320471+01:00" + "created": "2019-06-05T16:00:10.553065063+01:00" }, { - "id": 5, - "coverArt": 4, + "id": 11, + "coverArt": 11, "artistId": 3, "artist": "Anikas", "name": "Anika", - "created": "2019-05-28T20:59:03.035442597+01:00" + "created": "2019-06-05T16:00:10.565661506+01:00" } ] } diff --git a/server/handler/test_data/test_get_album_list_two_alpha_name b/server/handler/test_data/test_get_album_list_two_alpha_name index 7e02e2f..1f0b097 100644 --- a/server/handler/test_data/test_get_album_list_two_alpha_name +++ b/server/handler/test_data/test_get_album_list_two_alpha_name @@ -5,43 +5,44 @@ "albumList2": { "album": [ { - "id": 5, - "coverArt": 4, + "id": 11, + "coverArt": 11, "artistId": 3, "artist": "Anikas", "name": "Anika", - "created": "2019-05-28T20:59:03.035442597+01:00" + "created": "2019-06-05T16:00:10.565661506+01:00" }, { - "id": 3, - "coverArt": 2, + "id": 6, + "coverArt": 6, "artistId": 2, "artist": "13th Floor Elevators", "name": "Easter Everywhere", - "created": "2019-05-28T20:59:03.010415595+01:00" + "created": "2019-06-05T16:00:10.556862345+01:00" }, { - "id": 1, - "coverArt": 1, + "id": 3, + "coverArt": 3, "artistId": 1, "artist": "A Certain Ratio", "name": "The Graveyard and the Ballroom", - "created": "2019-05-28T20:59:02.988372626+01:00" + "created": "2019-06-05T16:00:10.54747823+01:00" }, { - "id": 4, - "coverArt": 3, + "id": 7, + "coverArt": 7, "artistId": 2, "artist": "13th Floor Elevators", "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "created": "2019-05-28T20:59:03.022922683+01:00" + "created": "2019-06-05T16:00:10.560355528+01:00" }, { - "id": 2, + "id": 4, + "coverArt": 4, "artistId": 1, "artist": "A Certain Ratio", "name": "To Each...", - "created": "2019-05-28T20:59:02.995320471+01:00" + "created": "2019-06-05T16:00:10.553065063+01:00" } ] } diff --git a/server/handler/test_data/test_get_album_list_two_newest b/server/handler/test_data/test_get_album_list_two_newest index 2176136..9648a8a 100644 --- a/server/handler/test_data/test_get_album_list_two_newest +++ b/server/handler/test_data/test_get_album_list_two_newest @@ -5,43 +5,44 @@ "albumList2": { "album": [ { - "id": 5, - "coverArt": 4, + "id": 11, + "coverArt": 11, "artistId": 3, "artist": "Anikas", "name": "Anika", - "created": "2019-05-28T20:59:03.035442597+01:00" + "created": "2019-06-05T16:00:10.565661506+01:00" }, { - "id": 4, - "coverArt": 3, + "id": 7, + "coverArt": 7, "artistId": 2, "artist": "13th Floor Elevators", "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "created": "2019-05-28T20:59:03.022922683+01:00" + "created": "2019-06-05T16:00:10.560355528+01:00" }, { - "id": 3, - "coverArt": 2, + "id": 6, + "coverArt": 6, "artistId": 2, "artist": "13th Floor Elevators", "name": "Easter Everywhere", - "created": "2019-05-28T20:59:03.010415595+01:00" + "created": "2019-06-05T16:00:10.556862345+01:00" }, { - "id": 2, + "id": 4, + "coverArt": 4, "artistId": 1, "artist": "A Certain Ratio", "name": "To Each...", - "created": "2019-05-28T20:59:02.995320471+01:00" + "created": "2019-06-05T16:00:10.553065063+01:00" }, { - "id": 1, - "coverArt": 1, + "id": 3, + "coverArt": 3, "artistId": 1, "artist": "A Certain Ratio", "name": "The Graveyard and the Ballroom", - "created": "2019-05-28T20:59:02.988372626+01:00" + "created": "2019-06-05T16:00:10.54747823+01:00" } ] } diff --git a/server/handler/test_data/test_get_album_list_two_random b/server/handler/test_data/test_get_album_list_two_random index 071cef6..e5b8c87 100644 --- a/server/handler/test_data/test_get_album_list_two_random +++ b/server/handler/test_data/test_get_album_list_two_random @@ -6,42 +6,43 @@ "album": [ { "id": 4, - "coverArt": 3, - "artistId": 2, - "artist": "13th Floor Elevators", - "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "created": "2019-05-28T20:59:03.022922683+01:00" - }, - { - "id": 5, "coverArt": 4, - "artistId": 3, - "artist": "Anikas", - "name": "Anika", - "created": "2019-05-28T20:59:03.035442597+01:00" - }, - { - "id": 1, - "coverArt": 1, - "artistId": 1, - "artist": "A Certain Ratio", - "name": "The Graveyard and the Ballroom", - "created": "2019-05-28T20:59:02.988372626+01:00" - }, - { - "id": 3, - "coverArt": 2, - "artistId": 2, - "artist": "13th Floor Elevators", - "name": "Easter Everywhere", - "created": "2019-05-28T20:59:03.010415595+01:00" - }, - { - "id": 2, "artistId": 1, "artist": "A Certain Ratio", "name": "To Each...", - "created": "2019-05-28T20:59:02.995320471+01:00" + "created": "2019-06-05T16:00:10.553065063+01:00" + }, + { + "id": 11, + "coverArt": 11, + "artistId": 3, + "artist": "Anikas", + "name": "Anika", + "created": "2019-06-05T16:00:10.565661506+01:00" + }, + { + "id": 3, + "coverArt": 3, + "artistId": 1, + "artist": "A Certain Ratio", + "name": "The Graveyard and the Ballroom", + "created": "2019-06-05T16:00:10.54747823+01:00" + }, + { + "id": 7, + "coverArt": 7, + "artistId": 2, + "artist": "13th Floor Elevators", + "name": "The Psychedelic Sounds of the 13th Floor Elevators", + "created": "2019-06-05T16:00:10.560355528+01:00" + }, + { + "id": 6, + "coverArt": 6, + "artistId": 2, + "artist": "13th Floor Elevators", + "name": "Easter Everywhere", + "created": "2019-06-05T16:00:10.556862345+01:00" } ] } diff --git a/server/handler/test_data/test_get_album_with_cover b/server/handler/test_data/test_get_album_with_cover index 3f128b4..652d725 100644 --- a/server/handler/test_data/test_get_album_with_cover +++ b/server/handler/test_data/test_get_album_with_cover @@ -4,181 +4,249 @@ "version": "1.9.0", "album": { "id": 3, - "coverArt": 2, - "artistId": 2, - "artist": "13th Floor Elevators", - "name": "Easter Everywhere", - "created": "2019-05-28T20:59:03.010415595+01:00", + "coverArt": 3, + "artistId": 1, + "artist": "A Certain Ratio", + "name": "The Graveyard and the Ballroom", + "created": "2019-06-05T16:00:10.54747823+01:00", "song": [ { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.01067974+01:00", - "id": 25, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/01.10 Slip Inside This House.flac", - "size": 52229000, + "coverArt": 3, + "created": "2019-06-05T16:00:10.552108331+01:00", + "id": 12, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/01.14 Do the Du (casse).flac", + "size": 20545509, "suffix": "flac", - "title": "Slip Inside This House", + "title": "Do the Du (casse)", "track": 1, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.010814449+01:00", - "id": 27, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/02.10 Slide Machine.flac", - "size": 22964562, + "coverArt": 3, + "created": "2019-06-05T16:00:10.550632503+01:00", + "id": 8, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/02.14 Faceless.flac", + "size": 16657561, "suffix": "flac", - "title": "Slide Machine", + "title": "Faceless", "track": 2, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.010880444+01:00", - "id": 28, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/03.10 She Lives (In a Time of Her Own).flac", - "size": 18474888, + "coverArt": 3, + "created": "2019-06-05T16:00:10.549864008+01:00", + "id": 6, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/03.14 Crippled Child.flac", + "size": 21325811, "suffix": "flac", - "title": "She Lives (In a Time of Her Own)", + "title": "Crippled Child", "track": 3, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.011044654+01:00", - "id": 30, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/04.10 Nobody to Love.flac", - "size": 18067448, + "coverArt": 3, + "created": "2019-06-05T16:00:10.551742258+01:00", + "id": 11, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/04.14 Choir.flac", + "size": 24728976, "suffix": "flac", - "title": "Nobody to Love", + "title": "Choir", "track": 4, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.011106774+01:00", - "id": 31, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/05.10 Baby Blue.flac", - "size": 31828836, + "coverArt": 3, + "created": "2019-06-05T16:00:10.548393601+01:00", + "id": 2, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/05.14 Flight.flac", + "size": 24860635, "suffix": "flac", - "title": "Baby Blue", + "title": "Flight", "track": 5, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.011174899+01:00", - "id": 32, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/06.10 Earthquake.flac", - "size": 29066645, + "coverArt": 3, + "created": "2019-06-05T16:00:10.552469878+01:00", + "id": 13, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/06.14 I Feel.flac", + "size": 16118749, "suffix": "flac", - "title": "Earthquake", + "title": "I Feel", "track": 6, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.010597689+01:00", - "id": 24, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/07.10 Dust.flac", - "size": 22652796, + "coverArt": 3, + "created": "2019-06-05T16:00:10.552842449+01:00", + "id": 14, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/07.14 Strain.flac", + "size": 17608752, "suffix": "flac", - "title": "Dust", + "title": "Strain", "track": 7, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.010749083+01:00", - "id": 26, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/08.10 Levitation.flac", - "size": 16354677, + "coverArt": 3, + "created": "2019-06-05T16:00:10.549504916+01:00", + "id": 5, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/08.14 All Night Party.flac", + "size": 24960016, "suffix": "flac", - "title": "Levitation", + "title": "All Night Party", "track": 8, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.011238025+01:00", - "id": 33, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/09.10 I Had to Tell You.flac", - "size": 14261007, + "coverArt": 3, + "created": "2019-06-05T16:00:10.549134887+01:00", + "id": 4, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/09.14 Oceans.flac", + "size": 26401567, "suffix": "flac", - "title": "I Had to Tell You", + "title": "Oceans", "track": 9, "type": "music" }, { - "album": "Easter Everywhere", + "album": "The Graveyard and the Ballroom", "albumId": 3, - "artist": "13th Floor Elevators", - "artistId": 2, + "artist": "A Certain Ratio", + "artistId": 1, "contentType": "audio/x-flac", - "coverArt": 2, - "created": "2019-05-28T20:59:03.010949903+01:00", - "id": 29, - "parent": 6, - "path": "13th Floor Lowervators/(1967) Easter Nowhere/10.10 Pictures (Leave Your Body Behind).flac", - "size": 39529576, + "coverArt": 3, + "created": "2019-06-05T16:00:10.551373999+01:00", + "id": 10, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/10.14 The Choir.flac", + "size": 24106680, "suffix": "flac", - "title": "Pictures (Leave Your Body Behind)", + "title": "The Choir", "track": 10, "type": "music" + }, + { + "album": "The Graveyard and the Ballroom", + "albumId": 3, + "artist": "A Certain Ratio", + "artistId": 1, + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "2019-06-05T16:00:10.550996621+01:00", + "id": 9, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/11.14 The Fox.flac", + "size": 24054498, + "suffix": "flac", + "title": "The Fox", + "track": 11, + "type": "music" + }, + { + "album": "The Graveyard and the Ballroom", + "albumId": 3, + "artist": "A Certain Ratio", + "artistId": 1, + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "2019-06-05T16:00:10.55027053+01:00", + "id": 7, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/12.14 Suspect.flac", + "size": 16592296, + "suffix": "flac", + "title": "Suspect", + "track": 12, + "type": "music" + }, + { + "album": "The Graveyard and the Ballroom", + "albumId": 3, + "artist": "A Certain Ratio", + "artistId": 1, + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "2019-06-05T16:00:10.547986038+01:00", + "id": 1, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/13.14 Flight.flac", + "size": 37302417, + "suffix": "flac", + "title": "Flight", + "track": 13, + "type": "music" + }, + { + "album": "The Graveyard and the Ballroom", + "albumId": 3, + "artist": "A Certain Ratio", + "artistId": 1, + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "2019-06-05T16:00:10.548763765+01:00", + "id": 3, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/14.14 Genotype_Phenotype.flac", + "size": 24349252, + "suffix": "flac", + "title": "Genotype/Phenotype", + "track": 14, + "type": "music" } ] } diff --git a/server/handler/test_data/test_get_album_without_cover b/server/handler/test_data/test_get_album_without_cover index b4d8404..0b9b94f 100644 --- a/server/handler/test_data/test_get_album_without_cover +++ b/server/handler/test_data/test_get_album_without_cover @@ -4,156 +4,8 @@ "version": "1.9.0", "album": { "id": 2, - "artistId": 1, - "artist": "A Certain Ratio", - "name": "To Each...", - "created": "2019-05-28T20:59:02.995320471+01:00", - "song": [ - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.99562727+01:00", - "id": 16, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./01.09 Felch.flac", - "size": 24708838, - "suffix": "flac", - "title": "Felch", - "track": 1, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.995889638+01:00", - "id": 20, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./02.09 My Spirit.flac", - "size": 17102404, - "suffix": "flac", - "title": "My Spirit", - "track": 2, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.99609285+01:00", - "id": 23, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./03.09 Forced Laugh.flac", - "size": 37924980, - "suffix": "flac", - "title": "Forced Laugh", - "track": 3, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.995953401+01:00", - "id": 21, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./04.09 Choir.flac", - "size": 21205583, - "suffix": "flac", - "title": "Choir", - "track": 4, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.99569934+01:00", - "id": 17, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./05.09 Back to the Start.flac", - "size": 56733069, - "suffix": "flac", - "title": "Back to the Start", - "track": 5, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.995826449+01:00", - "id": 19, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./06.09 The Fox.flac", - "size": 26835335, - "suffix": "flac", - "title": "The Fox", - "track": 6, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.995544892+01:00", - "id": 15, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./07.09 Loss.flac", - "size": 20494369, - "suffix": "flac", - "title": "Loss", - "track": 7, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.995761233+01:00", - "id": 18, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./08.09 Oceans.flac", - "size": 25233096, - "suffix": "flac", - "title": "Oceans", - "track": 8, - "type": "music" - }, - { - "album": "To Each...", - "albumId": 2, - "artist": "A Certain Ratio", - "artistId": 1, - "contentType": "audio/x-flac", - "created": "2019-05-28T20:59:02.99603217+01:00", - "id": 22, - "parent": 4, - "path": "A Certain Ratio/(1981) To Each./09.09 Winter Hill.flac", - "size": 89483446, - "suffix": "flac", - "title": "Winter Hill", - "track": 9, - "type": "music" - } - ] + "coverArt": 2, + "created": "2019-06-05T16:00:10.547172057+01:00" } } } diff --git a/server/handler/test_data/test_get_artist_id_one b/server/handler/test_data/test_get_artist_id_one index 44785a5..279a8a6 100644 --- a/server/handler/test_data/test_get_artist_id_one +++ b/server/handler/test_data/test_get_artist_id_one @@ -7,19 +7,20 @@ "name": "A Certain Ratio", "album": [ { - "id": 1, - "coverArt": 1, + "id": 3, + "coverArt": 3, "artistId": 1, "artist": "A Certain Ratio", "name": "The Graveyard and the Ballroom", - "created": "2019-05-28T20:59:02.988372626+01:00" + "created": "2019-06-05T16:00:10.54747823+01:00" }, { - "id": 2, + "id": 4, + "coverArt": 4, "artistId": 1, "artist": "A Certain Ratio", "name": "To Each...", - "created": "2019-05-28T20:59:02.995320471+01:00" + "created": "2019-06-05T16:00:10.553065063+01:00" } ] } diff --git a/server/handler/test_data/test_get_artist_id_three b/server/handler/test_data/test_get_artist_id_three index 24ad879..2cb1d18 100644 --- a/server/handler/test_data/test_get_artist_id_three +++ b/server/handler/test_data/test_get_artist_id_three @@ -7,12 +7,12 @@ "name": "Anikas", "album": [ { - "id": 5, - "coverArt": 4, + "id": 11, + "coverArt": 11, "artistId": 3, "artist": "Anikas", "name": "Anika", - "created": "2019-05-28T20:59:03.035442597+01:00" + "created": "2019-06-05T16:00:10.565661506+01:00" } ] } diff --git a/server/handler/test_data/test_get_artist_id_two b/server/handler/test_data/test_get_artist_id_two index 9ac78c4..50ebb3b 100644 --- a/server/handler/test_data/test_get_artist_id_two +++ b/server/handler/test_data/test_get_artist_id_two @@ -7,20 +7,20 @@ "name": "13th Floor Elevators", "album": [ { - "id": 3, - "coverArt": 2, + "id": 6, + "coverArt": 6, "artistId": 2, "artist": "13th Floor Elevators", "name": "Easter Everywhere", - "created": "2019-05-28T20:59:03.010415595+01:00" + "created": "2019-06-05T16:00:10.556862345+01:00" }, { - "id": 4, - "coverArt": 3, + "id": 7, + "coverArt": 7, "artistId": 2, "artist": "13th Floor Elevators", "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "created": "2019-05-28T20:59:03.022922683+01:00" + "created": "2019-06-05T16:00:10.560355528+01:00" } ] } diff --git a/server/handler/test_data/test_get_indexes_id_two b/server/handler/test_data/test_get_indexes_no_args similarity index 94% rename from server/handler/test_data/test_get_indexes_id_two rename to server/handler/test_data/test_get_indexes_no_args index e4af9c8..31976a6 100644 --- a/server/handler/test_data/test_get_indexes_id_two +++ b/server/handler/test_data/test_get_indexes_no_args @@ -11,6 +11,10 @@ { "id": 5, "name": "13th Floor Lowervators" + }, + { + "id": 8, + "name": "___Anika" } ] }, @@ -20,10 +24,6 @@ { "id": 2, "name": "A Certain Ratio" - }, - { - "id": 8, - "name": "Anika" } ] } diff --git a/server/handler/test_data/test_get_music_directory_with_tracks b/server/handler/test_data/test_get_music_directory_with_tracks index d33ef8f..b954d3a 100644 --- a/server/handler/test_data/test_get_music_directory_with_tracks +++ b/server/handler/test_data/test_get_music_directory_with_tracks @@ -8,55 +8,10 @@ "name": "(1994) The Graveyard and the Ballroom", "child": [ { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, - "created": "0001-01-01T00:00:00Z", - "id": 5, - "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/08.14 All Night Party.flac", - "size": 24960016, - "suffix": "flac", - "title": "All Night Party", - "track": 8, - "type": "music" - }, - { - "album": "The Graveyard and the Ballroom", - "artist": "A Certain Ratio", - "contentType": "audio/x-flac", - "coverArt": 1, - "created": "0001-01-01T00:00:00Z", - "id": 11, - "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/04.14 Choir.flac", - "size": 24728976, - "suffix": "flac", - "title": "Choir", - "track": 4, - "type": "music" - }, - { - "album": "The Graveyard and the Ballroom", - "artist": "A Certain Ratio", - "contentType": "audio/x-flac", - "coverArt": 1, - "created": "0001-01-01T00:00:00Z", - "id": 6, - "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/03.14 Crippled Child.flac", - "size": 21325811, - "suffix": "flac", - "title": "Crippled Child", - "track": 3, - "type": "music" - }, - { - "album": "The Graveyard and the Ballroom", - "artist": "A Certain Ratio", - "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 12, "parent": 3, @@ -68,10 +23,10 @@ "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 8, "parent": 3, @@ -83,25 +38,40 @@ "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", - "id": 1, + "id": 6, "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/13.14 Flight.flac", - "size": 37302417, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/03.14 Crippled Child.flac", + "size": 21325811, "suffix": "flac", - "title": "Flight", - "track": 13, + "title": "Crippled Child", + "track": 3, "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, + "created": "0001-01-01T00:00:00Z", + "id": 11, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/04.14 Choir.flac", + "size": 24728976, + "suffix": "flac", + "title": "Choir", + "track": 4, + "type": "music" + }, + { + "album": "(1994) The Graveyard and the Ballroom", + "artist": "A Certain Ratio", + "contentType": "audio/x-flac", + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 2, "parent": 3, @@ -113,25 +83,10 @@ "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, - "created": "0001-01-01T00:00:00Z", - "id": 3, - "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/14.14 Genotype_Phenotype.flac", - "size": 24349252, - "suffix": "flac", - "title": "Genotype/Phenotype", - "track": 14, - "type": "music" - }, - { - "album": "The Graveyard and the Ballroom", - "artist": "A Certain Ratio", - "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 13, "parent": 3, @@ -143,25 +98,10 @@ "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, - "created": "0001-01-01T00:00:00Z", - "id": 4, - "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/09.14 Oceans.flac", - "size": 26401567, - "suffix": "flac", - "title": "Oceans", - "track": 9, - "type": "music" - }, - { - "album": "The Graveyard and the Ballroom", - "artist": "A Certain Ratio", - "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 14, "parent": 3, @@ -173,25 +113,40 @@ "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", - "id": 7, + "id": 5, "parent": 3, - "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/12.14 Suspect.flac", - "size": 16592296, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/08.14 All Night Party.flac", + "size": 24960016, "suffix": "flac", - "title": "Suspect", - "track": 12, + "title": "All Night Party", + "track": 8, "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, + "created": "0001-01-01T00:00:00Z", + "id": 4, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/09.14 Oceans.flac", + "size": 26401567, + "suffix": "flac", + "title": "Oceans", + "track": 9, + "type": "music" + }, + { + "album": "(1994) The Graveyard and the Ballroom", + "artist": "A Certain Ratio", + "contentType": "audio/x-flac", + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 10, "parent": 3, @@ -203,10 +158,10 @@ "type": "music" }, { - "album": "The Graveyard and the Ballroom", + "album": "(1994) The Graveyard and the Ballroom", "artist": "A Certain Ratio", "contentType": "audio/x-flac", - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 9, "parent": 3, @@ -216,6 +171,51 @@ "title": "The Fox", "track": 11, "type": "music" + }, + { + "album": "(1994) The Graveyard and the Ballroom", + "artist": "A Certain Ratio", + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "0001-01-01T00:00:00Z", + "id": 7, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/12.14 Suspect.flac", + "size": 16592296, + "suffix": "flac", + "title": "Suspect", + "track": 12, + "type": "music" + }, + { + "album": "(1994) The Graveyard and the Ballroom", + "artist": "A Certain Ratio", + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "0001-01-01T00:00:00Z", + "id": 1, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/13.14 Flight.flac", + "size": 37302417, + "suffix": "flac", + "title": "Flight", + "track": 13, + "type": "music" + }, + { + "album": "(1994) The Graveyard and the Ballroom", + "artist": "A Certain Ratio", + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "0001-01-01T00:00:00Z", + "id": 3, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/14.14 Genotype_Phenotype.flac", + "size": 24349252, + "suffix": "flac", + "title": "Genotype/Phenotype", + "track": 14, + "type": "music" } ] } diff --git a/server/handler/test_data/test_get_music_directory_without_tracks b/server/handler/test_data/test_get_music_directory_without_tracks index 04b8ccc..4702d84 100644 --- a/server/handler/test_data/test_get_music_directory_without_tracks +++ b/server/handler/test_data/test_get_music_directory_without_tracks @@ -8,7 +8,7 @@ "name": "A Certain Ratio", "child": [ { - "coverArt": 1, + "coverArt": 3, "created": "0001-01-01T00:00:00Z", "id": 3, "isDir": true, @@ -16,9 +16,10 @@ "title": "(1994) The Graveyard and the Ballroom" }, { + "coverArt": 4, "created": "0001-01-01T00:00:00Z", - "isDir": true, "id": 4, + "isDir": true, "parent": 2, "title": "(1981) To Each." } diff --git a/server/handler/test_data/test_search_three_q_13 b/server/handler/test_data/test_search_three_q_13 index 9689f82..5f848ed 100644 --- a/server/handler/test_data/test_search_three_q_13 +++ b/server/handler/test_data/test_search_three_q_13 @@ -11,12 +11,12 @@ ], "album": [ { - "id": 4, - "coverArt": 3, + "id": 7, + "coverArt": 7, "artistId": 2, "artist": "13th Floor Elevators", "name": "The Psychedelic Sounds of the 13th Floor Elevators", - "created": "2019-05-28T20:59:03.022922683+01:00" + "created": "2019-06-05T16:00:10.560355528+01:00" } ] } diff --git a/server/handler/test_data/test_search_three_q_ani b/server/handler/test_data/test_search_three_q_ani index accc59d..69e491b 100644 --- a/server/handler/test_data/test_search_three_q_ani +++ b/server/handler/test_data/test_search_three_q_ani @@ -11,12 +11,12 @@ ], "album": [ { - "id": 5, - "coverArt": 4, + "id": 11, + "coverArt": 11, "artistId": 3, "artist": "Anikas", "name": "Anika", - "created": "2019-05-28T20:59:03.035442597+01:00" + "created": "2019-06-05T16:00:10.565661506+01:00" } ] } diff --git a/server/handler/test_data/test_search_two_q_13 b/server/handler/test_data/test_search_two_q_13 index 5de3e60..f9f8334 100644 --- a/server/handler/test_data/test_search_two_q_13 +++ b/server/handler/test_data/test_search_two_q_13 @@ -12,13 +12,45 @@ ], "album": [ { - "coverArt": 3, + "coverArt": 7, "created": "0001-01-01T00:00:00Z", "id": 7, "isDir": true, "parent": 5, "title": "(1966) The Psychedelic Sounds of the 13th Floor Elevators" } + ], + "song": [ + { + "album": "(1994) The Graveyard and the Ballroom", + "artist": "A Certain Ratio", + "contentType": "audio/x-flac", + "coverArt": 3, + "created": "0001-01-01T00:00:00Z", + "id": 1, + "parent": 3, + "path": "A Certain Ratio/(1994) The Graveyard and the Ballroom/13.14 Flight.flac", + "size": 37302417, + "suffix": "flac", + "title": "Flight", + "track": 13, + "type": "music" + }, + { + "album": "(1966) The Psychedelic Sounds of the 13th Floor Elevators", + "artist": "13th Floor Elevators", + "contentType": "audio/mpeg", + "coverArt": 7, + "created": "0001-01-01T00:00:00Z", + "id": 35, + "parent": 7, + "path": "13th Floor Lowervators/(1966) The Psychedelic Sounds of the 13th Floor Elevators/13.21 Before You Accuse Me.mp3", + "size": 4722688, + "suffix": "mp3", + "title": "Before You Accuse Me", + "track": 13, + "type": "music" + } ] } } diff --git a/server/handler/test_data/test_search_two_q_ani b/server/handler/test_data/test_search_two_q_ani index f7456bf..c199c25 100644 --- a/server/handler/test_data/test_search_two_q_ani +++ b/server/handler/test_data/test_search_two_q_ani @@ -7,12 +7,12 @@ { "id": 8, "parent": 1, - "name": "Anika" + "name": "___Anika" } ], "album": [ { - "coverArt": 4, + "coverArt": 11, "created": "0001-01-01T00:00:00Z", "id": 11, "isDir": true, diff --git a/server/lastfm/lastfm.go b/server/lastfm/lastfm.go index bebfaa0..8c7eb44 100644 --- a/server/lastfm/lastfm.go +++ b/server/lastfm/lastfm.go @@ -48,11 +48,11 @@ func Scrobble(apiKey, secret, session string, track *model.Track, } params.Add("api_key", apiKey) params.Add("sk", session) - params.Add("artist", track.TrackArtist) - params.Add("track", track.Title) - params.Add("album", track.Album.Title) + params.Add("artist", track.TagTrackArtist) + params.Add("track", track.TagTitle) + params.Add("album", track.Album.TagTitle) params.Add("albumArtist", track.Artist.Name) - params.Add("trackNumber", strconv.Itoa(track.TrackNumber)) + params.Add("trackNumber", strconv.Itoa(track.TagTrackNumber)) params.Add("api_sig", getParamSignature(params, secret)) _, err := makeRequest("POST", params) return err diff --git a/server/server.go b/server/server.go index 0fe3726..5ad1298 100644 --- a/server/server.go +++ b/server/server.go @@ -5,7 +5,6 @@ import ( "time" "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/sqlite" "github.com/sentriz/gonic/server/handler" ) @@ -43,12 +42,9 @@ func New(db *gorm.DB, musicPath string, listenAddr string) *Server { DB: db, MusicPath: musicPath, } - ret := &Server{ + return &Server{ mux: mux, Server: server, Controller: controller, } - ret.setupAdmin() - ret.setupSubsonic() - return ret } diff --git a/server/setup_admin.go b/server/setup_admin.go index 9422768..4b1ab4b 100644 --- a/server/setup_admin.go +++ b/server/setup_admin.go @@ -28,14 +28,14 @@ func extendFromBox(tmpl *template.Template, box *packr.Box, key string) *templat return newT } -func (s *Server) setupAdmin() { +func (s *Server) SetupAdmin() { sessionKey := []byte(s.GetSetting("session_key")) if len(sessionKey) == 0 { sessionKey = securecookie.GenerateRandomKey(32) s.SetSetting("session_key", string(sessionKey)) } // create gormstore (and cleanup) for backend sessions - s.SessDB = gormstore.New(s.DB, []byte(sessionKey)) + s.SessDB = gormstore.New(s.DB, sessionKey) go s.SessDB.PeriodicCleanup(1*time.Hour, nil) // using packr to bundle templates and static files box := packr.New("templates", "./templates") diff --git a/server/setup_subsonic.go b/server/setup_subsonic.go index 2733ca8..2162a69 100644 --- a/server/setup_subsonic.go +++ b/server/setup_subsonic.go @@ -1,6 +1,6 @@ package server -func (s *Server) setupSubsonic() { +func (s *Server) SetupSubsonic() { withWare := newChain( s.WithLogging, s.WithCORS,