Janina Sajka <janina(a)rednote.net> wrote:
Hi,
I need to calculate the total playing time of the audio files in a
particular folder. These are variously encoded--flac, ogg, and even some
mp3.
Anyone know how to do this, preferably from the cli? Or, perhaps one of
the music player apps can provide this datum for a folder?
I like using soxi from sox. The following should get you started:
(but do not run shell commands without understanding them :)
find \( -iname '*.flac' -o -iname '*.mp3' -o -iname '*.ogg' \)
-print0 | \
xargs -0 soxi
The find(1) invocation above searches for files with flac, mp3, and ogg
suffixes case-insensitively (-iname) wrapped inside the quoted '()' for
grouping via '-o' ("or").
-print0 in find pairs with the -0 in xargs so it can deal with shell-unfriendly
characters without breaking.
Finally the soxi(1) command does the grunt work of handling all the
command-line arguments for each supported filetype. You can also
parse and sum the time with the output of "soxi -D" instead of just
"soxi" (which shows output in a human-friendly format).
On Debian-based systems, you'll probably want install sox with all the
formats supported: apt-get install sox libsox-fmt-all
See the section 1 manpages for soxi, find, and xargs for more options
and possibilities.