[Easytag-mailing] Fwd: Re: Support for Multiple Tags of the same type




Oops, sorry for sending this privately, it was meant to be sent to the list only.

------- Vidaresänt brev -------
Från: "Johnny Rosenberg" <gurus knugum gmail com>
Till: "Owen Synge" <owen alice-dsl de>
Kopia:
Ärende: Re: [Easytag-mailing] Support for Multiple Tags of the same type
Datum: Sat, 18 Dec 2010 12:58:53 +0100

Den 2010-12-07 22:39:10 skrev Owen Synge <owen alice-dsl de>:

Dear all,

I have been using easytag for some time via debian but reasently foudn
a big probelm with it.

I want to tag a file with multiple Genre fields and easy tag wipes all
but one tag.

Exactly how do you do that? There is only one Genre field to write in,
right?

I was wondering if easytag has plans to support multiple tags, and user
defined tags for flac and ogg files.

A brief look at easytags source hinted that this might be a big change.

Is anyone else interested in thsi or working on this?

Interested, yes!

I saw a cryptic message on the changelog for the dev version:

"Fixed saving Ogg and Flac files with multifields and warn if the year
value will be truncated (thanks to Zohaib Hassan),"

Is this what I am looking for (the ability to easily manage multiple
tags of teh same type), if it is I havent worked out how to enable
tagging a file with 5+ genres and 5+ authors.

Probably not, see below.

Regards

Owen

I had the same thought and I also noticed that other applications for
tagging sound files lacks this too, at least those I tried, for example
Entagged.

If I create two or more tags of the same kind, like two ARTIST tags,
EasyTAG will show them all but in the same field, separated by ” - ”, for
example:
ARTIST="John Lennon"
ARTIST="Paul McCartney"

This will display as ”John Lennon - Paul McCartney” in EasyTAG.

It doesn't seem to be possible to create multiple tags with EasyTAG,
though.

OT:
When I manage my own sound files (I am some kind of a multi instrumental
musician with my own recording stuff at home), I use a script to add tags
to my FLAC files, since I add information to my files that most people
don't, such as who is playing what instrument, and I prefer my DATE tag to
look like ”2010-12-18” rather than just ”2010”. This allows me to use my
FLAC files as some kind of documentation of my ”work”, kind of.

For musical instruments tags I use the DESCRIPTION tag, so I don't
actually use ”my own” tag names, but I could if I rewrote my script a bit…

Also, my script only works for FLAC files, since I use METAFLAC for doing
the actual tag editing. METAFLAC is a part of the FLAC package, which in
Ubuntu can be installed from the repositories, which probably is the case
for Debian as well. Since tags in FLAC files are Vorbis tags, just like in
OGG Vorbis files, I would not be surprised if this worked for OGG Vorbis
files too, but some other parts of my scripts might not work, for example
my scripts test if the input files are real FLAC files before the action
starts…

I am a musician rather than a programmer, so I guess my scripts could be
done very much better, and so far they are only ”drafts” and almost all
text is in Swedish, but if anyone is interested or want some (bad?)
inspiration for making their own scripts, mine look like the following
code (even tried to translate all the Swedish to English, but maybe I
missed some text here and there).

You should change the values values of some variables defined at the
beginning of the code to make sure the code works on your system, of
course.

Use it at your own risk. It should be safe to copy some FLAC files
somewhere to test the script on them.

Before running a script you need to make sure you have the execute
permissions:
chmod +x edit-flac-tags-manually
chmod +x add-musician-info

You can also run the scripts by right clicking a FLAC file if you right
click a FLAC file, click ”Properties” → ”Open with” and add the scripts to
that list.

”edit-flac-tags-manually”:

# CODE STARTS HERE
#!/bin/bash

# edit-flac-tags-manually – Makes it easy to edit tags in flac files. You
can
# edit existing tags as well as copy them from another flac file, which is
# useful for musicians when a new version of a song (or remix, perharps) is
# going to replace an older one.
#
# Use this crap at your own risk…
#
# Johnny Rosenberg 2010-11-21 17:28:33

# REQUIREMENTS (obviously…)
# ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
# bash:					sudo apt-get install bash
# flac:					sudo apt-get install flac
# zenity:				sudo apt-get install zenity
# ubuntu or similar:	sudo apt-get install ubuntu (kidding… ;D )
# gedit:				sudo apt-get install gedit
#			(or use another text editor – just change the line below)
Editor="gedit"
Tempfile="${HOME}/.RosenTagg/Tempfile"

# Functions
IsRealFLAC () { # Checks wether the file is a real FLAC file or not.
	# Declare local variables.
	local FileName=$1
	zenity --info											\
		--title="Checking file"								\
		--text="Checking ${FileName}."						\
		--timeout=3 &
	
	Error=$(flac -t "${FileName}" 2>&1 | grep error)
	if [[ $Error ]]; then # Not a real FLAC file.
		Message="The file is probably not a FLAC file,\n"
		Message="${Message}or it might be corrupt."
		zenity --error 										\
			--width 300 									\
			--title "Corrupted file: ${InFile}"				\
			--text="${Message}"
		exit 1
	fi
}

Cancel () { # Function description
	zenity --info											\
		--width=250											\
		--title="Cancel"									\
		--text="Bye!"
	exit 1
}

FullPathName () { # Converts to full path filename
	# Declare local variables
	local FileName="$1"
	
	if [[ "${FileName}" = $(basename "${FileName}") ]]; then
		echo "${PWD}/${FileName}"
	else
		echo "${FileName}"
	fi
}
# End of functions

case $# in # How many arguments?
1) # Only one argument – is this the target or the source?
	InFile=$(FullPathName "$1")
	IsRealFLAC "${InFile}"
	Text="Selected file:\n"
	Text="${Text}$1"
	Val=$(zenity --list										\
		--title "Source or target file"						\
		--text="${Text}"									\
		--column="Category"									\
		--height=150										\
		--width=230											\
		"Source and target are the same"					\
		"Select another file as source"						\
		"Select another file as target")
	case "${Val}" in
	"Source and target are the same")
		TargetFile="${InFile}"
		;;
	"Select another file as source")
		TargetFile="${InFile}"
		if InFile=$(zenity --file-selection					\
			--title="Select source; target=${TargetFile}"	\
			--filename="${TargetFile}"						\
			--file-filter="*.flac"); then
			IsRealFLAC "${InFile}"
		else
			Cancel
		fi
		;;
	"Select another file as target")
		if TargetFile=$(zenity --file-selection				\
			--title="Select target; source=${InFile}"		\
			--filename="${InFile}"							\
			--file-filter="*.flac"); then
			IsRealFLAC "${TargetFile}"
		else
			Cancel
		fi
		;;
	*)
		Cancel
		;;
	esac
	;;
2) # Two arguments – the first one is source, the second one is target.
	InFile=$(FullPathName "$1")
	TargetFile=$(FullPathName "$2")
	IsRealFLAC "${TargetFile}"
	;;
*) # No arguments or too many – we won't deal with it at all.
	Text="Syntax:\n\n\tedit-flac-tags-manually FILE\n\t"
	Text="${Text}edit-flac-tags-manually INFILE OUTFILE"
	zenity --error 											\
		--width 300 										\
		--title "There is some crap behind the keyboard" 	\
		--text="${Text}"
	exit 1
	;;
esac

# Show the user what he did so far.
Text="You selected the follwoing:\n"
Text="${Text}Source=${InFile}\n\n"
Text="${Text}Target=${TargetFile}\n\n"
Text="${Text}Do you want to continue?"
if ! zenity --question										\
	--title="Your selections"								\
	--text="${Text}"										\
	--width=500; then
	Cancel
fi

if [[ -f "${Tempfile}" ]]; then
	rm "${Tempfile}"
fi
touch "${Tempfile}"

metaflac --export-tags-to="${Tempfile}" "${InFile}"

