Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to extract cover album art from mpc? (Read 24212 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to extract cover album art from mpc?

If using foobar, data is added at the end of the file enclosed in APE tag.

How to extract this from terminal? mpcdec doesn't have much options

How to extract cover album art from mpc?

Reply #1
There's Apetag for reading/writing APE tags, but I don't think it supports extraction of pictures. Maybe it'll dump the data as is? If so, maybe you could take the data and save it to a file… Or you could just run foobar with wine.

How to extract cover album art from mpc?

Reply #2
Here is brute force extractor for JPG files and size to 1MB (just in case):

Code: [Select]
x=`xxd -g0 "$1" | grep -im1 FFD8FFE0  | awk -F: '{print $1}'`
if [ -n "$x" ]; then
    y=`xxd -g0 "$1" | grep -im1 4150455441474558d0 | awk -F: '{print $1}'`
    if [ $((0x$y)) -gt $((0x$x)) ] && [ 1000000 -gt $((0x$y-0x$x)) ]; then
        dd ibs=1 count=$((0x$y-0x$x+2)) skip=$((0x$x+1)) if="$1" of=${1%.*}.jpg
    fi
fi


It expects mpc (or any other file with JPG inside) as argument
It's rather fragile, as can fail if searched signatures are wrapped by `xxd`, but it's better than no solution

How to extract cover album art from mpc?

Reply #3
There's Apetag for reading/writing APE tags, but I don't think it supports extraction of pictures. Maybe it'll dump the data as is? If so, maybe you could take the data and save it to a file… Or you could just run foobar with wine.


skamp, thanks for suggestion.
It dump cover simply with "./apetag -i input.mpc > out.dat" but has text at start and at the end, so "dd" has to be used again

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:

Code: [Select]
#!/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

How to extract cover album art from mpc?

Reply #5
I don't think it supports extraction of pictures. Maybe it'll dump the data as is? If so, maybe you could take the data and save it to a file… Or you could just run foobar with wine. ??
GuL