You are not logged in.
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
#!/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
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
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 .
//github/
Offline
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 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
(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
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
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.
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
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
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
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