MPD has recently gained the "readpicture" command in order to retrieve
cover images embedded in files. This works very similarly to albumart.
We now have the necessary features in mpdexec to implement this in
mpdthumb. When the --embedded option is supplied, the script will
first try readpicture, then albumart for each file specified.
'auto', which queries the server to determine the
appropriate method.
--no-binarylimit Equivalent to --binarylimit=no
'auto', which queries the server to determine the
appropriate method.
--no-binarylimit Equivalent to --binarylimit=no
+ --embedded Attempt to retrieve embedded covers using readpicture.
+ This requires (and implies) --binarylimit.
+ --no-embedded Use only album-level covers. This is the default.
--version Print a version message and then exit.
--help Print this message and then exit.
--version Print a version message and then exit.
--help Print this message and then exit.
--binarylimit=*) opt_binarylimit=${arg#--*=} ;;
--no-binarylimit) opt_binarylimit=no ;;
--binarylimit) opt_binarylimit=yes ;;
--binarylimit=*) opt_binarylimit=${arg#--*=} ;;
--no-binarylimit) opt_binarylimit=no ;;
--binarylimit) opt_binarylimit=yes ;;
+ --embedded) opt_embedded=yes ;;
+ --no-embedded) opt_embedded=no ;;
--size=*) size=${arg#--size=} ;;
--small) size=56 ;;
--size) lastarg=$arg ;;
--size=*) size=${arg#--size=} ;;
--small) size=56 ;;
--size) lastarg=$arg ;;
exec 5>"$tmp" 6<"$tmp"
rm -f "$tmp"
exec 5>"$tmp" 6<"$tmp"
rm -f "$tmp"
+# --embedded implies --binarylimit
+case $opt_embedded in
+yes) use_embedded=true ;;
+*) use_embedded=false ;;
+esac
+$use_embedded && opt_binarylimit=yes
+
# Test for binarylimit command in MPD server. We want to minimize data
# transfer in order to make cache hits as fast as possible.
#
# Test for binarylimit command in MPD server. We want to minimize data
# transfer in order to make cache hits as fast as possible.
#
binarylimit_offset=2147483647
fi
binarylimit_offset=2147483647
fi
-for arg; do
- arg=${arg%/*}/
- shift; set x "$@" "$arg"; shift
+for file; do
+ case $file in
+ */*) dir=${file%/*}/ ;;
+ *) dir=/ ;;
+ esac
- printf '%s\n' "$arg" | sed '/[ \\"'\'']/ {
+ if $use_embedded; then
+ shift; set x "$@" "$file" "$dir"; shift
+ else
+ file=
+ fi
+
+ printf '%s\n' "$dir" ${file:+"$file"} | sed -n '/[ \\"'\'']/ {
s/[\\"]/\\&/g
s/.*/"&"/
}
s/[\\"]/\\&/g
s/.*/"&"/
}
- s/.*/albumart & '"$binarylimit_offset"'/' >&3;
+ s/.*/albumart & '"$binarylimit_offset"'/
+ 1h
+ 2s/^albumart/readpicture/p
+ $ {
+ g
+ p
+ }' >&3;
-<&4 $MPDEXEC --ignore-errors >&5 2>&1 || exit
+valid=
+<&4 $MPDEXEC --verbose --ignore-errors >&5 2>&1 || exit
while read a b <&6; do
case $a in
while read a b <&6; do
case $a in
+ readpicture|albumart)
+ prevn=$# file=$1 mode=$a; shift || exit; continue
+ ;;
+ size:)
+ valid=$mode$#
+ ;;
- *binarylimit*) printf '%s: %s\n' "$argv0" "$a $b" 1>&2; exit 1 ;;
+ *'{binarylimit}'*|*'{readpicture}'*)
+ printf '%s: %s\n' "$argv0" "$a $b" 1>&2; exit 1 ;;
-
- echo; shift || exit; continue ;;
+ test x"$valid" = x"readpicture$prevn" || echo
+ continue
+ ;;
*) continue ;;
esac
# We combine the filename and the size to compute the cache key and
# hope this suffices to detect stale entries. Unfortunately MPD does
# not currently give us the modified date which would be more useful...
*) continue ;;
esac
# We combine the filename and the size to compute the cache key and
# hope this suffices to detect stale entries. Unfortunately MPD does
# not currently give us the modified date which would be more useful...
cache_id=`printf 'MPD:%s:%s' "$file" "$b" | md5sum`
cache_id=${cache_id:+${cache_id%% *}_$size.png}
cache_id=`printf 'MPD:%s:%s' "$file" "$b" | md5sum`
cache_id=${cache_id:+${cache_id%% *}_$size.png}
fi
# Not cached, retrieve the entire image
fi
# Not cached, retrieve the entire image
- $MPDEXEC --binary --download albumart "$file" >&3 || exit
+ $MPDEXEC --binary --download "$mode" "$file" >&3 || exit
<&4 $CONVERT -scale "$size" - "$THUMBNAILDIR/tmp.$cache_id" ||
{ rc=$? rm -f "$THUMBNAILDIR/tmp.$cache_id"; exit $rc; }
mv -f "$THUMBNAILDIR/tmp.$cache_id" "$THUMBNAILDIR/$cache_id"
<&4 $CONVERT -scale "$size" - "$THUMBNAILDIR/tmp.$cache_id" ||
{ rc=$? rm -f "$THUMBNAILDIR/tmp.$cache_id"; exit $rc; }
mv -f "$THUMBNAILDIR/tmp.$cache_id" "$THUMBNAILDIR/$cache_id"