我想创建一个脚本,它将使用4个id标签之一来搜索驱动器上的MP3文件。到目前为止,我设法创建了这样的东西,但它根本不起作用。有人可以建议我解决什么问题吗?
#!/bin/bash
while getopts ":atbg:" opt; do
case $opt in
a) artist=${OPTARG}
;;
b) album=${OPTARG}
;;
t) title=${OPTARG}
;;
g) genre=${OPTARG}
;;
esac
done
find . -name '*.mp3' -print0 | while read -d $'\0' file
do
checkere=0
if [ "$album" != NULL ]
then
if [ !($(id3info "$file" | grep '$artist' sed -e 's/.*: //g')) ]
then
$checkere=1
fi
fi
if [ "$title" != NULL ]
then
if [ !($(id3info "$file" | grep '$title' sed -e 's/.*: //g')) ]
then
$checkere=1
fi
fi
if [ "$album" != NULL ]
then
if !($(id3info "$file" | grep '$album' sed -e 's/.*: //g'))
then
$checkere=1
fi
fi
if [ "$genre" != NULL ]
then
if !($(id3info "$file" | grep '$genre' sed -e 's/.*: //g'))
then
$checkere=1
fi
fi
if [ $checkere -eq 0 ]
then
echo $file
fi
done
答案 0 :(得分:0)
#!/bin/bash
# Process command line args
while getopts a:b:t:g: arg ; do case $arg in
a) artist=${OPTARG} ;;
b) album=${OPTARG} ;;
t) title=${OPTARG} ;;
g) genre=${OPTARG} ;;
:) echo "${0##*/}: Must supply an argument to $OPTARG." ; exit 1 ;;
\?) echo "Invalid option. Abort" ; exit 1 ;;
esac
done
shift $(($OPTIND - 1))
[ "$#" -eq 0 ] || { echo "Incorrect usage" ; exit 1 ; }
# Find matching files
find . -name '*.mp3' -print0 |
while read -r -d $'\0' file
do
info=$(id3info $file)
[ "$artist" ] && { echo "$info" | grep -q "=== TPE1 (Lead performer(s)/Soloist(s)): $artist$" || continue ; }
[ "$album" ] && { echo "$info" | grep -q "=== TALB (Album/Movie/Show title): $album$" || continue ; }
[ "$title" ] && { echo "$info" | grep -q "=== TIT2 (Title/songname/content description): $title$" || continue ; }
[ "$genre" ] && { echo "$info" | grep -q "=== TCON (Content type): $genre$" || continue ; }
echo "$file"
done
样本用法:
mp3search -a "The Rolling Stones" -t "Let It Bleed"