Text="Your text editor will now\n"
Text="${Text}open. Edit the file manually,\n"
Text="${Text}save and close your editor.\n"
zenity --info												\
	--title="Edit"											\
	--text="${Text}"

$("${Editor}" "${Tempfile}")

if ! zenity --question										\
	--title="Check"											\
	--text="Do you want to continue?"; then
	zenity --info											\
		--title="Bye"										\
		--text="No files were changed."
	rm "${Tempfile}"
	exit 1
fi

Message="Do you want to remove existing tags\n"
Message="${Message}from the file before continuing?"
if	zenity --question										\
	--title="Clean?"										\
	--text="${Message}"; then
	metaflac --remove-all-tags "${TargetFile}"
fi

# If you don't want your ”COMMENT” and ”COMMENTS” tags to be removed,
# remove the following two lines…
metaflac --remove-tag=COMMENT "${TargetFile}"
metaflac --remove-tag=COMMENTS "${TargetFile}"

metaflac --import-tags-from="${Tempfile}" "${TargetFile}"

# Display all the tags of the target file
metaflac --export-tags-to="${Tempfile}" "${TargetFile}"
# Is it possible to replace the two following lines by one single line?
sed -i 's/DESCRIPTION=//' "${Tempfile}"
sed -i 's/\(^.\)\(.*\)=\(.*\)/\U\1\L\2:\n\E\3\n/' "${Tempfile}"

zenity --text-info											\
	--title="Tags in ”${TargetFile}”"						\
	--height=768											\
	--width=600												\
	--filename="${Tempfile}"

rm "${Tempfile}"
# END OF CODE

I used gedit to write this crap. I used tab stop for indents and and one
tab stop is set to 4 spaces. That will make it look a bit nicer than it
does in this email, regarding the ”\” characters at the end of some lines,
which are supposed to appear in the same column.

add-musician-info:

This one requires two text files: One containing names you are going to
use a lot and the other one a lot of music instruments, I will give you
mine as an example below this simple code:

# CODE STARTS HERE
#!/bin/bash

# add-musician-info – Adds information about musical instruments and
musicians
# to a FLAC file. This is done by multiple use of the DESCRIPTION tag.
#
# Use this crap at your own risk…
#
# Johnny Rosenberg 2010-11-21 17:36:23


# REQUIREMENTS (obviously…)
# ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
# bash:					sudo apt-get install bash
# flac:					sudo apt-get install flac
# zenity:				sudo apt-get install zenity
# ubuntu or similar:	sudo apt-get install ubuntu (kidding… ;D )
# gedit:				sudo apt-get install gedit
#			(or use another text editor – just change the line below)
Editor="gedit"
InstrumentsList="${HOME}/.RosenTagg/Instruments"
MusiciansList="${HOME}/.RosenTagg/Musicians"
Tempfile="${HOME}/.RosenTagg/Tempfile"

