How to extract cover album art from mpc?
Reply #4 –
Sorry for this, but if some mod can delete little script in post #3 it would be great. Thanks
I did lazy googling instead doing it myself, and that snippet is not accurate as it's just correct for my test sample. Problem is that byte offset (read by awk) is address of first byte in default 16 octet line where match is found
I corrected that, added 64 octets (max 256) to avoid more possible wrapping search signatures, and made search for closing APETAGEX offset from start signature position:
#!/bin/bash
start_pos=`xxd -g0 -c64 "$1" | grep -m1 ffd8ffe0`
offset=`echo $start_pos | cut -d: -f1`
correction=`echo $start_pos | cut -d' ' -f2 | sed 's/ffd8ffe0.*//'`
start_pos=$((0x$offset+${#correction}/2))
if [ $start_pos -gt 0 ]; then
end_pos=`xxd -g0 -c64 -s 0x$(printf '%x\n' $start_pos) "$1" | grep -m1 4150455441474558d0`
offset=`echo $end_pos | cut -d: -f1`
correction=`echo $end_pos | cut -d' ' -f2 | sed 's/4150455441474558d0.*//'`
end_pos=$((0x$offset+${#correction}/2))
if [ $end_pos -gt $start_pos ] && [ 1000000 -gt $(($end_pos-$start_pos)) ]; then
dd ibs=1 count=$(($end_pos-$start_pos)) skip=$start_pos if="$1" of="${1%.*}.jpg"
fi
else
echo 'No JPG cover found in APE tag'
fi
Sorry again for this gibberish, I didn't planed to do this
Cheers