dhowden / tag

ID3, MP4 and OGG/FLAC metadata parsing in Go
BSD 2-Clause "Simplified" License
558 stars 72 forks source link

Merge multiple Vorbis (and FLAC) tags #60

Open pgalbavy opened 4 years ago

pgalbavy commented 4 years ago

Another small patch, but needs thought:

diff --git a/vorbis.go b/vorbis.go
index c250615..bf8fc96 100644
--- a/vorbis.go
+++ b/vorbis.go
@@ -64,7 +64,11 @@ func (m *metadataVorbis) readVorbisComment(r io.Reader) error {
                if err != nil {
                        return err
                }
-               m.c[strings.ToLower(k)] = v
+               if _, ok := m.c[strings.ToLower(k)]; ok {
+                       m.c[strings.ToLower(k)] = m.c[strings.ToLower(k)] + "\\" + "\\" + v
+               } else {
+                       m.c[strings.ToLower(k)] = v
+               }
        }
        return nil
 }

The convention in many editors and players is two literal backslahes as value separators, but I would also propose being able to pass this down into ReadFrom() perhaps? mediainfo uses " / "

(I know my golang may not be perfectly clean, just learning it coming from C and perl)

Before:

 $ ./tag -raw  '/media/sda/Music/Compilations/Latin Fever/Disc 1 - 01 - Ricky Martin - Livin'\'' La Vida Loca (Pablo Flores English Radio Edit).flac'
Metadata Format: VORBIS
File Type: FLAC
 Title: Livin' La Visa Loca (Pablo Flores English radio edit)
 Album: Latin Fever
 Artist: Ricky Martin
 Composer: Desmond Child
 Genre: Latin
 Year: 2000
 Track: 1 of 19
 Disc: 1 of 2
 Picture: Picture{Ext: jpg, MIMEType: image/jpeg, Type: Cover (front), Description: , Data.Size: 27688}
 Lyrics:
 Comment:

[...]
"style": "Latin Pop"
"composer": "Desmond Child"
...

After:

$ ./tag -raw  '/media/sda/Music/Compilations/Latin Fever/Disc 1 - 01 - Ricky Martin - Livin'\'' La Vida Loca (Pablo Flores English Radio Edit).flac'
Metadata Format: VORBIS
File Type: FLAC
 Title: Livin' La Visa Loca (Pablo Flores English radio edit)
 Album: Latin Fever
 Artist: Ricky Martin
 Composer: Robi Rosa\Desmond Child
 Genre: Latin
 Year: 2000
 Track: 1 of 19
 Disc: 1 of 2
 Picture: Picture{Ext: jpg, MIMEType: image/jpeg, Type: Cover (front), Description: , Data.Size: 27688}
 Lyrics:
 Comment:

[...]
"composer": "Robi Rosa\\Desmond Child"
"style": "Urban\\Early Pop/Rock\\Mambo\\Salsa\\Latin Dance\\Adult Contemporary\\Club/Dance\\Dance-Pop\\Tropical\\Latin Pop"

file-trimmed.zip

bertvandepoel commented 2 years ago

Have you considered making this into a PR? It seems sensible, but I guess it has gotten stalled inside this issue. A PR may revive all of this.