Convert files on directories that are not always t

2019-07-12 08:34发布

I've got a script that runs when a torrent download is finished to see if there are FLAC audio files and if yes convert them to MP3. Until today I've used:

for file in "$torrentpath"/"$torrentname"/*.flac
do
    ffmpeg -i "$file" -qscale:a 0 "${file[@]/%flac/mp3}"

done

But I realised that when a torrent comes containing sub-directories the script is useless. I've tried messing around for the past few days with "find" and "if" and other ways but I can't really see the answer. I know it's there.

The script should just test if there are sub-dirs and execute ffmpeg on those, otherwise directly go with the conversion.

Any little hint will be appreciated.

2条回答
做个烂人
2楼-- · 2019-07-12 09:11

to handle arbitrary subdirectories in bash:

shopt -s globstar nullglob
for file in "$torrentpath/$torrentname"/**/*.flac
do ...
查看更多
Evening l夕情丶
3楼-- · 2019-07-12 09:11
find "$torrentpath"/"$torrentname" -name '*.flac' -print | while read file; do
    ffmpeg -i "$file" -qscale:a 0 "${file[@]/%flac/mp3}"
done
查看更多
登录 后发表回答