Browse Source

Merge pull request #7 from onlyjob/my-fixes

Fixes and improvements from Debian
master
Svend Sorensen 10 years ago
parent
commit
ac28bb8cd8
5 changed files with 74 additions and 45 deletions
  1. +4
    -4
      src/lib/cd.c
  2. +2
    -2
      src/lib/cuefile.c
  3. +1
    -1
      src/lib/time.c
  4. +1
    -1
      src/tools/cueprint.c
  5. +66
    -37
      src/tools/cuetag.sh

+ 4
- 4
src/lib/cd.c View File

@@ -126,7 +126,7 @@ Cdtext *cd_get_cdtext(Cd *cd)

Track *cd_add_track(Cd *cd)
{
if (MAXTRACK - 1 > cd->ntrack) {
if (MAXTRACK > cd->ntrack) {
cd->ntrack++;
} else {
fprintf(stderr, "too many tracks\n");
@@ -146,7 +146,7 @@ int cd_get_ntrack(Cd *cd)

Track *cd_get_track(Cd *cd, int i)
{
if (0 < i <= cd->ntrack) {
if (0 < i && i <= cd->ntrack) {
return cd->track[i - 1];
}

@@ -266,7 +266,7 @@ Cdtext *track_get_cdtext(Track *track)

void track_add_index(Track *track, long index)
{
if (MAXTRACK - 1 > track->nindex) {
if (MAXINDEX > track->nindex) {
track->nindex++;
} else {
fprintf(stderr, "too many indexes\n");
@@ -283,7 +283,7 @@ int track_get_nindex(Track *track)

long track_get_index(Track *track, int i)
{
if (0 <= i < track->nindex) {
if (0 <= i && i < track->nindex) {
return track->index[i];
}



+ 2
- 2
src/lib/cuefile.c View File

@@ -18,7 +18,7 @@ Cd *cf_parse(char *name, int *format)

if (UNKNOWN == *format) {
if (UNKNOWN == (*format = cf_format_from_suffix(name))) {
fprintf(stderr, "%s: unknown format\n", name);
fprintf(stderr, "%s: unknown file suffix\n", name);
return NULL;
}
}
@@ -52,7 +52,7 @@ int cf_print(char *name, int *format, Cd *cd)

if (UNKNOWN == *format) {
if (UNKNOWN == (*format = cf_format_from_suffix(name))) {
fprintf(stderr, "%s: unknown format\n", name);
fprintf(stderr, "%s: unknown file suffix\n", name);
return -1;
}
}


+ 1
- 1
src/lib/time.c View File

@@ -34,7 +34,7 @@ void time_frame_to_msf(long frame, int *m, int *s, int *f)
/* print frame in mm:ss:ff format */
char *time_frame_to_mmssff(long f)
{
static char msf[9];
static char msf[10];
int minutes, seconds, frames;

msf_frame_to_msf(f, &minutes, &seconds, &frames);


+ 1
- 1
src/tools/cueprint.c View File

@@ -264,7 +264,7 @@ void print_conv(char *start, int length, Cd *cd, int trackno)
printf(conv, value.sval);
break;
default:
printf("%d: ", strlen(conv));
printf("%zu: ", strlen(conv));
printf("%s", conv);
}



+ 66
- 37
src/tools/cuetag.sh View File

@@ -27,9 +27,13 @@ usage()
# for FLAC and Ogg Vorbis files
vorbis()
{
trackno=$1; shift
file="$1"; shift
fields="$@"

# FLAC tagging
# --remove-vc-all overwrites existing comments
METAFLAC="metaflac --remove-vc-all --import-vc-from=-"
METAFLAC="metaflac --remove-all-tags --import-tags-from=-"

# Ogg Vorbis tagging
# -w overwrites existing comments
@@ -40,7 +44,7 @@ vorbis()
# TODO: this also outputs to stdout
TXTFILE="tee"

case "$2" in
case "$file" in
*.[Ff][Ll][Aa][Cc])
VORBISTAG=$METAFLAC
;;
@@ -55,8 +59,9 @@ vorbis()
# space seperated list of recomended stardard field names
# see http://www.xiph.org/ogg/vorbis/doc/v-comment.html
# TRACKTOTAL is not in the Xiph recomendation, but is in common use
fields='TITLE VERSION ALBUM TRACKNUMBER TRACKTOTAL ARTIST PERFORMER COPYRIGHT LICENSE ORGANIZATION DESCRIPTION GENRE DATE LOCATION CONTACT ISRC'

[ -n "$fields" ] ||
fields='TITLE VERSION ALBUM TRACKNUMBER TRACKTOTAL ARTIST PERFORMER COPYRIGHT LICENSE ORGANIZATION DESCRIPTION GENRE DATE LOCATION CONTACT ISRC'

# fields' corresponding cueprint conversion characters
# seperate alternates with a space
@@ -64,8 +69,8 @@ vorbis()
TITLE='%t'
VERSION=''
ALBUM='%T'
TRACKNUMBER='%n'
TRACKTOTAL='%N'
TRACKNUMBER='%02n'
TRACKTOTAL='%02N'
ARTIST='%c %p'
PERFORMER='%p'
COPYRIGHT=''
@@ -79,21 +84,31 @@ vorbis()
ISRC='%i %u'

(for field in $fields; do
value=""
for conv in $(eval echo \$$field); do
value=$($CUEPRINT -n $1 -t "$conv\n" $cue_file)

if [ -n "$value" ]; then
echo "$field=$value"
break
fi
done
done) | $VORBISTAG "$2"
case "$field" in
(*=*) echo "$field";;
(*)
value=""
for conv in $(eval echo \$$field); do
value=$($CUEPRINT -n $trackno -t "$conv\n" "$cue_file")

if [ -n "$value" ]; then
echo "$field=$value"
break
fi
done
;;
esac
done) | $VORBISTAG "$file"
}

id3()
{
MP3INFO=mp3info
MP3TAG=$(which mid3v2) \
|| MP3TAG=$(which id3v2)
if [ -z "${MP3TAG}" ]; then
echo "error: not found '(m)id3v2'."
exit 1
fi

# space seperated list of ID3 v1.1 tags
# see http://id3lib.sourceforge.net/id3/idev1.html
@@ -112,37 +127,42 @@ id3()
TRACKNUMBER='%n'

for field in $fields; do
value=""
for conv in $(eval echo \$$field); do
value=$($CUEPRINT -n $1 -t "$conv\n" $cue_file)

if [ -n "$value" ]; then
break
fi
done
case "$field" in
*=*) value="${field#*=}";;
*)
value=""
for conv in $(eval echo \$$field); do
value=$($CUEPRINT -n $1 -t "$conv\n" "$cue_file")

if [ -n "$value" ]; then
break
fi
done
;;
esac

if [ -n "$value" ]; then
case $field in
TITLE)
$MP3INFO -t "$value" "$2"
$MP3TAG -t "$value" "$2"
;;
ALBUM)
$MP3INFO -l "$value" "$2"
$MP3TAG -A "$value" "$2"
;;
ARTIST)
$MP3INFO -a "$value" "$2"
$MP3TAG -a "$value" "$2"
;;
YEAR)
$MP3INFO -y "$value" "$2"
$MP3TAG -y "$value" "$2"
;;
COMMENT)
$MP3INFO -c "$value" "$2"
$MP3TAG -c "$value" "$2"
;;
GENRE)
$MP3INFO -g "$value" "$2"
$MP3TAG -g "$value" "$2"
;;
TRACKNUMBER)
$MP3INFO -n "$value" "$2"
$MP3TAG -T "$value" "$2"
;;
esac
fi
@@ -159,23 +179,32 @@ main()
cue_file=$1
shift

ntrack=$(cueprint -d '%N' $cue_file)
ntrack=$(cueprint -d '%N' "$cue_file")
trackno=1

FILES= FIELDS=
for arg in "$@"; do
case "$arg" in
*.*) FILES="$FILES $arg";;
*) FIELDS="$FIELDS $arg";;
esac
done

set -- $FILES
if [ $# -ne $ntrack ]; then
echo "warning: number of files does not match number of tracks"
fi

for file in $@; do
for file in "$@"; do
case $file in
*.[Ff][Ll][Aa][Cc])
vorbis $trackno "$file"
vorbis $trackno "$file" $FIELDS
;;
*.[Oo][Gg][Gg])
vorbis $trackno "$file"
vorbis $trackno "$file" $FIELDS
;;
*.[Mm][Pp]3)
id3 $trackno "$file"
id3 $trackno "$file" $FIELDS
;;
*.[Tt][Xx][Tt])
vorbis $trackno "$file"


Loading…
Cancel
Save