if [[ $# != 1 ]]; then # Too many or too few arguments
	zenity --error 											\
		--width 300 										\
		--title "There is some crap behind the keyboard" 	\
		--text="Syntax:\n\n\tadd-musician-info FILE"
	exit 1
fi
SoundFile=$1

# Check the file. Is it a real FLAC file?
Error=$(flac -t "${SoundFile}" 2>&1 | grep error)
if [[ $Error ]]; then # Not a real FLAC file
	Message="The file is probably not a FLAC file,\n"
	Message="${Message}or it might be corrupt."
	zenity --error 											\
		--width 300 										\
		--title "Corrupted file" 							\
		--text="${Message}"
	exit 1
fi

if zenity --question										\
	--title="Input options"									\
	--text="Do you want to edit existing tags only?"; then
# BUG! ################################################################################################
	metaflac --show-tag=DESCRIPTION "${SoundFile}" > "${Tempfile}"
# END OF BUG ##########################################################################################
else
	if [[ -f "${Tempfile}" ]]; then
		rm "${Tempfile}"
	fi
	touch "${Tempfile}"

	Text="Select from the list.\n"
	Text="${Text}Click ”Cancel” to\n"
	Text="${Text}finish."
	while	Instrument=$(zenity --list						\
				--title "Select an instrument"				\
				--text="${Text}"							\
				--column="Instrument"						\
				--height=460								\
				--width=250 < "${InstrumentsList}") &&		\
			Musicians=$(zenity --list						\
				--title "${Instrument}: Select a musician"	\
				--text="${Text}"							\
				--column="Check"							\
				--column="Instrument"						\
				--checklist									\
				--separator=", "							\
				--height=480								\
				--width=370 < "${MusiciansList}"); do
		echo "${Instrument}: ${Musicians}" >> "${Tempfile}"
	done
fi

Text="Your text editor will now\n"
Text="${Text}open. Edit the file manually,\n"
Text="${Text}save and close your editor.\n"
zenity --info												\
	--title="Edit"											\
	--text="${Text}"

$("${Editor}" "${Tempfile}")

if !	zenity --question									\
			--title="Checking"								\
			--text="Do you want to continue?"; then
		zenity --info										\
			--title="Bye"									\
			--text="No files were changed."
		rm "${Tempfile}"
		exit 1
fi

Message="Do you want to clean the file\n"
Message="${Message}from existing comments first?"
if	zenity --question										\
		--title="Clean?"									\
		--text="${Message}"; then
	metaflac --remove-tag=DESCRIPTION "${SoundFile}"
fi

# If you don't want your ”COMMENT” and ”COMMENTS” tags to be removed,
# remove the following two lines…
metaflac --remove-tag=COMMENT "${SoundFile}"
metaflac --remove-tag=COMMENTS "${SoundFile}"

sed -i 's/^/DESCRIPTION=/' "$Tempfile"

metaflac --import-tags-from="${Tempfile}" "${SoundFile}"

# Display all the tags of the FLAC file
metaflac --export-tags-to="${Tempfile}" "${SoundFile}"
# Is it possible to replace the two following lines by one single line?
sed -i 's/DESCRIPTION=//' "${Tempfile}"
sed -i 's/\(^.\)\(.*\)=\(.*\)/\U\1\L\2:\n\E\3\n/' "${Tempfile}"

zenity --text-info											\
	--title="Tags in ”${SoundFile}”"						\
	--height=768											\
	--width=600												\
	--filename="${Tempfile}"

rm "${Tempfile}"
# END OF CODE

Here's my example file ”Instruments”; note that all instruments are sorted
in alphabetic order:
Accordion
Acoustic guitar
Backing vocals
Bass guitar
Cello
Digital drums
Double bass
Drum machine programming
Drums
Harmonica
Keyboard
Lead guitar
Lead vocal
Organ
Rhythm guitar

And finally, here is what a ”Musicians” file should look like (the names
here are fake):
FALSE
Pelvis Resley
FALSE
Johnny Trash
FALSE
Kenneth Knutter
FALSE
Maria Cherry
FALSE
Polly Partner
FALSE
Michael Saxon

The location of the ”Instruments” file should match the InstrumentsList
variable. Put the file where you want it and change the InstrumentsList
variable accordingly. This variable is set at the beginning of the
add-musician-info file, right after the initial comments.

The same goes for the ”Musicians” file, and the variable you should edit
is MusiciansList, located directly below the InstrumentsList variable,
described above.


--
Kind regards

Johnny Rosenberg

The script ”add-musician-info” above has a bug that in some cases causes tags like ”DESCRIPTION=DESCRIPTION=Some text” rather than ”DESCRIPTION=Some text”, so here is the fixed version, just forget about the version above (I have marked the bug above and the fix below):
# CODE STARTS HERE
#!/bin/bash

# add-musician-info – Adds information about musical instruments and musicians
# to a FLAC file. This is done by multiple use of the DESCRIPTION tag.
#
# Use this crap at your own risk…
#
# Johnny Rosenberg 2010-12-18 17:01:38


# REQUIREMENTS (obviously…)
# ≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈≈
# bash:					sudo apt-get install bash
# flac:					sudo apt-get install flac
# zenity:				sudo apt-get install zenity
# ubuntu or similar:	sudo apt-get install ubuntu (kidding… ;D )
# gedit:				sudo apt-get install gedit
#			(or use another text editor – just change the line below)
Editor="gedit"
InstrumentsList="${HOME}/.RosenTagg/Instruments"
MusiciansList="${HOME}/.RosenTagg/Musicians"
Tempfile="${HOME}/.RosenTagg/Tempfile"

if [[ $# != 1 ]]; then # Too many or too few arguments
	zenity --error 											\
		--width 300 										\
		--title "There is some crap behind the keyboard" 	\
		--text="Syntax:\n\n\tadd-musician-info FILE"
	exit 1
fi
SoundFile=$1

# Check the file. Is it a real FLAC file?
Error=$(flac -t "${SoundFile}" 2>&1 | grep error)
if [[ $Error ]]; then # Not a real FLAC file
	Message="The file is probably not a FLAC file,\n"
	Message="${Message}or it might be corrupt."
	zenity --error 											\
		--width 300 										\
		--title "Corrupted file" 							\
		--text="${Message}"
	exit 1
fi

if zenity --question										\
	--title="Input options"									\
	--text="Do you want to edit existing tags only?"; then
# Here's the bug fix! #################################################################################
	metaflac --show-tag=DESCRIPTION "${SoundFile}" |		\
		sed 's/DESCRIPTION=//' > "${Tempfile}"
# Bug fix ends here ###################################################################################
else
	if [[ -f "${Tempfile}" ]]; then
		rm "${Tempfile}"
	fi
	touch "${Tempfile}"

	Text="Select from the list.\n"
	Text="${Text}Click ”Cancel” to\n"
	Text="${Text}finish."
	while	Instrument=$(zenity --list						\
				--title "Select an instrument"				\
				--text="${Text}"							\
				--column="Instrument"						\
				--height=460								\
				--width=250 < "${InstrumentsList}") &&		\
			Musicians=$(zenity --list						\
				--title "${Instrument}: Select a musician"	\
				--text="${Text}"							\
				--column="Check"							\
				--column="Instrument"						\
				--checklist									\
				--separator=", "							\
				--height=480								\
				--width=370 < "${MusiciansList}"); do
		echo "${Instrument}: ${Musicians}" >> "${Tempfile}"
	done
fi

Text="Your text editor will now\n"
Text="${Text}open. Edit the file manually,\n"
Text="${Text}save and close your editor.\n"
zenity --info												\
	--title="Edit"											\
	--text="${Text}"

$("${Editor}" "${Tempfile}")

if !	zenity --question									\
			--title="Checking"								\
			--text="Do you want to continue?"; then
		zenity --info										\
			--title="Bye"									\
			--text="No files were changed."
		rm "${Tempfile}"
		exit 1
fi

Message="Do you want to clean the file\n"
Message="${Message}from existing comments first?"
if	zenity --question										\
		--title="Clean?"									\
		--text="${Message}"; then
	metaflac --remove-tag=DESCRIPTION "${SoundFile}"
fi

# If you don't want your ”COMMENT” and ”COMMENTS” tags to be removed,
# remove the following two lines…
metaflac --remove-tag=COMMENT "${SoundFile}"
metaflac --remove-tag=COMMENTS "${SoundFile}"

sed -i 's/^/DESCRIPTION=/' "$Tempfile"

metaflac --import-tags-from="${Tempfile}" "${SoundFile}"

# Display all the tags of the FLAC file
metaflac --export-tags-to="${Tempfile}" "${SoundFile}"
# Is it possible to replace the two following lines by one single line?
sed -i 's/DESCRIPTION=//' "${Tempfile}"
sed -i 's/\(^.\)\(.*\)=\(.*\)/\U\1\L\2:\n\E\3\n/' "${Tempfile}"

zenity --text-info											\
	--title="Tags in ”${SoundFile}”"						\
	--height=768											\
	--width=600												\
	--filename="${Tempfile}"

rm "${Tempfile}"
# END OF CODE




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]