Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: FLAC files show duplicate tag (Read 15119 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

FLAC files show duplicate tag

Using metaflac command, "metaflac --show-all-tags".  There is a tag that is listed twice.  Also, only one of the tags has a value.  This seems to be the case for all of my flac files.  I ripped these with dBpoweramp and this was defined as a "custom" tag.
I can do the same command using exiftool, "exiftool --tag-all" and I only see the single tag, the one that has a value is the one listed.
Does anyone know why it might be listed twice using metaflac.  I thought metaflac would be the better tool since it is the "official" tool, at least I assume it is.  Exiftool will read flac files but will not write to them, so I wonder if I am getting a complete list from it.  But on the other hand how can a tag be duplicated; do they not need to be unique?

Re: FLAC files show duplicate tag

Reply #1
Metaflac shows you the correct information. I'm assuming the other tool you have tested filters away the extras as they have no values.

It was easy to introduce unwanted empty tags into FLAC files earlier when using the flac command line binary for encoding and tagging. It had a bug, or more like shortcoming, that it saved the given tag field name even if the tag field wasn't given any value to store. This was fixed some releases ago.

And having the same tag field multiple times is perfectly legal in the tagging system used by FLAC. It's the correct way to store multiple values for a single field. For example if your track had multiple artists they are supposed to be stored in their own "artist" fields.

Re: FLAC files show duplicate tag

Reply #2
Thank you for the great reply Case.

Re: FLAC files show duplicate tag

Reply #3
Sorry if I was not specific enough when I posted/asked for help. I thought things were self-explanatory.

My intent is to remove a “custom” tag that I inadvertently put a space in it’s name (Song Rating).  And replace it with a tag with no space (SongRating).
Or rename of the tag, but I didn't see a way to do that.
This is all via Windows 11  ( I am trying to leave Windows for Linux, still a bit more comfortable with Windows)
My working file is WorkingMan.flac
If I run the metaflac command:
metaflac --show-tag="Song Rating" --show-tag=SongRating WorkingMan.flac
I see the following:
--------------------------
R:\Rush\Rush>metaflac --show-tag="Song Rating" --show-tag=SongRating WorkingMan.flac
SONG RATING=9
SongRating=
SongRating=9

R:\Rush\Rush>
--------------------------
There is a duplicate tag (one with a value and one with no value)
Case explained to me that a duplicate tag is not necessarily unwanted.
 
From within dBpoweramp I deleted the SONG RATING tag (the one with the space that I wish to remove)
Then re-run the same metaflac command
metaflac --show-tag="Song Rating" --show-tag=SongRating WorkingMan.flac
I now see:
--------------------------
 R:\Rush\Rush>metaflac --show-tag="Song Rating" --show-tag=SongRating WorkingMan.flac
SongRating=9

R:\Rush\Rush>
--------------------------
That not only removed the tag that I actually wanted to delete, it also removed the duplicated tag that had no value.
…I must say I am confused.
So now the question begs to be asked.  If there are 2 or more tags with the same name, with or without values. How do you remove a specific tag that you want to remove.  If I use the metaflac command:
metaflac --remove-tag=SongRating WorkingMan_Copy.flac
it removes both.

Thanks
Dave

Re: FLAC files show duplicate tag

Reply #4
You  might try a tool like MP3Tag.
Manually select the tags you like to be removed.
TheWellTemperedComputer.com

Re: FLAC files show duplicate tag

Reply #5
So now the question begs to be asked.  If there are 2 or more tags with the same name, with or without values. How do you remove a specific tag that you want to remove.  If I use the metaflac command:
metaflac --remove-tag=SongRating WorkingMan_Copy.flac
it removes both.

Assuming metaflac won't write an empty tag, have you tried:
Code: [Select]
metaflac --no-utf8-convert --export-tags-to=- WorkingMan_Copy.flac | metaflac --remove-all-tags --import-tags-from=- WorkingMan_Copy.flac

EDIT: I didn't think I'd be able to create an empty tag to test this with, but it looks like metaflac does write empty tags and rewriting doesn't remove them.
Perhaps something like:
Code: [Select]
metaflac --no-utf8-convert --export-tags-to=- WorkingMan_Copy.flac | grep -v '^SongRating=$' | metaflac --remove-all-tags --import-tags-from=- WorkingMan_Copy.flac

Re: FLAC files show duplicate tag

Reply #6
Thanks for taking the time to help SimBun.  The edited command worked great!!  I made a small tweak to it to also remove the
 "SONG RATING" tag in the same command so I don't have to go back and touch all of these files again.   My tweaked command appears to work without breaking anything.

metaflac --remove-tag="SONG RATING" --no-utf8-convert --export-tags-to=- WorkingMan_Copy.flac | grep -v '^SongRating=$' | metaflac --remove-all-tags --import-tags-from=- WorkingMan_Copy.flac

This may not be the proper place to ask but I have a few questions about the command
If is is too complex or this is not the place I understand and am very grateful for the code.  Thank you SimBun!!

The 1st action (2nd in the tweaked) in the command seems to be exporting the tags to to themselves.  Is that right?
I see the metaflac help says to use ‘-‘ for stdout.  But it also seems to require a space after that, is that correct?

Thank you again, I am so appreciative to have received this!!!
Dave

Re: FLAC files show duplicate tag

Reply #7
The 1st action (2nd in the tweaked) in the command seems to be exporting the tags to to themselves.  Is that right?
I see the metaflac help says to use ‘-‘ for stdout.  But it also seems to require a space after that, is that correct?

The - after the --export-tags-to instructs metaflac to direct the output of the command to STDOUT (default output stream) so that it can be passed to subsequent commands.
The | connects the output (STDOUT) of one command to the input (STDIN) of another.

  • The first metaflac produces a tag listing that is passed to
  • grep which removes (-v) "SongRating=" from the listing and passes the output to
  • metaflac which reads the tags from STDIN and writes them to WorkingMan_Copy.flac.

--import-tags-from appends tags to the target file, so existing tags need to be removed first.

Try running it step by step.
Code: [Select]
$ metaflac --no-utf8-convert --export-tags-to=test.txt WorkingMan_Copy.flac
$ grep -v '^SongRating=$' test.txt > stripped.txt
$ metaflac --remove-all-tags --import-tags-from=stripped.txt WorkingMan_Copy.flac

Re: FLAC files show duplicate tag

Reply #8
I see/understand it now... Thanks SimBun

Dave

Re: FLAC files show duplicate tag

Reply #9
grep does not work in Windows out of the box? (Mine is gnu'ed up a bit, so I do have grep here, but I don't think that's default command. From the directory backslashes I presume it is Windows.)

Then instead use findstr (I looked up the syntax here). Note the double quotes.

metaflac --no-utf8-convert --export-tags-to=- WorkingMan_Copy.flac | findstr /B /E /V "SongRating=" | metaflac --remove-all-tags --import-tags-from=- WorkingMan_Copy.flac

  • The | ("pipe") sends the output to the next command.
  • The next command, findstr (or grep if you have that) is a string finder. /B finds it only at beginning of line, /E finds it only at end of line, so that means you are searching for a line that is "SongRating=" and nothing before or after; /V means to invert it, so to return every line that does NOT match.
If you are familiar with regular expressions, then findstr supports that as well, if you give the /R switch. Then it would be findstr /R /V "^SongRating=$" which closely matches the grep command suggested. In regex speak, a sole "^" means beginning of line and a sole "$" means end of line. The problem about regular expressions is that you need to know that there are special characters, so if all you need is "this is the entire line" then /B /E is just as good.
  • Then piping what grep/findstr found (namely the whole shebang except lines that are exactly "SongRating=") on to the next command. Which is another metaflac, that removes all the tags and imports the tags from "-" which is the standard input it was sent by the command before the pipe.

And yes, whitespace after "-", and sure you can use whitespaces around | too.


Re: FLAC files show duplicate tag

Reply #10
Thanks for the Windows command Porcus.  I have a Linux machine and a Windows.  I am trying to get off of Windows so I jumped onto my Linux box, and SimBun's code works like a charm.  But thanks for this... Next time I fire up my Windows box I will give this a try.
Thanks