Fix non-folder folder empty parent ids

fixes #134
introduced by 711ffe144f

id          updated_at                           modified_at                          left_path   right_path  right_path_u_dec  parent_id   cover       tag_artist_id  tag_title   tag_title_u_dec  tag_brainz_id  tag_year
----------  -----------------------------------  -----------------------------------  ----------  ----------  ----------------  ----------  ----------  -------------  ----------  ---------------  -------------  ----------
1           2021-04-20 22:04:31.437318349+01:00  2021-04-20 21:35:55.423563144+01:00              .
2           2021-04-20 22:04:31.437920005+01:00  2021-04-20 21:35:50.766896425+01:00              luke
3           2021-04-20 22:04:31.475871668+01:00  2021-04-20 21:35:11.526895985+01:00  luke/       (2003) Yos                    2           folder.jpe  1              YosepH                       cf497d42-736a  2003
4           2021-04-20 22:04:31.476325505+01:00  2021-04-20 21:35:55.423563144+01:00              beng
5           2021-04-20 22:04:31.511647498+01:00  2021-04-20 21:35:27.060229492+01:00  beng/       (2013) Cha                    4           folder.jpg  2              Chapter II                   bcafa993-f065  2013

->

id          updated_at                           modified_at                          left_path   right_path  right_path_u_dec  parent_id   cover       tag_artist_id  tag_title   tag_title_u_dec  tag_brainz_id  tag_year
----------  -----------------------------------  -----------------------------------  ----------  ----------  ----------------  ----------  ----------  -------------  ----------  ---------------  -------------  ----------
1           2021-04-20 22:22:55.368005558+01:00  2021-04-20 21:35:55.423563144+01:00              .                                                                                                                0
2           2021-04-20 22:22:55.331985959+01:00  2021-04-20 21:35:50.766896425+01:00              luke                          1                                                                                  0
3           2021-04-20 22:22:55.33148277+01:00   2021-04-20 21:35:11.526895985+01:00  luke/       (2003) Yos                    2           folder.jpe  1              YosepH                       cf497d42-736a  2003
4           2021-04-20 22:22:55.367693081+01:00  2021-04-20 21:35:55.423563144+01:00              beng                          1                                                                                  0
5           2021-04-20 22:22:55.36711045+01:00   2021-04-20 21:35:27.060229492+01:00  beng/       (2013) Cha                    4           folder.jpg  2              Chapter II                   bcafa993-f065  2013
This commit is contained in:
sentriz
2021-04-20 22:25:12 +01:00
parent e206dd25db
commit 61e11471b3
2 changed files with 4 additions and 6 deletions

View File

@@ -195,9 +195,8 @@ type Album struct {
TagBrainzID string `sql:"default: null"`
TagYear int `sql:"default: null"`
Tracks []*Track
ChildCount int `sql:"-"`
Duration int `sql:"-"`
ShouldSave bool `sql:"-"`
ChildCount int `sql:"-"`
Duration int `sql:"-"`
}
func (a *Album) SID() *specid.ID {

View File

@@ -324,7 +324,7 @@ func (s *Scanner) callbackPost(fullPath string, info *godirwalk.Dirent) error {
// begin taking the current folder off the stack and add it's
// parent, cover that we found, etc.
folder := s.curFolders.Pop()
if !folder.ShouldSave {
if folder.ParentID != 0 {
return nil
}
folder.ParentID = s.curFolders.PeekID()
@@ -477,7 +477,7 @@ func (s *Scanner) handleTrack(it *item) error {
// ** begin set album if this is the first track in the folder
folder := s.curFolders.Peek()
if folder.ShouldSave {
if folder.TagTitle != "" {
return nil
}
err = s.trTx.
@@ -501,7 +501,6 @@ func (s *Scanner) handleTrack(it *item) error {
folder.TagBrainzID = trTags.AlbumBrainzID()
folder.TagYear = trTags.Year()
folder.TagArtistID = artist.ID
folder.ShouldSave = true
return nil
}