Invert dependency of metadata and extractors
This commit is contained in:
@@ -6,14 +6,15 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/navidrome/navidrome/log"
|
||||
"github.com/navidrome/navidrome/scanner/metadata"
|
||||
)
|
||||
|
||||
type Parser struct{}
|
||||
const ExtractorID = "taglib"
|
||||
|
||||
type parsedTags = map[string][]string
|
||||
type Extractor struct{}
|
||||
|
||||
func (e *Parser) Parse(paths ...string) (map[string]parsedTags, error) {
|
||||
fileTags := map[string]parsedTags{}
|
||||
func (e *Extractor) Parse(paths ...string) (map[string]metadata.ParsedTags, error) {
|
||||
fileTags := map[string]metadata.ParsedTags{}
|
||||
for _, path := range paths {
|
||||
tags, err := e.extractMetadata(path)
|
||||
if !errors.Is(err, os.ErrPermission) {
|
||||
@@ -23,7 +24,7 @@ func (e *Parser) Parse(paths ...string) (map[string]parsedTags, error) {
|
||||
return fileTags, nil
|
||||
}
|
||||
|
||||
func (e *Parser) extractMetadata(filePath string) (parsedTags, error) {
|
||||
func (e *Extractor) extractMetadata(filePath string) (metadata.ParsedTags, error) {
|
||||
tags, err := Read(filePath)
|
||||
if err != nil {
|
||||
log.Warn("TagLib: Error reading metadata from file. Skipping", "filePath", filePath, err)
|
||||
@@ -53,3 +54,7 @@ func (e *Parser) extractMetadata(filePath string) (parsedTags, error) {
|
||||
}
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
metadata.RegisterExtractor(ExtractorID, &Extractor{})
|
||||
}
|
||||
|
||||
@@ -8,13 +8,13 @@ import (
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Parser", func() {
|
||||
var e *Parser
|
||||
var _ = Describe("Extractor", func() {
|
||||
var e *Extractor
|
||||
// This file will have 0222 (no read) permission during these tests
|
||||
var accessForbiddenFile = "tests/fixtures/test_no_read_permission.ogg"
|
||||
|
||||
BeforeEach(func() {
|
||||
e = &Parser{}
|
||||
e = &Extractor{}
|
||||
|
||||
err := os.Chmod(accessForbiddenFile, 0222)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
Reference in New Issue
Block a user