#!/bin/zsh
-## Copyright (C) 2006 - 2011 Steve Youngs
+## Copyright (C) 2006 - 2013 Steve Youngs
## Author: Steve Youngs <steve@steveyoungs.com>
## Maintainer: Steve Youngs <steve@steveyoungs.com>
## Created: <2006-08-08>
-## Time-stamp: <Sunday Jun 19, 2011 12:21:40 steve>
+## Time-stamp: <Saturday Feb 20, 2021 12:38:28 steve>
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## o Partial album ripping. Specify track numbers or a range of
## track numbers to only rip/encode those tracks.
##
-## o Ripping from music DVDs
+## o Rewrite online metadata retrieval to use MusicBrainz instead
+## of freedb.org as the latter no longer exists.
##
### Bugs:
# Version info.
VERSION=@VERSION@
-COPYRIGHT="Copyright (C) 2006 - 2011 Steve Youngs <steve@steveyoungs.com>"
+COPYRIGHT="Copyright (C) 2006 - 2021 Steve Youngs <steve@steveyoungs.com>"
version_str="${ourname}: ${VERSION}
${COPYRIGHT}"
[ -a ALBUM ] [ --album=ALBUM ] [ -s ARTIST ] [ --sameartist=ARTIST ]
[ -t ENCODING_TYPE ] [ --type=ENCODING_TYPE ] [ -f | --flac_copy ]
[ -e FILE | --edit_rcfile=FILE ] [ -O | --online ] [ -d DIR | --dir=DIR ]
+ [ -p PLAYLISTFILE | --playlist=PLAYLISTFILE ]
$ourname
[ -h | --help ]
$ourname
$ourname is a "frontend" to the process of ripping audio (cdda) CDs
to a hard disk and encoding the audio tracks to either MP3 format or
- Ogg Vorbis format.
+ Ogg/Vorbis format.
File names are auto-generated from track titles, with illegal
characters removed and spaces converted to underscores.
Track title, artist, and album names are added to the ID3 tags or
Vorbis comments header.
+ If the file: '\${PWD}/cover.jpg' exists it will be embedded into
+ each track file as "Front Cover" art. This is only supported for
+ Ogg/Vorbis and FLAC formats.
+
Options:
-------
Save encoded files to the directory, DIR. If flac encoding
is also requested, see '--flac_copy' option below, the flac
files will be saved to DIR/flac. If this option is omitted,
- it defaults to 'PWD/ARTIST/ALBUM' the album name is first
- converted to a sane filename.
+ it defaults to: '\${PWD}/ARTIST/ALBUM' (with sanitised
+ filenames).
-e FILE
--edit_rcfile=FILE
-f
--flac_copy
- In addition to encoding the CD audio tracks to MP3 or Ogg
- Vorbis, create a FLAC audio file for archival purposes.
+ In addition to encoding the CD audio tracks to Ogg/Vorbis or
+ MP3, create a FLAC audio file for archival purposes.
-h
--help
-o
--ogg
- Specify Ogg Vorbis encoding.
+ Specify Ogg/Vorbis encoding.
-O
--online
Attempt to grab the track info from freedb.freedb.org.
+ DO NOT USE.
+
+ freedb.org no longer exists. The plan is for zcdrip to
+ use MusicBrainz instead of freedb.org but it is not yet
+ implemented.
+
+ -p PLAYLISTFILE
+ --playlist=PLAYLISTFILE
+ Write a playlist file to PLAYLISTFILE. Argument PLAYLISTFILE
+ is _NOT_ optional, and should be given as the full path to the
+ file.
-r FILE
--rcfile=FILE
Artist Name|Track Title
One "record" per line. Whitespace and punctuation is permitted,
- blank lines are not. And there is no "comment" lines.
+ blank lines are not. And there are no "comment" lines.
-s ARTIST
--sameartist=ARTIST
lame http://www.mp3dev.org/
For encoding to MP3 format. (optional if encoding to
- Ogg Vorbis)
+ Ogg/Vorbis)
oggenc http://www.xiph.org/
- For encoding to Ogg Vorbis format (optional if encoding
+ For encoding to Ogg/Vorbis format (optional if encoding
to MP3)
flac http://flac.sourceforge.net/
Example Usage:
-------------
+ ## Note:
+ Currently, online metadata retrieval is not possible because freedb.org
+ no longer exists. We will be converting to MusicBrainz but that is yet
+ to be implemented. In the meantime, the examples below that use the
+ '-O' option are presently not valid.
Probably the most common usage would be to encode to Ogg/Vorbis
format using track info obtained from freedb.freedb.org. Like
EOF
}
+# Cover Art
+ARTWORK=$(pwd)/cover.jpg
# Convert song title to something resembling a sane filename... no
# whitespace, no punctuation, etc. Also adds .ogg/.mp3 extension.
done
}
+### FIXME: freedb.org no longer exists. Convert to MusicBrainz.
### freedb magic
_freedb_login ()
{
return 0
}
+### FIXME: freedb.org no longer exists. Convert to MusicBrainz.
_parse_cddb ()
{
local various=yes
fi
# create an rcfile
+ :>$rcfile # make sure it is empty
+
+ for (( i=0; i<$tracks; i++ )); do
+ TRACK=""
+ for TITLE in $(grep TTITLE${i}= ${zlog}|cut -d= -f2); do
+ TRACK="${TRACK} ${TITLE}"
+ done
+ TRACK=${TRACK//[[:cntrl:]]/}
+ TRACK=${TRACK/[[:space:]]/}
+ echo ${TRACK} >> ${rcfile}
+ done
+
if [[ $various == yes || -n $(grep TTITLE $zlog|grep $art) ]]; then
- grep TTITLE $zlog|cut -d= -f2|sed 's@ [-/] @|@' > $rcfile
+ sed -i 's@ [-/] @|@g' $rcfile
else
- grep TTITLE $zlog|cut -d= -f2 > $rcfile
sed -i "s@^@${art}|@g" $rcfile
fi
}
+### FIXME: freedb.org no longer exists. Convert to MusicBrainz.
_freedb_read ()
{
if [[ -z $1 ]]; then
}
+### FIXME: freedb.org no longer exists. Convert to MusicBrainz.
_freedb_query ()
{
if [[ -z $1 ]]; then
esac
}
+### FIXME: freedb.org no longer exists. Convert to MusicBrainz.
do_online ()
{
autoload -U tcp_open
_album_to_dir ()
{
local talbum=$album
- local tart=$art
+ local tart=${ARTIST:-$art}
local psub="[[:cntrl:],\`';/\\\\\"]"
local prep=""
local wsub="[[:space:][:blank:]]"
dir=$(pwd)/${tart}/${talbum}
[[ -d ${dir} ]] || mkdir -p ${dir}
- [[ $keep_flac == yes ]] && fdir=${dir}/flac; mkdir -p ${fdir}
+
+ if [[ $keep_flac == yes ]]; then
+ fdir=${dir}/flac
+ mkdir -p ${fdir}
+ fi
}
$_zedit $rcfile
fi
+ album=${ALBUM:-$album}
if [[ -z $album ]]; then
echo -n "Please enter the name of this album: "
read album
fi
fi
+ year=${YEAR:-$year}
if [[ -z $year ]]; then
echo -n "Please enter the year this album was released: "
read year
echo
fi
+ genre=${GENRE:-$genre}
if [[ -z $genre ]]; then
echo -n "Please enter the genre of this album: "
read genre
{
file=$1
shift # pop off $1 (flacfile)
- flac -8 --delete-input-file -o ${fdir}/${file} ${1}
+ [ -f ${ARTWORK} ] && PIC="--picture=${ARTWORK}" || PIC=""
+ flac -8 ${PIC} --delete-input-file -o ${fdir}/${file} ${1}
shift # pop off next arg (wavfile)
for tag in title artist album year genre tracknumber comment; do
metaflac --set-tag="$tag=${1}" ${fdir}/${file}
mp3=$2
# tags
- title=$(metaflac --show-tag=title|cut -d= -f2)
- artist=$(metaflac --show-tag=artist|cut -d= -f2)
- album=$(metaflac --show-tag=album|cut -d= -f2)
- year=$(metaflac --show-tag=year|cut -d= -f2)
- genre=$(metaflac --show-tag=genre|cut -d= -f2)
- track=$(metaflac --show-tag=tracknumber|cut -d= -f2)
- comment=$(metaflac --show-tag=comment|cut -d= -f2)
+ title=$(metaflac --show-tag=title ${flac}|cut -d= -f2)
+ artist=$(metaflac --show-tag=artist ${flac}|cut -d= -f2)
+ album=$(metaflac --show-tag=album ${flac}|cut -d= -f2)
+ year=$(metaflac --show-tag=year ${flac}|cut -d= -f2)
+ genre=$(metaflac --show-tag=genre ${flac}|cut -d= -f2)
+ track=$(metaflac --show-tag=tracknumber ${flac}|cut -d= -f2)
+ comment=$(metaflac --show-tag=comment ${flac}|cut -d= -f2)
flac -c -d $flac|lame -h --tt ${title} --ta ${artist} --tl ${album} \
--ty $year --tg $genre --tn $track --tc ${comment} - $mp3
mp3rip ()
{
# Work around lame being too anal about genre
- lame --genre-list|grep ${genre} 1>/dev/null || genre=Other
+ lame --genre-list 2>&1 | grep -q ${genre} || genre=Other
for (( i=1; i<=$tracks; ++i )); do
echo MP3-Ripping: $song[$i], by: $artist[$i], to: $filename[$i]
--ty $year --tg $genre --tc $zcomment $wavfile \
--tn $i ${dir}/$filename[$i]
fi
+ [[ $write_playlist == yes ]] && echo ${dir}$filename[$i] >> $plfile
fi
[[ -f $wavfile ]] && rm -f $wavfile
done
-N $i $wavfile
rm $wavfile
fi
+ [ -f ${ARTWORK} ] && album_art ${dir}/$filename[$i]
+ [[ $write_playlist == yes ]] && echo ${dir}/$filename[$i] >> $plfile
fi
done
}
# Make sure we have everything we need.
# This might be a little over the top, but I don't see any point in
# checking for `oggenc' if you are encoding to MP3, likewise, there's
-# no point in checking for `lame' if you are encoding to Ogg Vorbis.
+# no point in checking for `lame' if you are encoding to Ogg/Vorbis.
chkreqs ()
{
reqs=(cdparanoia lame oggenc flac)
# Command line parsing
-args=mofihVO-:r:a:s:t:e:d:
+args=mofihVO-:r:a:s:t:e:d:p:
flavour=0
rc=0
interactive=no
(album?*) album=${OPTARG/album=/} ;;
(sameartist?*) art=${OPTARG/sameartist=/} ;;
(dir?*) dir=${OPTARG/dir=/} ;;
+ (playlist?*) write_playlist=yes; plfile=${OPTARG/playlist=/} ;;
(version) _version; exit 0 ;;
(help) cmd=usage; rv=0 ;;
(*)
(s) art=$OPTARG ;;
(t) atype=$OPTARG; (( ++flavour )) ;;
(d) dir=$OPTARG ;;
+ (p) write_playlist=yes; plfile=$OPTARG ;;
(V) _version; exit 0 ;;
(h) cmd=usage; rv=0 ;;
(*) rv=2 ;;