Renamed Id to ID, following GoLang convention
This commit is contained in:
+6
-6
@@ -25,7 +25,7 @@ func (c *BrowsingController) GetMusicFolders(w http.ResponseWriter, r *http.Requ
|
|||||||
mediaFolderList, _ := c.browser.MediaFolders()
|
mediaFolderList, _ := c.browser.MediaFolders()
|
||||||
folders := make([]responses.MusicFolder, len(mediaFolderList))
|
folders := make([]responses.MusicFolder, len(mediaFolderList))
|
||||||
for i, f := range mediaFolderList {
|
for i, f := range mediaFolderList {
|
||||||
folders[i].Id = f.Id
|
folders[i].Id = f.ID
|
||||||
folders[i].Name = f.Name
|
folders[i].Name = f.Name
|
||||||
}
|
}
|
||||||
response := NewEmpty()
|
response := NewEmpty()
|
||||||
@@ -50,7 +50,7 @@ func (c *BrowsingController) getArtistIndex(r *http.Request, ifModifiedSince tim
|
|||||||
res.Index[i].Name = idx.Id
|
res.Index[i].Name = idx.Id
|
||||||
res.Index[i].Artists = make([]responses.Artist, len(idx.Artists))
|
res.Index[i].Artists = make([]responses.Artist, len(idx.Artists))
|
||||||
for j, a := range idx.Artists {
|
for j, a := range idx.Artists {
|
||||||
res.Index[i].Artists[j].Id = a.ArtistId
|
res.Index[i].Artists[j].Id = a.ArtistID
|
||||||
res.Index[i].Artists[j].Name = a.Artist
|
res.Index[i].Artists[j].Name = a.Artist
|
||||||
res.Index[i].Artists[j].AlbumCount = a.AlbumCount
|
res.Index[i].Artists[j].AlbumCount = a.AlbumCount
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@ func (c *BrowsingController) GetMusicDirectory(w http.ResponseWriter, r *http.Re
|
|||||||
dir, err := c.browser.Directory(r.Context(), id)
|
dir, err := c.browser.Directory(r.Context(), id)
|
||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Error(r, "Requested Id not found ", "id", id)
|
log.Error(r, "Requested ID not found ", "id", id)
|
||||||
return nil, NewError(responses.ErrorDataNotFound, "Directory not found")
|
return nil, NewError(responses.ErrorDataNotFound, "Directory not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@@ -104,7 +104,7 @@ func (c *BrowsingController) GetArtist(w http.ResponseWriter, r *http.Request) (
|
|||||||
dir, err := c.browser.Artist(r.Context(), id)
|
dir, err := c.browser.Artist(r.Context(), id)
|
||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Error(r, "Requested ArtistId not found ", "id", id)
|
log.Error(r, "Requested ArtistID not found ", "id", id)
|
||||||
return nil, NewError(responses.ErrorDataNotFound, "Artist not found")
|
return nil, NewError(responses.ErrorDataNotFound, "Artist not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
@@ -121,7 +121,7 @@ func (c *BrowsingController) GetAlbum(w http.ResponseWriter, r *http.Request) (*
|
|||||||
dir, err := c.browser.Album(r.Context(), id)
|
dir, err := c.browser.Album(r.Context(), id)
|
||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Error(r, "Requested Id not found ", "id", id)
|
log.Error(r, "Requested ID not found ", "id", id)
|
||||||
return nil, NewError(responses.ErrorDataNotFound, "Album not found")
|
return nil, NewError(responses.ErrorDataNotFound, "Album not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
@@ -138,7 +138,7 @@ func (c *BrowsingController) GetSong(w http.ResponseWriter, r *http.Request) (*r
|
|||||||
song, err := c.browser.GetSong(id)
|
song, err := c.browser.GetSong(id)
|
||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Error(r, "Requested Id not found ", "id", id)
|
log.Error(r, "Requested ID not found ", "id", id)
|
||||||
return nil, NewError(responses.ErrorDataNotFound, "Song not found")
|
return nil, NewError(responses.ErrorDataNotFound, "Song not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (c *MediaAnnotationController) SetRating(w http.ResponseWriter, r *http.Req
|
|||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
return nil, NewError(responses.ErrorDataNotFound, "Id not found")
|
return nil, NewError(responses.ErrorDataNotFound, "ID not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
return nil, NewError(responses.ErrorGeneric, "Internal Error")
|
return nil, NewError(responses.ErrorGeneric, "Internal Error")
|
||||||
@@ -68,7 +68,7 @@ func (c *MediaAnnotationController) Star(w http.ResponseWriter, r *http.Request)
|
|||||||
switch {
|
switch {
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
return nil, NewError(responses.ErrorDataNotFound, "Id not found")
|
return nil, NewError(responses.ErrorDataNotFound, "ID not found")
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Error(r, err)
|
log.Error(r, err)
|
||||||
return nil, NewError(responses.ErrorGeneric, "Internal Error")
|
return nil, NewError(responses.ErrorGeneric, "Internal Error")
|
||||||
|
|||||||
+1
-1
@@ -26,7 +26,7 @@ func (c *PlaylistsController) GetPlaylists(w http.ResponseWriter, r *http.Reques
|
|||||||
}
|
}
|
||||||
playlists := make([]responses.Playlist, len(allPls))
|
playlists := make([]responses.Playlist, len(allPls))
|
||||||
for i, p := range allPls {
|
for i, p := range allPls {
|
||||||
playlists[i].Id = p.Id
|
playlists[i].Id = p.ID
|
||||||
playlists[i].Name = p.Name
|
playlists[i].Name = p.Name
|
||||||
playlists[i].Comment = p.Comment
|
playlists[i].Comment = p.Comment
|
||||||
playlists[i].SongCount = len(p.Tracks)
|
playlists[i].SongCount = len(p.Tracks)
|
||||||
|
|||||||
+2
-2
@@ -3,9 +3,9 @@ package domain
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Album struct {
|
type Album struct {
|
||||||
Id string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
ArtistId string `parent:"artist"`
|
ArtistID string `parent:"artist"`
|
||||||
CoverArtPath string
|
CoverArtPath string
|
||||||
CoverArtId string
|
CoverArtId string
|
||||||
Artist string
|
Artist string
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Artist struct {
|
type Artist struct {
|
||||||
Id string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
AlbumCount int
|
AlbumCount int
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@ package domain
|
|||||||
import "github.com/cloudsonic/sonic-server/utils"
|
import "github.com/cloudsonic/sonic-server/utils"
|
||||||
|
|
||||||
type ArtistInfo struct {
|
type ArtistInfo struct {
|
||||||
ArtistId string
|
ArtistID string
|
||||||
Artist string
|
Artist string
|
||||||
AlbumCount int
|
AlbumCount int
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -6,14 +6,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type MediaFile struct {
|
type MediaFile struct {
|
||||||
Id string
|
ID string
|
||||||
Path string
|
Path string
|
||||||
Title string
|
Title string
|
||||||
Album string
|
Album string
|
||||||
Artist string
|
Artist string
|
||||||
ArtistId string
|
ArtistID string
|
||||||
AlbumArtist string
|
AlbumArtist string
|
||||||
AlbumId string `parent:"album"`
|
AlbumID string `parent:"album"`
|
||||||
HasCoverArt bool
|
HasCoverArt bool
|
||||||
TrackNumber int
|
TrackNumber int
|
||||||
DiscNumber int
|
DiscNumber int
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
type MediaFolder struct {
|
type MediaFolder struct {
|
||||||
Id string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Path string
|
Path string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import "time"
|
|||||||
const NowPlayingExpire = 60 * time.Minute
|
const NowPlayingExpire = 60 * time.Minute
|
||||||
|
|
||||||
type NowPlayingInfo struct {
|
type NowPlayingInfo struct {
|
||||||
TrackId string
|
TrackID string
|
||||||
Start time.Time
|
Start time.Time
|
||||||
Username string
|
Username string
|
||||||
PlayerId int
|
PlayerId int
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
type Playlist struct {
|
type Playlist struct {
|
||||||
Id string
|
ID string
|
||||||
Name string
|
Name string
|
||||||
Comment string
|
Comment string
|
||||||
FullPath string
|
FullPath string
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Property struct {
|
type Property struct {
|
||||||
Id string
|
ID string
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -116,7 +116,7 @@ func (b *browser) GetSong(id string) (*Entry, error) {
|
|||||||
|
|
||||||
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
|
func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *DirectoryInfo {
|
||||||
dir := &DirectoryInfo{
|
dir := &DirectoryInfo{
|
||||||
Id: a.Id,
|
Id: a.ID,
|
||||||
Name: a.Name,
|
Name: a.Name,
|
||||||
AlbumCount: a.AlbumCount,
|
AlbumCount: a.AlbumCount,
|
||||||
}
|
}
|
||||||
@@ -131,14 +131,14 @@ func (b *browser) buildArtistDir(a *domain.Artist, albums domain.Albums) *Direct
|
|||||||
|
|
||||||
func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirectoryInfo {
|
func (b *browser) buildAlbumDir(al *domain.Album, tracks domain.MediaFiles) *DirectoryInfo {
|
||||||
dir := &DirectoryInfo{
|
dir := &DirectoryInfo{
|
||||||
Id: al.Id,
|
Id: al.ID,
|
||||||
Name: al.Name,
|
Name: al.Name,
|
||||||
Parent: al.ArtistId,
|
Parent: al.ArtistID,
|
||||||
PlayCount: int32(al.PlayCount),
|
PlayCount: int32(al.PlayCount),
|
||||||
UserRating: al.Rating,
|
UserRating: al.Rating,
|
||||||
Starred: al.StarredAt,
|
Starred: al.StarredAt,
|
||||||
Artist: al.Artist,
|
Artist: al.Artist,
|
||||||
ArtistId: al.ArtistId,
|
ArtistId: al.ArtistID,
|
||||||
SongCount: al.SongCount,
|
SongCount: al.SongCount,
|
||||||
Duration: al.Duration,
|
Duration: al.Duration,
|
||||||
Created: al.CreatedAt,
|
Created: al.CreatedAt,
|
||||||
|
|||||||
+10
-10
@@ -45,7 +45,7 @@ type Entries []Entry
|
|||||||
|
|
||||||
func FromArtist(ar *domain.Artist) Entry {
|
func FromArtist(ar *domain.Artist) Entry {
|
||||||
e := Entry{}
|
e := Entry{}
|
||||||
e.Id = ar.Id
|
e.Id = ar.ID
|
||||||
e.Title = ar.Name
|
e.Title = ar.Name
|
||||||
e.AlbumCount = ar.AlbumCount
|
e.AlbumCount = ar.AlbumCount
|
||||||
e.IsDir = true
|
e.IsDir = true
|
||||||
@@ -54,10 +54,10 @@ func FromArtist(ar *domain.Artist) Entry {
|
|||||||
|
|
||||||
func FromAlbum(al *domain.Album) Entry {
|
func FromAlbum(al *domain.Album) Entry {
|
||||||
e := Entry{}
|
e := Entry{}
|
||||||
e.Id = al.Id
|
e.Id = al.ID
|
||||||
e.Title = al.Name
|
e.Title = al.Name
|
||||||
e.IsDir = true
|
e.IsDir = true
|
||||||
e.Parent = al.ArtistId
|
e.Parent = al.ArtistID
|
||||||
e.Album = al.Name
|
e.Album = al.Name
|
||||||
e.Year = al.Year
|
e.Year = al.Year
|
||||||
e.Artist = al.AlbumArtist
|
e.Artist = al.AlbumArtist
|
||||||
@@ -66,8 +66,8 @@ func FromAlbum(al *domain.Album) Entry {
|
|||||||
e.Starred = al.StarredAt
|
e.Starred = al.StarredAt
|
||||||
e.PlayCount = int32(al.PlayCount)
|
e.PlayCount = int32(al.PlayCount)
|
||||||
e.Created = al.CreatedAt
|
e.Created = al.CreatedAt
|
||||||
e.AlbumId = al.Id
|
e.AlbumId = al.ID
|
||||||
e.ArtistId = al.ArtistId
|
e.ArtistId = al.ArtistID
|
||||||
e.UserRating = al.Rating
|
e.UserRating = al.Rating
|
||||||
e.Duration = al.Duration
|
e.Duration = al.Duration
|
||||||
e.SongCount = al.SongCount
|
e.SongCount = al.SongCount
|
||||||
@@ -76,10 +76,10 @@ func FromAlbum(al *domain.Album) Entry {
|
|||||||
|
|
||||||
func FromMediaFile(mf *domain.MediaFile) Entry {
|
func FromMediaFile(mf *domain.MediaFile) Entry {
|
||||||
e := Entry{}
|
e := Entry{}
|
||||||
e.Id = mf.Id
|
e.Id = mf.ID
|
||||||
e.Title = mf.Title
|
e.Title = mf.Title
|
||||||
e.IsDir = false
|
e.IsDir = false
|
||||||
e.Parent = mf.AlbumId
|
e.Parent = mf.AlbumID
|
||||||
e.Album = mf.Album
|
e.Album = mf.Album
|
||||||
e.Year = mf.Year
|
e.Year = mf.Year
|
||||||
e.Artist = mf.Artist
|
e.Artist = mf.Artist
|
||||||
@@ -91,7 +91,7 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
|
|||||||
e.BitRate = mf.BitRate
|
e.BitRate = mf.BitRate
|
||||||
e.Starred = mf.StarredAt
|
e.Starred = mf.StarredAt
|
||||||
if mf.HasCoverArt {
|
if mf.HasCoverArt {
|
||||||
e.CoverArt = mf.Id
|
e.CoverArt = mf.ID
|
||||||
}
|
}
|
||||||
e.ContentType = mf.ContentType()
|
e.ContentType = mf.ContentType()
|
||||||
// Creates a "pseudo" path, to avoid sending absolute paths to the client
|
// Creates a "pseudo" path, to avoid sending absolute paths to the client
|
||||||
@@ -101,8 +101,8 @@ func FromMediaFile(mf *domain.MediaFile) Entry {
|
|||||||
e.PlayCount = int32(mf.PlayCount)
|
e.PlayCount = int32(mf.PlayCount)
|
||||||
e.DiscNumber = mf.DiscNumber
|
e.DiscNumber = mf.DiscNumber
|
||||||
e.Created = mf.CreatedAt
|
e.Created = mf.CreatedAt
|
||||||
e.AlbumId = mf.AlbumId
|
e.AlbumId = mf.AlbumID
|
||||||
e.ArtistId = mf.ArtistId
|
e.ArtistId = mf.ArtistID
|
||||||
e.Type = "music" // TODO Hardcoded for now
|
e.Type = "music" // TODO Hardcoded for now
|
||||||
e.UserRating = mf.Rating
|
e.UserRating = mf.Rating
|
||||||
return e
|
return e
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestCover(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When id is found", func() {
|
Convey("When id is found", func() {
|
||||||
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
||||||
err := cover.Get("2", 0, out)
|
err := cover.Get("2", 0, out)
|
||||||
|
|
||||||
Convey("Then it should return the cover from the file", func() {
|
Convey("Then it should return the cover from the file", func() {
|
||||||
@@ -41,7 +41,7 @@ func TestCover(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When there is an error accessing the database", func() {
|
Convey("When there is an error accessing the database", func() {
|
||||||
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
||||||
mockMediaFileRepo.SetError(true)
|
mockMediaFileRepo.SetError(true)
|
||||||
err := cover.Get("2", 0, out)
|
err := cover.Get("2", 0, out)
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ func TestCover(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When id is found but file is not present", func() {
|
Convey("When id is found but file is not present", func() {
|
||||||
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/NOT_FOUND.mp3"}]`, 1)
|
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/NOT_FOUND.mp3"}]`, 1)
|
||||||
err := cover.Get("2", 0, out)
|
err := cover.Get("2", 0, out)
|
||||||
|
|
||||||
Convey("Then it should return DatNotFound error", func() {
|
Convey("Then it should return DatNotFound error", func() {
|
||||||
@@ -58,7 +58,7 @@ func TestCover(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When specifying a size", func() {
|
Convey("When specifying a size", func() {
|
||||||
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
mockMediaFileRepo.SetData(`[{"ID":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
||||||
err := cover.Get("2", 100, out)
|
err := cover.Get("2", 100, out)
|
||||||
|
|
||||||
Convey("Then image returned should be 100x100", func() {
|
Convey("Then image returned should be 100x100", func() {
|
||||||
@@ -71,7 +71,7 @@ func TestCover(t *testing.T) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When id is for an album", func() {
|
Convey("When id is for an album", func() {
|
||||||
mockAlbumRepo.SetData(`[{"Id":"1","CoverArtPath":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
mockAlbumRepo.SetData(`[{"ID":"1","CoverArtPath":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
|
||||||
err := cover.Get("al-1", 0, out)
|
err := cover.Get("al-1", 0, out)
|
||||||
|
|
||||||
Convey("Then it should return the cover for the album", func() {
|
Convey("Then it should return the cover for the album", func() {
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ func (g *listGenerator) GetNowPlaying() (Entries, error) {
|
|||||||
}
|
}
|
||||||
entries := make(Entries, len(npInfo))
|
entries := make(Entries, len(npInfo))
|
||||||
for i, np := range npInfo {
|
for i, np := range npInfo {
|
||||||
mf, err := g.mfRepository.Get(np.TrackId)
|
mf, err := g.mfRepository.Get(np.TrackID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -67,7 +67,7 @@ func (p *playlists) Update(playlistId string, name *string, idsToAdd []string, i
|
|||||||
}
|
}
|
||||||
if name != nil {
|
if name != nil {
|
||||||
pl.Name = *name
|
pl.Name = *name
|
||||||
err := p.itunes.RenamePlaylist(pl.Id, pl.Name)
|
err := p.itunes.RenamePlaylist(pl.ID, pl.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ func (p *playlists) Update(playlistId string, name *string, idsToAdd []string, i
|
|||||||
pl.Tracks, pl.Tracks[len(pl.Tracks)-1] = append(pl.Tracks[:i], pl.Tracks[i+1:]...), ""
|
pl.Tracks, pl.Tracks[len(pl.Tracks)-1] = append(pl.Tracks[:i], pl.Tracks[i+1:]...), ""
|
||||||
}
|
}
|
||||||
pl.Tracks = append(pl.Tracks, idsToAdd...)
|
pl.Tracks = append(pl.Tracks, idsToAdd...)
|
||||||
err := p.itunes.UpdatePlaylist(pl.Id, pl.Tracks)
|
err := p.itunes.UpdatePlaylist(pl.ID, pl.Tracks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ func (p *playlists) Get(id string) (*PlaylistInfo, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pinfo := &PlaylistInfo{
|
pinfo := &PlaylistInfo{
|
||||||
Id: pl.Id,
|
Id: pl.ID,
|
||||||
Name: pl.Name,
|
Name: pl.Name,
|
||||||
SongCount: len(pl.Tracks),
|
SongCount: len(pl.Tracks),
|
||||||
Duration: pl.Duration,
|
Duration: pl.Duration,
|
||||||
|
|||||||
+4
-4
@@ -33,7 +33,7 @@ func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
|
|||||||
mfs, _ := r.mfRepo.FindByAlbum(id)
|
mfs, _ := r.mfRepo.FindByAlbum(id)
|
||||||
if len(mfs) > 0 {
|
if len(mfs) > 0 {
|
||||||
log.Debug(ctx, "Set Rating", "value", rating, "album", mfs[0].Album)
|
log.Debug(ctx, "Set Rating", "value", rating, "album", mfs[0].Album)
|
||||||
if err := r.itunes.SetAlbumRating(mfs[0].Id, rating); err != nil {
|
if err := r.itunes.SetAlbumRating(mfs[0].ID, rating); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ func (r ratings) SetRating(ctx context.Context, id string, rating int) error {
|
|||||||
}
|
}
|
||||||
if mf != nil {
|
if mf != nil {
|
||||||
log.Debug(ctx, "Set Rating", "value", rating, "song", mf.Title)
|
log.Debug(ctx, "Set Rating", "value", rating, "song", mf.Title)
|
||||||
if err := r.itunes.SetTrackRating(mf.Id, rating); err != nil {
|
if err := r.itunes.SetTrackRating(mf.ID, rating); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@@ -61,7 +61,7 @@ func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
|
|||||||
mfs, _ := r.mfRepo.FindByAlbum(id)
|
mfs, _ := r.mfRepo.FindByAlbum(id)
|
||||||
if len(mfs) > 0 {
|
if len(mfs) > 0 {
|
||||||
log.Debug(ctx, "Set Star", "value", star, "album", mfs[0].Album)
|
log.Debug(ctx, "Set Star", "value", star, "album", mfs[0].Album)
|
||||||
if err := r.itunes.SetAlbumLoved(mfs[0].Id, star); err != nil {
|
if err := r.itunes.SetAlbumLoved(mfs[0].ID, star); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ func (r ratings) SetStar(ctx context.Context, star bool, ids ...string) error {
|
|||||||
}
|
}
|
||||||
if mf != nil {
|
if mf != nil {
|
||||||
log.Debug(ctx, "Set Star", "value", star, "song", mf.Title)
|
log.Debug(ctx, "Set Star", "value", star, "song", mf.Title)
|
||||||
if err := r.itunes.SetTrackLoved(mf.Id, star); err != nil {
|
if err := r.itunes.SetTrackLoved(mf.ID, star); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
|
|||||||
+9
-9
@@ -38,14 +38,14 @@ func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId str
|
|||||||
return
|
return
|
||||||
case 1:
|
case 1:
|
||||||
np, _ := s.npRepo.Tail(playerId)
|
np, _ := s.npRepo.Tail(playerId)
|
||||||
if np.TrackId != trackId {
|
if np.TrackID != trackId {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.npRepo.Dequeue(playerId)
|
s.npRepo.Dequeue(playerId)
|
||||||
default:
|
default:
|
||||||
prev, _ := s.npRepo.Dequeue(playerId)
|
prev, _ := s.npRepo.Dequeue(playerId)
|
||||||
for {
|
for {
|
||||||
if prev.TrackId == trackId {
|
if prev.TrackID == trackId {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
np, err := s.npRepo.Dequeue(playerId)
|
np, err := s.npRepo.Dequeue(playerId)
|
||||||
@@ -54,15 +54,15 @@ func (s *scrobbler) detectSkipped(ctx context.Context, playerId int, trackId str
|
|||||||
}
|
}
|
||||||
diff := np.Start.Sub(prev.Start)
|
diff := np.Start.Sub(prev.Start)
|
||||||
if diff < minSkipped || diff > maxSkipped {
|
if diff < minSkipped || diff > maxSkipped {
|
||||||
log.Debug(ctx, fmt.Sprintf("-- Playtime for track %s was %v. Not skipping.", prev.TrackId, diff))
|
log.Debug(ctx, fmt.Sprintf("-- Playtime for track %s was %v. Not skipping.", prev.TrackID, diff))
|
||||||
prev = np
|
prev = np
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err = s.itunes.MarkAsSkipped(prev.TrackId, prev.Start.Add(1*time.Minute))
|
err = s.itunes.MarkAsSkipped(prev.TrackID, prev.Start.Add(1*time.Minute))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn(ctx, "Error skipping track", "id", prev.TrackId)
|
log.Warn(ctx, "Error skipping track", "id", prev.TrackID)
|
||||||
} else {
|
} else {
|
||||||
log.Debug(ctx, "-- Skipped track "+prev.TrackId)
|
log.Debug(ctx, "-- Skipped track "+prev.TrackID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ func (s *scrobbler) Register(ctx context.Context, playerId int, trackId string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mf == nil {
|
if mf == nil {
|
||||||
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
|
return nil, errors.New(fmt.Sprintf(`ID "%s" not found`, trackId))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.itunes.MarkAsPlayed(trackId, playTime); err != nil {
|
if err := s.itunes.MarkAsPlayed(trackId, playTime); err != nil {
|
||||||
@@ -93,9 +93,9 @@ func (s *scrobbler) NowPlaying(ctx context.Context, playerId int, playerName, tr
|
|||||||
}
|
}
|
||||||
|
|
||||||
if mf == nil {
|
if mf == nil {
|
||||||
return nil, errors.New(fmt.Sprintf(`Id "%s" not found`, trackId))
|
return nil, errors.New(fmt.Sprintf(`ID "%s" not found`, trackId))
|
||||||
}
|
}
|
||||||
|
|
||||||
info := &domain.NowPlayingInfo{TrackId: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
|
info := &domain.NowPlayingInfo{TrackID: trackId, Username: username, Start: time.Now(), PlayerId: playerId, PlayerName: playerName}
|
||||||
return mf, s.npRepo.Enqueue(info)
|
return mf, s.npRepo.Enqueue(info)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func TestScrobbler(t *testing.T) {
|
|||||||
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
|
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
|
||||||
|
|
||||||
Convey("Given a DB with one song", t, func() {
|
Convey("Given a DB with one song", t, func() {
|
||||||
mfRepo.SetData(`[{"Id":"2","Title":"Hands Of Time"}]`, 1)
|
mfRepo.SetData(`[{"ID":"2","Title":"Hands Of Time"}]`, 1)
|
||||||
|
|
||||||
Convey("When I scrobble an existing song", func() {
|
Convey("When I scrobble an existing song", func() {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
@@ -63,7 +63,7 @@ func TestScrobbler(t *testing.T) {
|
|||||||
|
|
||||||
Convey("And it saves the song as the one current playing", func() {
|
Convey("And it saves the song as the one current playing", func() {
|
||||||
info, _ := npRepo.Head(1)
|
info, _ := npRepo.Head(1)
|
||||||
So(info.TrackId, ShouldEqual, "2")
|
So(info.TrackID, ShouldEqual, "2")
|
||||||
// Commenting out time sensitive test, due to flakiness
|
// Commenting out time sensitive test, due to flakiness
|
||||||
// So(info.Start, ShouldHappenBefore, time.Now())
|
// So(info.Start, ShouldHappenBefore, time.Now())
|
||||||
So(info.Username, ShouldEqual, "deluan")
|
So(info.Username, ShouldEqual, "deluan")
|
||||||
@@ -95,7 +95,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
|
scrobbler := engine.NewScrobbler(itCtrl, mfRepo, npRepo)
|
||||||
|
|
||||||
Convey("Given a DB with three songs", t, func() {
|
Convey("Given a DB with three songs", t, func() {
|
||||||
mfRepo.SetData(`[{"Id":"1","Title":"Femme Fatale"},{"Id":"2","Title":"Here She Comes Now"},{"Id":"3","Title":"Lady Godiva's Operation"}]`, 3)
|
mfRepo.SetData(`[{"ID":"1","Title":"Femme Fatale"},{"ID":"2","Title":"Here She Comes Now"},{"ID":"3","Title":"Lady Godiva's Operation"}]`, 3)
|
||||||
itCtrl.skipped = make(map[string]time.Time)
|
itCtrl.skipped = make(map[string]time.Time)
|
||||||
npRepo.ClearAll()
|
npRepo.ClearAll()
|
||||||
Convey("When I skip 2 songs", func() {
|
Convey("When I skip 2 songs", func() {
|
||||||
@@ -109,7 +109,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
np, err := npRepo.GetAll()
|
np, err := npRepo.GetAll()
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(np, ShouldHaveLength, 1)
|
So(np, ShouldHaveLength, 1)
|
||||||
So(np[0].TrackId, ShouldEqual, "2")
|
So(np[0].TrackID, ShouldEqual, "2")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Convey("When I play one song", func() {
|
Convey("When I play one song", func() {
|
||||||
@@ -120,7 +120,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
|
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
|
||||||
Convey("Then the first song should be marked as skipped", func() {
|
Convey("Then the first song should be marked as skipped", func() {
|
||||||
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
|
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
|
||||||
So(mf.Id, ShouldEqual, "2")
|
So(mf.ID, ShouldEqual, "2")
|
||||||
So(itCtrl.skipped, ShouldContainKey, "1")
|
So(itCtrl.skipped, ShouldContainKey, "1")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
@@ -130,7 +130,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
|
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
|
||||||
Convey("Then the first song should be marked as skipped", func() {
|
Convey("Then the first song should be marked as skipped", func() {
|
||||||
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
|
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
|
||||||
So(mf.Id, ShouldEqual, "2")
|
So(mf.ID, ShouldEqual, "2")
|
||||||
So(itCtrl.skipped, ShouldBeEmpty)
|
So(itCtrl.skipped, ShouldBeEmpty)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
@@ -140,7 +140,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
|
scrobbler.NowPlaying(nil, 1, "DSub", "2", "deluan")
|
||||||
Convey("Then the first song should be marked as skipped", func() {
|
Convey("Then the first song should be marked as skipped", func() {
|
||||||
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
|
mf, err := scrobbler.Register(nil, 1, "2", aPointInTime.Add(3*time.Minute))
|
||||||
So(mf.Id, ShouldEqual, "2")
|
So(mf.ID, ShouldEqual, "2")
|
||||||
So(itCtrl.skipped, ShouldBeEmpty)
|
So(itCtrl.skipped, ShouldBeEmpty)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
@@ -148,7 +148,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
Convey("And I scrobble it before starting to play the other song", func() {
|
Convey("And I scrobble it before starting to play the other song", func() {
|
||||||
mf, err := scrobbler.Register(nil, 1, "1", time.Now())
|
mf, err := scrobbler.Register(nil, 1, "1", time.Now())
|
||||||
Convey("Then the first song should NOT marked as skipped", func() {
|
Convey("Then the first song should NOT marked as skipped", func() {
|
||||||
So(mf.Id, ShouldEqual, "1")
|
So(mf.ID, ShouldEqual, "1")
|
||||||
So(itCtrl.skipped, ShouldBeEmpty)
|
So(itCtrl.skipped, ShouldBeEmpty)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
})
|
})
|
||||||
@@ -163,7 +163,7 @@ func TestSkipping(t *testing.T) {
|
|||||||
Convey("Then the NowPlaying song should be the last one", func() {
|
Convey("Then the NowPlaying song should be the last one", func() {
|
||||||
np, _ := npRepo.GetAll()
|
np, _ := npRepo.GetAll()
|
||||||
So(np, ShouldHaveLength, 1)
|
So(np, ShouldHaveLength, 1)
|
||||||
So(np[0].TrackId, ShouldEqual, "2")
|
So(np[0].TrackID, ShouldEqual, "2")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
+4
-4
@@ -62,15 +62,15 @@ func (s *search) ClearAll() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *search) IndexArtist(ar *domain.Artist) error {
|
func (s *search) IndexArtist(ar *domain.Artist) error {
|
||||||
return s.idxArtist.Index(ar.Id, sanitize.Accents(strings.ToLower(ar.Name)))
|
return s.idxArtist.Index(ar.ID, sanitize.Accents(strings.ToLower(ar.Name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *search) IndexAlbum(al *domain.Album) error {
|
func (s *search) IndexAlbum(al *domain.Album) error {
|
||||||
return s.idxAlbum.Index(al.Id, sanitize.Accents(strings.ToLower(al.Name)))
|
return s.idxAlbum.Index(al.ID, sanitize.Accents(strings.ToLower(al.Name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *search) IndexMediaFile(mf *domain.MediaFile) error {
|
func (s *search) IndexMediaFile(mf *domain.MediaFile) error {
|
||||||
return s.idxSong.Index(mf.Id, sanitize.Accents(strings.ToLower(mf.Title)))
|
return s.idxSong.Index(mf.ID, sanitize.Accents(strings.ToLower(mf.Title)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *search) RemoveArtist(ids ...string) error {
|
func (s *search) RemoveArtist(ids ...string) error {
|
||||||
@@ -153,7 +153,7 @@ func criticalError(ctx context.Context, kind, id string, err error) bool {
|
|||||||
case err != nil:
|
case err != nil:
|
||||||
return true
|
return true
|
||||||
case err == domain.ErrNotFound:
|
case err == domain.ErrNotFound:
|
||||||
log.Warn(ctx, kind+"Id not in DB. Need a reindex?", "id", id)
|
log.Warn(ctx, kind+"ID not in DB. Need a reindex?", "id", id)
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,10 @@ func NewAlbumRepository() domain.AlbumRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *albumRepository) Put(m *domain.Album) error {
|
func (r *albumRepository) Put(m *domain.Album) error {
|
||||||
if m.Id == "" {
|
if m.ID == "" {
|
||||||
return errors.New("album Id is not set")
|
return errors.New("album ID is not set")
|
||||||
}
|
}
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.ID, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *albumRepository) Get(id string) (*domain.Album, error) {
|
func (r *albumRepository) Get(id string) (*domain.Album, error) {
|
||||||
@@ -60,7 +60,7 @@ func (r *albumRepository) GetAllIds() ([]string, error) {
|
|||||||
|
|
||||||
func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error) {
|
func (r *albumRepository) PurgeInactive(active domain.Albums) ([]string, error) {
|
||||||
return r.purgeInactive(active, func(e interface{}) string {
|
return r.purgeInactive(active, func(e interface{}) string {
|
||||||
return e.(domain.Album).Id
|
return e.(domain.Album).ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ func NewArtistRepository() domain.ArtistRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *artistRepository) Put(m *domain.Artist) error {
|
func (r *artistRepository) Put(m *domain.Artist) error {
|
||||||
if m.Id == "" {
|
if m.ID == "" {
|
||||||
return errors.New("artist Id is not set")
|
return errors.New("artist ID is not set")
|
||||||
}
|
}
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.ID, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *artistRepository) Get(id string) (*domain.Artist, error) {
|
func (r *artistRepository) Get(id string) (*domain.Artist, error) {
|
||||||
@@ -31,7 +31,7 @@ func (r *artistRepository) Get(id string) (*domain.Artist, error) {
|
|||||||
|
|
||||||
func (r *artistRepository) PurgeInactive(active domain.Artists) ([]string, error) {
|
func (r *artistRepository) PurgeInactive(active domain.Artists) ([]string, error) {
|
||||||
return r.purgeInactive(active, func(e interface{}) string {
|
return r.purgeInactive(active, func(e interface{}) string {
|
||||||
return e.(domain.Artist).Id
|
return e.(domain.Artist).ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (r *checkSumRepository) loadData() {
|
|||||||
|
|
||||||
func (r *checkSumRepository) Put(id, sum string) error {
|
func (r *checkSumRepository) Put(id, sum string) error {
|
||||||
if id == "" {
|
if id == "" {
|
||||||
return errors.New("Id is required")
|
return errors.New("ID is required")
|
||||||
}
|
}
|
||||||
_, err := Db().HSet(checkSumKeyName, []byte(id), []byte(sum))
|
_, err := Db().HSet(checkSumKeyName, []byte(id), []byte(sum))
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func NewArtistIndexRepository() domain.ArtistIndexRepository {
|
|||||||
|
|
||||||
func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
|
func (r *artistIndexRepository) Put(m *domain.ArtistIndex) error {
|
||||||
if m.Id == "" {
|
if m.Id == "" {
|
||||||
return errors.New("index Id is not set")
|
return errors.New("index ID is not set")
|
||||||
}
|
}
|
||||||
sort.Sort(m.Artists)
|
sort.Sort(m.Artists)
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.Id, m)
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func TestIndexRepository(t *testing.T) {
|
|||||||
|
|
||||||
So(s, shouldBeEqual, i)
|
So(s, shouldBeEqual, i)
|
||||||
})
|
})
|
||||||
Convey("It should be able to check for existence of an Id", func() {
|
Convey("It should be able to check for existence of an ID", func() {
|
||||||
i := &domain.ArtistIndex{Id: "123"}
|
i := &domain.ArtistIndex{Id: "123"}
|
||||||
|
|
||||||
repo.Put(i)
|
repo.Put(i)
|
||||||
@@ -35,7 +35,7 @@ func TestIndexRepository(t *testing.T) {
|
|||||||
s, _ = repo.Exists("NOT_FOUND")
|
s, _ = repo.Exists("NOT_FOUND")
|
||||||
So(s, ShouldBeFalse)
|
So(s, ShouldBeFalse)
|
||||||
})
|
})
|
||||||
Convey("Method Put() should return error if Id is not set", func() {
|
Convey("Method Put() should return error if ID is not set", func() {
|
||||||
i := &domain.ArtistIndex{}
|
i := &domain.ArtistIndex{}
|
||||||
|
|
||||||
err := repo.Put(i)
|
err := repo.Put(i)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func TestBaseRepository(t *testing.T) {
|
|||||||
|
|
||||||
Convey("When I call NewId with a name", func() {
|
Convey("When I call NewId with a name", func() {
|
||||||
Id := repo.newId("a name")
|
Id := repo.newId("a name")
|
||||||
Convey("Then it should return a new Id", func() {
|
Convey("Then it should return a new ID", func() {
|
||||||
So(Id, ShouldNotBeEmpty)
|
So(Id, ShouldNotBeEmpty)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -100,7 +100,7 @@ func TestBaseRepository(t *testing.T) {
|
|||||||
FirstId := repo.newId("a name")
|
FirstId := repo.newId("a name")
|
||||||
SecondId := repo.newId("a name")
|
SecondId := repo.newId("a name")
|
||||||
|
|
||||||
Convey("Then it should return the same Id each time", func() {
|
Convey("Then it should return the same ID each time", func() {
|
||||||
So(FirstId, ShouldEqual, SecondId)
|
So(FirstId, ShouldEqual, SecondId)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ func TestBaseRepository(t *testing.T) {
|
|||||||
entity := &TestEntity{Id: "111", Name: "One Name", ParentId: "AAA"}
|
entity := &TestEntity{Id: "111", Name: "One Name", ParentId: "AAA"}
|
||||||
repo.saveOrUpdate(entity.Id, entity)
|
repo.saveOrUpdate(entity.Id, entity)
|
||||||
|
|
||||||
Convey("When I save an entity with a different Id", func() {
|
Convey("When I save an entity with a different ID", func() {
|
||||||
newEntity := &TestEntity{Id: "222", Name: "Another Name", ParentId: "AAA"}
|
newEntity := &TestEntity{Id: "222", Name: "Another Name", ParentId: "AAA"}
|
||||||
repo.saveOrUpdate(newEntity.Id, newEntity)
|
repo.saveOrUpdate(newEntity.Id, newEntity)
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ func TestBaseRepository(t *testing.T) {
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("When I save an entity with the same Id", func() {
|
Convey("When I save an entity with the same ID", func() {
|
||||||
newEntity := &TestEntity{Id: "111", Name: "New Name", ParentId: "AAA"}
|
newEntity := &TestEntity{Id: "111", Name: "New Name", ParentId: "AAA"}
|
||||||
repo.saveOrUpdate(newEntity.Id, newEntity)
|
repo.saveOrUpdate(newEntity.Id, newEntity)
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ func NewMediaFileRepository() domain.MediaFileRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *mediaFileRepository) Put(m *domain.MediaFile) error {
|
func (r *mediaFileRepository) Put(m *domain.MediaFile) error {
|
||||||
if m.Id == "" {
|
if m.ID == "" {
|
||||||
return errors.New("mediaFile Id is not set")
|
return errors.New("mediaFile ID is not set")
|
||||||
}
|
}
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.ID, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
||||||
@@ -31,7 +31,7 @@ func (r *mediaFileRepository) Get(id string) (*domain.MediaFile, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
mf := m.(*domain.MediaFile)
|
mf := m.(*domain.MediaFile)
|
||||||
if mf.Id != id {
|
if mf.ID != id {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
return mf, nil
|
return mf, nil
|
||||||
@@ -69,7 +69,7 @@ func (r *mediaFileRepository) GetAllIds() ([]string, error) {
|
|||||||
|
|
||||||
func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) ([]string, error) {
|
func (r *mediaFileRepository) PurgeInactive(active domain.MediaFiles) ([]string, error) {
|
||||||
return r.purgeInactive(active, func(e interface{}) string {
|
return r.purgeInactive(active, func(e interface{}) string {
|
||||||
return e.(domain.MediaFile).Id
|
return e.(domain.MediaFile).ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func NewMediaFolderRepository() domain.MediaFolderRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (*mediaFolderRepository) GetAll() (domain.MediaFolders, error) {
|
func (*mediaFolderRepository) GetAll() (domain.MediaFolders, error) {
|
||||||
mediaFolder := domain.MediaFolder{Id: "0", Name: "iTunes Library", Path: conf.Sonic.MusicFolder}
|
mediaFolder := domain.MediaFolder{ID: "0", Name: "iTunes Library", Path: conf.Sonic.MusicFolder}
|
||||||
result := make(domain.MediaFolders, 1)
|
result := make(domain.MediaFolders, 1)
|
||||||
result[0] = mediaFolder
|
result[0] = mediaFolder
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|||||||
@@ -17,10 +17,10 @@ func NewPlaylistRepository() domain.PlaylistRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *playlistRepository) Put(m *domain.Playlist) error {
|
func (r *playlistRepository) Put(m *domain.Playlist) error {
|
||||||
if m.Id == "" {
|
if m.ID == "" {
|
||||||
return errors.New("playlist Id is not set")
|
return errors.New("playlist ID is not set")
|
||||||
}
|
}
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.ID, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
|
func (r *playlistRepository) Get(id string) (*domain.Playlist, error) {
|
||||||
@@ -41,7 +41,7 @@ func (r *playlistRepository) GetAll(options domain.QueryOptions) (domain.Playlis
|
|||||||
|
|
||||||
func (r *playlistRepository) PurgeInactive(active domain.Playlists) ([]string, error) {
|
func (r *playlistRepository) PurgeInactive(active domain.Playlists) ([]string, error) {
|
||||||
return r.purgeInactive(active, func(e interface{}) string {
|
return r.purgeInactive(active, func(e interface{}) string {
|
||||||
return e.(domain.Playlist).Id
|
return e.(domain.Playlist).ID
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ func NewPropertyRepository() domain.PropertyRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *propertyRepository) Put(id string, value string) error {
|
func (r *propertyRepository) Put(id string, value string) error {
|
||||||
m := &domain.Property{Id: id, Value: value}
|
m := &domain.Property{ID: id, Value: value}
|
||||||
if m.Id == "" {
|
if m.ID == "" {
|
||||||
return errors.New("Id is required")
|
return errors.New("ID is required")
|
||||||
}
|
}
|
||||||
return r.saveOrUpdate(m.Id, m)
|
return r.saveOrUpdate(m.ID, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *propertyRepository) Get(id string) (string, error) {
|
func (r *propertyRepository) Get(id string) (string, error) {
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func (m *MockAlbum) SetData(j string, size int) {
|
|||||||
fmt.Println("ERROR: ", err)
|
fmt.Println("ERROR: ", err)
|
||||||
}
|
}
|
||||||
for _, a := range m.all {
|
for _, a := range m.all {
|
||||||
m.data[a.Id] = &a
|
m.data[a.ID] = &a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ func (m *MockAlbum) FindByArtist(artistId string) (domain.Albums, error) {
|
|||||||
var res = make(domain.Albums, len(m.data))
|
var res = make(domain.Albums, len(m.data))
|
||||||
i := 0
|
i := 0
|
||||||
for _, a := range m.data {
|
for _, a := range m.data {
|
||||||
if a.ArtistId == artistId {
|
if a.ArtistID == artistId {
|
||||||
res[i] = *a
|
res[i] = *a
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (m *MockArtist) SetData(j string, size int) {
|
|||||||
fmt.Println("ERROR: ", err)
|
fmt.Println("ERROR: ", err)
|
||||||
}
|
}
|
||||||
for _, a := range l {
|
for _, a := range l {
|
||||||
m.data[a.Id] = &a
|
m.data[a.ID] = &a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (m *MockMediaFile) SetData(j string, size int) {
|
|||||||
fmt.Println("ERROR: ", err)
|
fmt.Println("ERROR: ", err)
|
||||||
}
|
}
|
||||||
for _, a := range l {
|
for _, a := range l {
|
||||||
m.data[a.Id] = a
|
m.data[a.ID] = a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ func (m *MockMediaFile) FindByAlbum(artistId string) (domain.MediaFiles, error)
|
|||||||
var res = make(domain.MediaFiles, len(m.data))
|
var res = make(domain.MediaFiles, len(m.data))
|
||||||
i := 0
|
i := 0
|
||||||
for _, a := range m.data {
|
for _, a := range m.data {
|
||||||
if a.AlbumId == artistId {
|
if a.AlbumID == artistId {
|
||||||
res[i] = a
|
res[i] = a
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -184,7 +184,7 @@ func (i *Importer) importMediaFiles() (domain.MediaFiles, int) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if mf.Starred {
|
if mf.Starred {
|
||||||
original, err := i.mfRepo.Get(mf.Id)
|
original, err := i.mfRepo.Get(mf.ID)
|
||||||
if err != nil || !original.Starred {
|
if err != nil || !original.Starred {
|
||||||
mf.StarredAt = mf.UpdatedAt
|
mf.StarredAt = mf.UpdatedAt
|
||||||
} else {
|
} else {
|
||||||
@@ -216,7 +216,7 @@ func (i *Importer) importAlbums() (domain.Albums, int) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if al.Starred {
|
if al.Starred {
|
||||||
original, err := i.albumRepo.Get(al.Id)
|
original, err := i.albumRepo.Get(al.ID)
|
||||||
if err != nil || !original.Starred {
|
if err != nil || !original.Starred {
|
||||||
al.StarredAt = al.UpdatedAt
|
al.StarredAt = al.UpdatedAt
|
||||||
} else {
|
} else {
|
||||||
@@ -294,7 +294,7 @@ func (i *Importer) collectIndex(ig utils.IndexGroups, a *domain.Artist, artistIn
|
|||||||
artists = make(tempIndex)
|
artists = make(tempIndex)
|
||||||
artistIndex[group] = artists
|
artistIndex[group] = artists
|
||||||
}
|
}
|
||||||
artists[indexName] = domain.ArtistInfo{ArtistId: a.Id, Artist: a.Name, AlbumCount: a.AlbumCount}
|
artists[indexName] = domain.ArtistInfo{ArtistID: a.ID, Artist: a.Name, AlbumCount: a.AlbumCount}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Importer) findGroup(ig utils.IndexGroups, name string) string {
|
func (i *Importer) findGroup(ig utils.IndexGroups, name string) string {
|
||||||
|
|||||||
+15
-15
@@ -77,11 +77,11 @@ func (s *ItunesScanner) ScanLibrary(lastModifiedSince time.Time, path string) (i
|
|||||||
mf := s.collectMediaFiles(&t)
|
mf := s.collectMediaFiles(&t)
|
||||||
s.collectAlbums(&t, mf, ar)
|
s.collectAlbums(&t, mf, ar)
|
||||||
|
|
||||||
songsPerAlbum[mf.AlbumId]++
|
songsPerAlbum[mf.AlbumID]++
|
||||||
if albumsPerArtist[mf.ArtistId] == nil {
|
if albumsPerArtist[mf.ArtistID] == nil {
|
||||||
albumsPerArtist[mf.ArtistId] = make(map[string]bool)
|
albumsPerArtist[mf.ArtistID] = make(map[string]bool)
|
||||||
}
|
}
|
||||||
albumsPerArtist[mf.ArtistId][mf.AlbumId] = true
|
albumsPerArtist[mf.ArtistID][mf.AlbumID] = true
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
if i%1000 == 0 {
|
if i%1000 == 0 {
|
||||||
@@ -174,18 +174,18 @@ func (s *ItunesScanner) skipPlaylist(p *itl.Playlist, ignFolders bool, ignPatter
|
|||||||
|
|
||||||
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist, fullPath string) {
|
func (s *ItunesScanner) collectPlaylists(p *itl.Playlist, fullPath string) {
|
||||||
pl := &domain.Playlist{}
|
pl := &domain.Playlist{}
|
||||||
pl.Id = p.PlaylistPersistentID
|
pl.ID = p.PlaylistPersistentID
|
||||||
pl.Name = unescape(p.Name)
|
pl.Name = unescape(p.Name)
|
||||||
pl.FullPath = fullPath
|
pl.FullPath = fullPath
|
||||||
pl.Tracks = make([]string, 0, len(p.PlaylistItems))
|
pl.Tracks = make([]string, 0, len(p.PlaylistItems))
|
||||||
for _, item := range p.PlaylistItems {
|
for _, item := range p.PlaylistItems {
|
||||||
if mf, found := s.pmediaFiles[item.TrackID]; found {
|
if mf, found := s.pmediaFiles[item.TrackID]; found {
|
||||||
pl.Tracks = append(pl.Tracks, mf.Id)
|
pl.Tracks = append(pl.Tracks, mf.ID)
|
||||||
pl.Duration += mf.Duration
|
pl.Duration += mf.Duration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(pl.Tracks) > 0 {
|
if len(pl.Tracks) > 0 {
|
||||||
s.playlists[pl.Id] = pl
|
s.playlists[pl.ID] = pl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,10 +233,10 @@ func (s *ItunesScanner) calcCheckSum(t *itl.Track) string {
|
|||||||
|
|
||||||
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
||||||
mf := &domain.MediaFile{}
|
mf := &domain.MediaFile{}
|
||||||
mf.Id = t.PersistentID
|
mf.ID = t.PersistentID
|
||||||
mf.Album = unescape(t.Album)
|
mf.Album = unescape(t.Album)
|
||||||
mf.AlbumId = albumId(t)
|
mf.AlbumID = albumId(t)
|
||||||
mf.ArtistId = artistId(t)
|
mf.ArtistID = artistId(t)
|
||||||
mf.Title = unescape(t.Name)
|
mf.Title = unescape(t.Name)
|
||||||
mf.Artist = unescape(t.Artist)
|
mf.Artist = unescape(t.Artist)
|
||||||
if mf.Album == "" {
|
if mf.Album == "" {
|
||||||
@@ -274,7 +274,7 @@ func (s *ItunesScanner) collectMediaFiles(t *itl.Track) *domain.MediaFile {
|
|||||||
mf.HasCoverArt = hasCoverArt(path)
|
mf.HasCoverArt = hasCoverArt(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.mediaFiles[mf.Id] = mf
|
s.mediaFiles[mf.ID] = mf
|
||||||
s.pmediaFiles[t.TrackID] = mf
|
s.pmediaFiles[t.TrackID] = mf
|
||||||
|
|
||||||
return mf
|
return mf
|
||||||
@@ -288,8 +288,8 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
|
|||||||
}
|
}
|
||||||
|
|
||||||
al := s.albums[id]
|
al := s.albums[id]
|
||||||
al.Id = id
|
al.ID = id
|
||||||
al.ArtistId = ar.Id
|
al.ArtistID = ar.ID
|
||||||
al.Name = mf.Album
|
al.Name = mf.Album
|
||||||
al.Year = t.Year
|
al.Year = t.Year
|
||||||
al.Compilation = t.Compilation
|
al.Compilation = t.Compilation
|
||||||
@@ -308,7 +308,7 @@ func (s *ItunesScanner) collectAlbums(t *itl.Track, mf *domain.MediaFile, ar *do
|
|||||||
al.Duration += mf.Duration
|
al.Duration += mf.Duration
|
||||||
|
|
||||||
if mf.HasCoverArt {
|
if mf.HasCoverArt {
|
||||||
al.CoverArtId = mf.Id
|
al.CoverArtId = mf.ID
|
||||||
al.CoverArtPath = mf.Path
|
al.CoverArtPath = mf.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ func (s *ItunesScanner) collectArtists(t *itl.Track) *domain.Artist {
|
|||||||
s.artists[id] = &domain.Artist{}
|
s.artists[id] = &domain.Artist{}
|
||||||
}
|
}
|
||||||
ar := s.artists[id]
|
ar := s.artists[id]
|
||||||
ar.Id = id
|
ar.ID = id
|
||||||
ar.Name = unescape(realArtistName(t))
|
ar.Name = unescape(realArtistName(t))
|
||||||
if ar.Name == "" {
|
if ar.Name == "" {
|
||||||
ar.Name = "[Unknown Artist]"
|
ar.Name = "[Unknown Artist]"
|
||||||
|
|||||||
Reference in New Issue
Block a user