Skip to content

Commit

Permalink
Merge pull request #171 from kenellorando/populator-fix
Browse files Browse the repository at this point in the history
Loop all given file extensions
  • Loading branch information
kenellorando authored Jan 23, 2020
2 parents 6835724 + 8612352 commit 8cffc6e
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions server/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,39 +136,38 @@ func databasePopulate() error {
}

// Skip non-music files
var extensions = [...]string{".mp3", ".ogg", ".flac"}
var extensions = [...]string{".mp3", ".ogg", ".flac", ".m4a"}
for _, ext := range extensions {
if strings.HasSuffix(path, ext) {
break
// Open a file for reading
file, e := os.Open(path)
if e != nil {
return e
}

// Read metadata from the file
tags, er := tag.ReadFrom(file)
if er != nil {
return er
}

// Insert into database
_, err = database.Exec(insertInto, tags.Title(), tags.Album(), tags.Artist(),
tags.Genre(), tags.Year(), path)
if err != nil {
panic(err)
}

// Add song (as LibraryEntry) to full libraryData
libraryData = append(libraryData, LibraryEntry{Artist: tags.Artist(), Title: tags.Title()})

// Close the file
file.Close()
return nil
} else {
return nil
}
}

// Open a file for reading
file, e := os.Open(path)
if e != nil {
return e
}

// Read metadata from the file
tags, er := tag.ReadFrom(file)
if er != nil {
return er
}

// Insert into database
_, err = database.Exec(insertInto, tags.Title(), tags.Album(), tags.Artist(),
tags.Genre(), tags.Year(), path)
if err != nil {
panic(err)
}

// Add song (as LibraryEntry) to full libraryData
libraryData = append(libraryData, LibraryEntry{Artist: tags.Artist(), Title: tags.Title()})

// Close the file
file.Close()
return nil
})

Expand Down

0 comments on commit 8cffc6e

Please sign in to comment.