Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use file name / foder name for unknown tag retrieval. #541

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mockfs/mockfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ func (i *TagInfo) ReplayGainAlbumPeak() float32 { return 0 }
func (i *TagInfo) Length() int { return firstInt(100, i.RawLength) }
func (i *TagInfo) Bitrate() int { return firstInt(100, i.RawBitrate) }

func (i *TagInfo) AbsPath() string { return "" }

var _ tagcommon.Reader = (*tagReader)(nil)

func firstInt(or int, ints ...int) int {
Expand Down
5 changes: 3 additions & 2 deletions scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,9 @@ func populateTrack(tx *db.DB, album *db.Album, track *db.Track, trags tagcommon.
track.Size = size
track.AlbumID = album.ID

track.TagTitle = trags.Title()
track.TagTitleUDec = decoded(trags.Title())
tagTitle := tagcommon.MustTitle(trags)
track.TagTitle = tagTitle
track.TagTitleUDec = decoded(tagTitle)
track.TagTrackArtist = tagcommon.MustArtist(trags)
track.TagTrackNumber = trags.TrackNumber()
track.TagDiscNumber = trags.DiscNumber()
Expand Down
17 changes: 15 additions & 2 deletions tags/tagcommon/tagcommmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tagcommon

import (
"errors"
"path"
)

var ErrUnsupported = errors.New("filetype unsupported")
Expand Down Expand Up @@ -33,19 +34,31 @@ type Info interface {

Length() int
Bitrate() int

AbsPath() string
}

const (
FallbackAlbum = "Unknown Album"
FallbackArtist = "Unknown Artist"
FallbackGenre = "Unknown Genre"
)

func MustTitle(p Info) string {
if r := p.Title(); r != "" {
return r
}

// return the file name for title name
return path.Base(p.AbsPath())
}

func MustAlbum(p Info) string {
if r := p.Album(); r != "" {
return r
}
return FallbackAlbum

// return the dir name for album name
return path.Base(path.Dir(p.AbsPath()))
}

func MustArtist(p Info) string {
Expand Down
9 changes: 6 additions & 3 deletions tags/taglib/taglib.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ func (TagLib) Read(absPath string) (tagcommon.Info, error) {
defer f.Close()
props := f.ReadAudioProperties()
raw := f.ReadTags()
return &info{raw, props}, nil
return &info{raw, props, absPath}, nil
}

type info struct {
raw map[string][]string
props *audiotags.AudioProperties
raw map[string][]string
props *audiotags.AudioProperties
abspath string
}

// https://picard-docs.musicbrainz.org/downloads/MusicBrainz_Picard_Tag_Map.html
Expand All @@ -60,6 +61,8 @@ func (i *info) ReplayGainAlbumPeak() float32 { return flt(first(find(i.raw, "rep
func (i *info) Length() int { return i.props.Length }
func (i *info) Bitrate() int { return i.props.Bitrate }

func (i *info) AbsPath() string { return i.abspath }

func first[T comparable](is []T) T {
var z T
for _, i := range is {
Expand Down
Loading