Refactor getAlbum

This commit is contained in:
Deluan
2020-08-13 18:50:28 -04:00
committed by Deluan Quintão
parent e344f616b3
commit 15c8f4c0ef
2 changed files with 40 additions and 21 deletions
+12 -1
View File
@@ -187,7 +187,7 @@ func ChildFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
child.CoverArt = "al-" + mf.AlbumID
}
child.ContentType = mf.ContentType()
child.Path = mf.Path
child.Path = fmt.Sprintf("%s/%s/%s.%s", realArtistName(mf), mf.Album, mf.Title, mf.Suffix)
child.DiscNumber = mf.DiscNumber
child.Created = &mf.CreatedAt
child.AlbumId = mf.AlbumID
@@ -208,6 +208,17 @@ func ChildFromMediaFile(ctx context.Context, mf model.MediaFile) responses.Child
return child
}
func realArtistName(mf model.MediaFile) string {
switch {
case mf.Compilation:
return consts.VariousArtists
case mf.AlbumArtist != "":
return mf.AlbumArtist
}
return mf.Artist
}
func ChildrenFromMediaFiles(ctx context.Context, mfs model.MediaFiles) []responses.Child {
children := make([]responses.Child, len(mfs))
for i, mf := range mfs {