add browse by folder to scanner
This commit is contained in:
72
TODO
Normal file
72
TODO
Normal file
@@ -0,0 +1,72 @@
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/A Certain Ratio`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/A Certain Ratio/(1994) The Graveyard and the Ballroom`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/A Certain Ratio/(1994) The Graveyard and the Ballroom`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/A Certain Ratio/(1981) To Each.`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/A Certain Ratio/(1981) To Each.`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/A Certain Ratio`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/13th Floor Elevators`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/13th Floor Elevators/(1966) The Psychedelic Sounds of the 13th Floor Elevators`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/13th Floor Elevators/(1966) The Psychedelic Sounds of the 13th Floor Elevators`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/13th Floor Elevators/(1967) Easter Everywhere`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/13th Floor Elevators/(1967) Easter Everywhere`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/13th Floor Elevators`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/Anika`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/Anika/Hello`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/Anika/Hello/There`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/Anika/Hello/There/(2010) Anika`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/Hello/There/(2010) Anika`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/Hello/There`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/Hello`
|
||||
2019/05/07 14:34:55 entering folder `/home/senan/music/Anika/No Music Here`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/No Music Here`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music`
|
||||
2019/05/07 14:34:55 scanned in 364.785µs
|
||||
2019/05/07 14:34:55 cleaned in 106.441µs
|
||||
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/A Certain Ratio/(1994) The Graveyard and the Ballroom`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/A Certain Ratio/(1981) To Each.`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/A Certain Ratio`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/13th Floor Elevators/(1966) The Psychedelic Sounds of the 13th Floor Elevators`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/13th Floor Elevators/(1967) Easter Everywhere`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/13th Floor Elevators`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/Hello/There/(2010) Anika`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/Hello/There`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/Hello`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika/No Music Here`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music/Anika`
|
||||
2019/05/07 14:34:55 ___ processed folder `/home/senan/music`
|
||||
2019/05/07 14:34:55 scanned in 364.785µs
|
||||
2019/05/07 14:34:55 cleaned in 106.441µs
|
||||
|
||||
// handleFolder is for browse by folders, while handleTrack is for both
|
||||
func handleFolder(fullPath string, stat os.FileInfo) error {
|
||||
log.Printf("entering folder `%s`", fullPath)
|
||||
return nil
|
||||
// this must be run before any tracks so that seenDirs is
|
||||
// correct for the coming tracks
|
||||
modTime := stat.ModTime()
|
||||
folder := db.Folder{
|
||||
Path: fullPath,
|
||||
}
|
||||
// skip if the record exists and hasn't been modified since
|
||||
// the last scan
|
||||
err := tx.Where(folder).First(&folder).Error
|
||||
if !gorm.IsRecordNotFoundError(err) &&
|
||||
modTime.Before(folder.UpdatedAt) {
|
||||
// even though we don't want to update this record,
|
||||
// add it to seenDirs now that we have the id
|
||||
seenDirs.Push(folder.ID)
|
||||
return nil
|
||||
}
|
||||
_, folderName := path.Split(fullPath)
|
||||
folder.ParentID = seenDirs.Peek()
|
||||
folder.Name = folderName
|
||||
// save the record with new parent id, then add the new
|
||||
// current id to seenDirs
|
||||
tx.Save(&folder)
|
||||
seenDirs.Push(folder.ID)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user