You are not logged in.

#1 2009-10-07 08:18:31

dyscoria
Member
Registered: 2008-01-10
Posts: 1,007

BASH:Searching for missing cover art (looking for ideas, not a script)

Not looking for someone to write a BASH script for me, but just for ideas on the best way to go about this so that I can write a suitable BASH script.

Music directory is like this:

Music
--> AC_DC
      --> Back In Black
            --> 01 - Hells Bell.flac
            --> 02 - Shoot To Thrill.flac
            --> etc
            --> cover.jpg
--> Artist
      --> Album 1
            --> Disc 1
                  --> songs
            --> Disc 1
                  --> songs
      --> Album 2
etc etc

This is my solution so far:

Obviously not all directories need a cover.jpg. So do a find -iname '*.flac' to list directories that actually contain music. Then use parameter expansion to remove the filename and leave the directory. Use sort to remove duplicates. Then to search within this list of directories for cover.jpg to determine which ones are missing album art.

Any better methods of doing this?

Thanks

Last edited by dyscoria (2009-10-07 08:19:12)


flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)

Offline

#2 2009-10-07 14:27:13

scj
Member
From: Sweden
Registered: 2007-09-23
Posts: 158

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

#!/bin/bash

medialib=$HOME/Music
test(){ find $medialib -iname $1 | sed 's|\(.*\)/.*|\1|' | sort | uniq ; }
diff <(test '*.jpg') <(test '*.flac') | grep '^>' | sed 's|^> ||'

Should give you the folders that are lacking coverart.

Offline

#3 2009-10-07 15:09:23

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

BTW you can use these with diff so you don't need to change the output: --old-line-format='' --unchanged-line-format=''

This is called set complement, isn't it?

Offline

#4 2009-10-07 15:35:16

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

your idea is basically right, i'd do this:

find ~/Music -iname '*.flac' -exec dirname {} \; | sort | uniq

that'll list unique directories containing flac files.  use for or while to loop on that and check [ -f $i/cover.jpg ] && echo COVER || echo NO COVER

*this script basically writes itself from there, but you said you didn't want one so i left it openended big_smile.

Offline

#5 2009-10-10 09:21:40

dyscoria
Member
Registered: 2008-01-10
Posts: 1,007

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

Thanks guys! Can't believe I've never discovered dirname! Would have made my life so much easier over the years.

Here's the quick unfancy solution i've come up with so far that echos the folders that are missing artwork (though you guys should use "sort -u" instead of "sort | uniq"):

#!/bin/bash

MUSICDIR='/data/Music'
TMPFILE='/tmp/checkart.files'

cd "${MUSICDIR}" || exit 1
find -iname '*.flac' -exec dirname {} \; | sort -u > "${TMPFILE}"

totalnumber="$(cat "${TMPFILE}" | wc -l)"
line='1'

until [ "${line}" -gt "${totalnumber}" ]; do
    folder="$(sed -n "${line}p" "${TMPFILE}")"
        cd "${folder}" || exit 1
        if [ ! -f 'cover.jpg' ]; then
            echo "${folder}"
        fi
        cd "${MUSICDIR}"
        line="$((${line}+1))"
done

rm -rf "${TMPFILE}"

Coding is so much quicker when you know exactly what it is you need to do. I spend half my time fannying about thinking what the optimal solution would be for a problem. Then when I've finally come up with something, I find out it really isn't optimal at all tongue Meh

Last edited by dyscoria (2009-10-10 09:25:37)


flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)

Offline

#6 2009-10-10 14:50:26

scj
Member
From: Sweden
Registered: 2007-09-23
Posts: 158

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

dyscoria wrote:

(though you guys should use "sort -u" instead of "sort | uniq")

No, we shouldn't. "sort | uniq" is self documenting, while "sort -u" isn't.

Offline

#7 2009-10-10 15:07:45

klixon
Member
From: Nederland
Registered: 2007-01-17
Posts: 525

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

you could also do this, instead of the totalnumber, line and until stuff:

while read folder; do
    if [ ! -f "${folder}/cover.jpg"]; then
        echo "${folder}"
    fi
done < "${TMPFILE}"

Stand back, intruder, or i'll blast you out of space! I am Klixon and I don't want any dealings with you human lifeforms. I'm a cyborg!

Offline

#8 2009-10-10 19:45:19

dyscoria
Member
Registered: 2008-01-10
Posts: 1,007

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

scj wrote:
dyscoria wrote:

(though you guys should use "sort -u" instead of "sort | uniq")

No, we shouldn't. "sort | uniq" is self documenting, while "sort -u" isn't.

What do you mean by self documenting? sort -u is faster so that's why I thought it would be better for this situation.

klixon wrote:

you could also do this, instead of the totalnumber, line and until stuff:

while read folder; do
    if [ ! -f "${folder}/cover.jpg"]; then
        echo "${folder}"
    fi
done < "${TMPFILE}"

Hmm that is very nice indeed! Thanks!


flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)

Offline

#9 2009-10-11 01:48:23

Garns
Member
Registered: 2008-05-28
Posts: 239

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

dyscoria wrote:
scj wrote:
dyscoria wrote:

(though you guys should use "sort -u" instead of "sort | uniq")

No, we shouldn't. "sort | uniq" is self documenting, while "sort -u" isn't.

What do you mean by self documenting? sort -u is faster so that's why I thought it would be better for this situation.

When you have some knowledge about bash/shell scripting you can grasp the meaning of sort | uniq in one look but probably have to consult the manpage when you see sort -u. Of course if you intend to use this script only once and only for yourselve you don't have to care. On the other hand, if you look at it in 3 month and have to look at the manpage to find out what sort -u does, you will care.

Offline

#10 2009-10-11 08:17:50

dyscoria
Member
Registered: 2008-01-10
Posts: 1,007

Re: BASH:Searching for missing cover art (looking for ideas, not a script)

Garns wrote:
dyscoria wrote:
scj wrote:

No, we shouldn't. "sort | uniq" is self documenting, while "sort -u" isn't.

What do you mean by self documenting? sort -u is faster so that's why I thought it would be better for this situation.

When you have some knowledge about bash/shell scripting you can grasp the meaning of sort | uniq in one look but probably have to consult the manpage when you see sort -u. Of course if you intend to use this script only once and only for yourselve you don't have to care. On the other hand, if you look at it in 3 month and have to look at the manpage to find out what sort -u does, you will care.

Ahhh I see. That makes sense smile


flack 2.0.6: menu-driven BASH script to easily tag FLAC files (AUR)
knock-once 1.2: BASH script to easily create/send one-time sequences for knockd (forum/AUR)

Offline

Board footer

Powered by FluxBB