Bug#357421: [vorbistagedit] updated version
Adeodato Simó
dato at net.com.org.es
Tue Jun 13 13:04:23 UTC 2006
* martin f krafft [Tue, 30 May 2006 11:39:49 +0200]:
Hey Martin.
> updated version attached.
I'm willing to ship this script in the package, but not without fixing a
couple issues first. I'm attaching both a patch, and the version resulting
from applying it. Please ack the changes, and I'll consider the script
ready for upload (or else, nack the changes and fix the bugs in some
other way that you fancy more :P).
The fixed issues are:
- deal with filenames that contain spaces (all my .ogg files do, so
this bug revealed itself pretty quickly ;-). For this, two things
are needed: quoting variables that contain filenames. And, when
getting filenames from stdin, assume one file per line (this is what
you get with e.g. `ls *.ogg | vorbistagedit`); for this, play with
IFS.
- do not glob tags (e.g., try setting "TITLE=Foo * Bar"). For this,
just quote "$tag" in write_tags().
- when the list of files is obtained from stdin with $(cat), I
experienced that the ${EDITOR} would die immediately, or do weird
things, because stdin is not a terminal; I tested with both vi and
joe, both in console an xterm, and both before and after introducing
the IFS change. The fix is to run the editor with </dev/tty.
Cheers,
--
Adeodato Simó dato at net.com.org.es
Debian Developer adeodato at debian.org
Listening to: Wagon Christ - Sci-Fi Staircase
-------------- next part --------------
--- vorbistagedit
+++ vorbistagedit.new
@@ -23,7 +23,7 @@
echo Usage: $ME file1.ogg [file2.ogg [file3.ogg ...]] >&2
echo
echo If no filenames are given, the list of filenames >&2
- echo is read from stdin. >&2
+ echo is read from stdin, one per line. >&2
}
for opt in $(getopt -n $ME -l version,help -o vVh? -- $@); do
@@ -46,7 +46,11 @@
exit -1
fi
+old_IFS="$IFS"
+IFS="
+"
[ $# -eq 0 ] && set -- $(cat)
+IFS="$old_IFS"
if [ $# -eq 0 ]; then
echo "$ME: no files given." >&2
@@ -68,15 +72,15 @@
_eof
for i in "$@"; do
- case $i in
+ case "$i" in
*.ogg)
- if [ ! -r $i ]; then
+ if [ ! -r "$i" ]; then
echo "$ME: unreadable file - $i" >&2
exit 1
fi
echo ": $i"
- vorbiscomment -l $i
+ vorbiscomment -l "$i"
echo
;;
@@ -90,7 +94,7 @@
MD5SUM=$(md5sum $TMPFILE)
-${EDITOR:-editor} $TMPFILE
+${EDITOR:-editor} $TMPFILE </dev/tty
if [ "$MD5SUM" = "$(md5sum $TMPFILE)" ]; then
echo "$ME: no changes, exiting..." >&2
@@ -100,8 +104,8 @@
declare -a tags
write_tags() {
- local file=$1; shift
- for tag; do echo $tag; done | vorbiscomment -w $file
+ local file="$1"; shift
+ for tag; do echo "$tag"; done | vorbiscomment -w "$file"
}
while read line; do
-------------- next part --------------
#!/bin/sh -eu
#
# vorbistagedit -- allows batch editing of vorbis comments with an editor
#
# © 2006 martin f. krafft <vorbistagedit at pobox.madduck.net>
# Released under the terms of the artistic licence.
#
VERSION=0.2
RELEASE=2006.05.06.1137
#
ME=${0##*/}
versioninfo() {
echo "vorbistagedit $VERSION ($RELEASE)" >&2
echo "vorbistagedit is (c) 2006 martin f. krafft" >&2
echo and released under the terms of the Artistic Licence. >&2
}
usage() {
versioninfo
echo
echo Usage: $ME file1.ogg [file2.ogg [file3.ogg ...]] >&2
echo
echo If no filenames are given, the list of filenames >&2
echo is read from stdin, one per line. >&2
}
for opt in $(getopt -n $ME -l version,help -o vVh? -- $@); do
case $opt in
--version|-V|-v)
versioninfo
exit 0;;
--help|-h|-\?)
usage
exit 0;;
--) :;;
-*)
exit 1;;
*) :;;
esac
done
if ! command -v vorbiscomment >/dev/null; then
echo "$ME: vorbiscomment not found in \$PATH." >&2
exit -1
fi
old_IFS="$IFS"
IFS="
"
[ $# -eq 0 ] && set -- $(cat)
IFS="$old_IFS"
if [ $# -eq 0 ]; then
echo "$ME: no files given." >&2
exit 0
fi
TMPFILE=$(mktemp /tmp/vorbistagedit.XXXXXX)
trap "rm -f $TMPFILE" 0
cat <<_eof > $TMPFILE
# vorbistagedit
#
# Edit the lines in this file to your desire, but
# DO NOT touch lines starting with a colon (:)!
#
# We are in directory:
# $(pwd)
_eof
for i in "$@"; do
case "$i" in
*.ogg)
if [ ! -r "$i" ]; then
echo "$ME: unreadable file - $i" >&2
exit 1
fi
echo ": $i"
vorbiscomment -l "$i"
echo
;;
*)
echo "$ME: invalid argument - $i" >&2
exit 2
;;
esac
done >> $TMPFILE
echo : EOF >> $TMPFILE
MD5SUM=$(md5sum $TMPFILE)
${EDITOR:-editor} $TMPFILE </dev/tty
if [ "$MD5SUM" = "$(md5sum $TMPFILE)" ]; then
echo "$ME: no changes, exiting..." >&2
exit 0
fi
declare -a tags
write_tags() {
local file="$1"; shift
for tag; do echo "$tag"; done | vorbiscomment -w "$file"
}
while read line; do
case "$line" in
': EOF')
write_tags "$file" "${tags[@]}";;
:*)
if [ -n "${file:-}" ]; then
write_tags "$file" "${tags[@]}"
tags=()
fi
file="${line#: }";;
*=*)
tags[${#tags[@]}]="$line";;
*|'#*') :;;
esac
done < $TMPFILE
rm -f $TMPFILE
trap - 0
exit 0
More information about the pkg-xiph-maint
mailing list