Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # mp3reclaimer
- # retrieves mp3 files stored on ipods
- # and renames them based on their id3 tags
- # created 2015-06-26 Ri
- # modified 2015-06-26 Ri
- # set variables
- myname=`basename $0`
- ipodVolumePath=
- ipodMusicPath="iPod_Control/Music"
- outputDir=`pwd`
- # declare functions
- error() # error handler
- {
- echo "$myname: $1" 1>&2
- }
- check_path() # checks if supplied argument is a valid path
- {
- if [ ! -d "$1" ] && [ ! -f "$1" ]; then
- error "invalid path $1"
- exit 1
- fi
- }
- get_id3_tag() # gets id3 tags on supplied file
- {
- id3v2 --list "$1" |
- grep -e "^$2" | awk 'BEGIN { FS=": " } ; { print $2 }'
- }
- # parse options and arguments
- while [ $# -gt 0 ]; do
- case $1 in
- -o|--outputdir)
- outputDir="$2"
- shift 2
- ;;
- -*|--*)
- error "invalid option $1"
- exit 1
- ;;
- *)
- ipodVolumePath="$1"
- shift
- ;;
- esac
- done
- # perform sanity check
- check_path "$ipodVolumePath"
- check_path "$ipodVolumePath/$ipodMusicPath"
- check_path "$outputDir"
- # execute
- for f in "$ipodVolumePath/$ipodMusicPath"/**/*.mp3; do
- artist=`get_id3_tag "$f" "TP1"`
- if [ "X$artist" = "X" ]; then
- artist="Unknown Artist"
- fi
- artist=`echo "$artist" | LANG=C sed 's/:/;/g'`
- artist=`echo "$artist" | LANG=C sed 's/\//:/g'`
- title=`get_id3_tag "$f" "TT2"`
- if [ "X$title" = "X" ]; then
- title="Unknown Title"
- fi
- title=`echo "$title" | LANG=C sed 's/:/;/g'`
- title=`echo "$title" | LANG=C sed 's/\//:/g'`
- newfilename="$artist - $title"
- cp -v "$f" "$outputDir/$newfilename.mp3"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement