From b4efa7809277747312288f6aaf078f4b136f1189 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 29 Apr 2013 23:16:56 +0200 Subject: [PATCH 1/3] Read tags from video files --- lib/tags/getInfos::ffmpeg | 51 +++++++++++++++++++++++++++++++++++++++ lib/tags/getTags | 5 +++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 lib/tags/getInfos::ffmpeg diff --git a/lib/tags/getInfos::ffmpeg b/lib/tags/getInfos::ffmpeg new file mode 100644 index 0000000..d855139 --- /dev/null +++ b/lib/tags/getInfos::ffmpeg @@ -0,0 +1,51 @@ +#!/bin/bash +getInfosffmpeg_version='ffmpeg-1' +tagreaders+=( "$getInfosffmpeg_version" ) +getInfos::ffmpeg() { + tagreader="$getInfosffmpeg_version" + local allinfos=$( + ffprobe -show_streams \ + -i "$sourcepath/$filename" 2>&1 \ + |sed ' + /^Input/,/.* Audio: /{s/ *: */=/} + s/^[[:space:]]*//' + ) + local metadata=$( + echo -e "$allinfos" \ + |sed -n '/Metadata=/,/\[STREAM\]/p' + ) + local fmt_infos=$( + echo -e "$allinfos" \ + |sed -n \ + '/codec_type=audio/,/\[STREAM\]/{ + /^\(sample_rate\|bit_rate\|channels\)=/{ + p + } + }' + ) + local infos="$metadata" + albumartist=$(gettag album_artist) + album=$(gettag album) + artist=$(gettag artist) + composer=$(gettag composer) + genre=$(gettag genre) + performer=$(gettag TOPE) + title=$(gettag title) + tracknum=$(gettag tracknumber) + year=$(gettag year) + expr='^[0-9]*$' + if [ -n "$genre" ] && [[ $genre =~ $expr ]] + then + genre="${id3genres[$genre]}" + fi + infos="$fmt_infos" + channels=$(gettag channels) + rate=$(gettag 'sample_rate') + bitrate=$(gettag 'bit_rate') + if [[ $bitrate == N/A ]] + then + unset bitrate + else + bitrate=$((bitrate / 1000)) + fi +} diff --git a/lib/tags/getTags b/lib/tags/getTags index 6a735df..0774d68 100644 --- a/lib/tags/getTags +++ b/lib/tags/getTags @@ -1,5 +1,5 @@ #!/bin/bash -getTags_version='unknown-2' +getTags_version='unknown-3' tagreaders+=( "$getTags_version" ) getTags() { unset type @@ -16,6 +16,9 @@ getTags() { audio/x-flac) type=FLAC ;; + video/*) + type=ffmpeg + ;; *) extendedtype=$(file -b "$sourcepath/$filename") case "$extendedtype" in From 311617cefb0eb5472b5a47f5628574102ed990b8 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 29 Apr 2013 23:18:10 +0200 Subject: [PATCH 2/3] move code to decodeFile() --- atom | 70 +----------------------- lib/decode/decodeFile | 120 +++++++++++++++++++++++++++++++++--------- 2 files changed, 95 insertions(+), 95 deletions(-) diff --git a/atom b/atom index 2a2d80b..c338785 100755 --- a/atom +++ b/atom @@ -420,75 +420,7 @@ do rest=${rest#*|} performer=${rest%%|*} unset rest - case "$mimetype" in - 'audio/mpeg') - if [[ ${destinationformat[$destination]} = mp3 ]] \ - && checkCopy - then - copied=1 - else - decodeSox - fi - ;; - 'application/ogg opus') - if [[ ${destinationformat[$destination]} = opus ]] \ - && checkCopy - then - copied=1 - else - decodeOpusdec - if (( ${destinationnormalize["$destination"]}))\ - || ( - [ -n "${destinationfrequency["$destination"]}" ]\ - && (( ${rate:-0} != ${destinationfrequency["$destination"]}))\ - ) || ( - [ -n "${destinationchannels["$destination"]}" ]\ - && (( ${channels:-0} != ${destinationchannels["$destination"]} )) - ) - then - sox_needed=1 - fi - fi - ;; - 'application/ogg'*) - if [[ ${destinationformat[$destination]} = vorbis ]] \ - && checkCopy - then - copied=1 - else - decodeSox - fi - ;; - 'audio/x-flac') - decodeSox - ;; - *) - extendedtype=$(file -b "$sourcepath/$filename") - case "$extendedtype" in - *'Musepack '*) - decodeMpcdec - if (( ${destinationnormalize["$destination"]}))\ - || ( - [ -n "${destinationfrequency["$destination"]}" ]\ - && (( ${rate:-0} != ${destinationfrequency["$destination"]}))\ - ) || ( - [ -n "${destinationchannels["$destination"]}" ]\ - && (( ${channels:-0} != ${destinationchannels["$destination"]} )) - ) - then - sox_needed=1 - fi - ;; - *) - decodeSox - ;; - esac - ;; - esac - if ! (( copied )) - then - decodeFile - fi + decodeFile getDestDir getDestFile if (( copied )) diff --git a/lib/decode/decodeFile b/lib/decode/decodeFile index b66c6ef..f1e2762 100644 --- a/lib/decode/decodeFile +++ b/lib/decode/decodeFile @@ -1,33 +1,77 @@ #!/bin/bash decodeFile() { - if ! decodetaskid=$( - Select tasks id <<<"key = $tmpfile" - ) - then - decodetaskid=$( - Insert tasks <<-EOInsert - key $tmpfile - source_file $fileid - $( - for key in ${!commandline[@]} - do - echo "cmd_arg$key ${commandline[key]}" - done + case "$mimetype" in + 'audio/mpeg') + if [[ ${destinationformat[$destination]} = mp3 ]] \ + && checkCopy + then + copied=1 + else + decodeSox + fi + ;; + 'application/ogg opus') + if [[ ${destinationformat[$destination]} = opus ]] \ + && checkCopy + then + copied=1 + else + decodeOpusdec + if (( ${destinationnormalize["$destination"]}))\ + || ( + [ -n "${destinationfrequency["$destination"]}" ]\ + && (( ${rate:-0} != ${destinationfrequency["$destination"]}))\ + ) || ( + [ -n "${destinationchannels["$destination"]}" ]\ + && (( ${channels:-0} != ${destinationchannels["$destination"]} )) ) - status 0 - EOInsert - ) - progressSpin - fi - if (( sox_needed )) + then + sox_needed=1 + fi + fi + ;; + 'application/ogg'*) + if [[ ${destinationformat[$destination]} = vorbis ]] \ + && checkCopy + then + copied=1 + else + decodeSox + fi + ;; + 'audio/x-flac') + decodeSox + ;; + *) + extendedtype=$(file -b "$sourcepath/$filename") + case "$extendedtype" in + *'Musepack '*) + decodeMpcdec + if (( ${destinationnormalize["$destination"]}))\ + || ( + [ -n "${destinationfrequency["$destination"]}" ]\ + && (( ${rate:-0} != ${destinationfrequency["$destination"]}))\ + ) || ( + [ -n "${destinationchannels["$destination"]}" ]\ + && (( ${channels:-0} != ${destinationchannels["$destination"]} )) + ) + then + sox_needed=1 + fi + ;; + *) + decodeSox + ;; + esac + ;; + esac + if ! (( copied )) then - cleanup="$tempdir/$tmpfile" - decodeSox "$tempdir/$tmpfile.wav" - if ! soxtaskid=$( + if ! decodetaskid=$( Select tasks id <<<"key = $tmpfile" ) then - soxtaskid=$( + decodetaskid=$( Insert tasks <<-EOInsert key $tmpfile source_file $fileid @@ -37,13 +81,37 @@ decodeFile() { echo "cmd_arg$key ${commandline[key]}" done ) - requires $decodetaskid - required $decodetaskid status 0 - cleanup $cleanup EOInsert ) progressSpin fi + if (( sox_needed )) + then + cleanup="$tempdir/$tmpfile" + decodeSox "$tempdir/$tmpfile.wav" + if ! soxtaskid=$( + Select tasks id <<<"key = $tmpfile" + ) + then + soxtaskid=$( + Insert tasks <<-EOInsert + key $tmpfile + source_file $fileid + $( + for key in ${!commandline[@]} + do + echo "cmd_arg$key ${commandline[key]}" + done + ) + requires $decodetaskid + required $decodetaskid + status 0 + cleanup $cleanup + EOInsert + ) + progressSpin + fi + fi fi } From a0a0fdd37a2b68883fe0a53fc4f16455ecd01fd0 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 29 Apr 2013 23:35:33 +0200 Subject: [PATCH 3/3] decode video files (ffmpeg) --- lib/decode/decodeFile | 4 ++++ lib/video/extractaudio | 6 ++++++ 2 files changed, 10 insertions(+) create mode 100644 lib/video/extractaudio diff --git a/lib/decode/decodeFile b/lib/decode/decodeFile index f1e2762..cc52f01 100644 --- a/lib/decode/decodeFile +++ b/lib/decode/decodeFile @@ -1,6 +1,10 @@ #!/bin/bash decodeFile() { case "$mimetype" in + 'video/'*) + extractAudio + sox_needed=1 + ;; 'audio/mpeg') if [[ ${destinationformat[$destination]} = mp3 ]] \ && checkCopy diff --git a/lib/video/extractaudio b/lib/video/extractaudio new file mode 100644 index 0000000..d8d3344 --- /dev/null +++ b/lib/video/extractaudio @@ -0,0 +1,6 @@ +#!/bin/bash +extractAudio() { + tmpfile="${fileid}ffmpeg" + commandline=(${ionice}ffmpeg -v 0 -vn -y) + commandline+=(-i "$sourcepath/$filename" "$tempdir/$tmpfile.wav") +}