You are not logged in.
hi, i have a little awk script that creates a textfile containing informations of a given set of media files.
what i want now is some script that will execute my awk script on a dir by dir base. After each directory it should append the new tags to the textfile and write some keyword between them.
In practive i have this:
mutagen-inspect $1/* | grep -E '^artist=|^album=|^title|^date|^genre|^totaltracks' | sort | uniq | sed 's/=/::/' > list.txt
This will produce this text file:
artist::Alice In Chains
album::Dirt
date::1992
genre::Grunge
totaltracks::13
title::Them Bones
title::Dam That River
title::Rain When I Die
title::Sickman
title::Rooster
title::Junkhead
title::Dirt
title::God Smack
title::[Iron Gland]
title::Hate To Feel
title::Angry Chair
title::Down In A Hole
title::Would?
what i want now is that the script will walk through a given set of directories recursively and write each output to the same file. in between it should write a keyword.
so in the end i want to have something like this:
artist::Alice In Chains
album::Dirt
date::1992
genre::Grunge
totaltracks::13
title::Them Bones
title::Dam That River
title::Rain When I Die
title::Sickman
title::Rooster
title::Junkhead
title::Dirt
title::God Smack
title::[Iron Gland]
title::Hate To Feel
title::Angry Chair
title::Down In A Hole
title::Would?
EOI
artist::Alice In Chains
album::Sap
date::1992
genre::Grunge
totaltracks::4
title::BLA
title::BLUB
title::DADADA
Last edited by Rasi (2010-05-03 13:53:25)
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
Maybe you should run the script in the given dirs, collect all the output files, add the keywords to the end of the file(s) and 'cat list1 list2 ...'?
Offline
I think the find command will do just what you need. It will look recursively through directories starting at some specified root for files that meet some RE criteria. It can then perform an operation on each of those files (print the name, pass the name as an argument into an executable, etc...)
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way
Offline
echo -e "\nEOI\n" >> list1.txt
should give you the keyword and newlines. Of course you can script this part too :-)
The last part is just gluing the lists back to back 'cat list1 list2 ...'
At least this is how I understand it. Feel free to suggest another way.
Last edited by karol (2010-05-03 14:55:04)
Offline
You should use tee for the script, so you can enter something into read for the keyword, although I didn't really understand that part of your question. This way you can also see the list before you enter the keyword.
{ mutagen-inspect "$1"/* | grep -E '^artist=|^album=|^title|^date|^genre|^totaltracks' | sort | uniq | sed 's/=/::/'
echo
read -p "KEYWORD: "
echo $REPLY
echo
} | tee -a list.txt
Like ewaller said, just put it in a loop like `for file in $(find -type d)` or something like that.
Offline
You should use tee for the script, so you can enter something into read for the keyword, although I didn't really understand that part of your question. This way you can also see the list before you enter the keyword.
{ mutagen-inspect "$1"/* | grep -E '^artist=|^album=|^title|^date|^genre|^totaltracks' | sort | uniq | sed 's/=/::/' echo read -p "KEYWORD: " echo $REPLY echo } | tee -a list.txt
Like ewaller said, just put it in a loop like `for file in $(find -type d)` or something like that.
the keyword is just some fixed sequence of characters. The list is gonna be parsed by a programm afterwards and each keyword will tell the programm that a new item starts now.
Maybe you should run the script in the given dirs, collect all the output files, add the keywords to the end of the file(s) and 'cat list1 list2 ...'?
thats more or less what i am asking about. Its about around 1000 directories so it needs to be automatic
Last edited by Rasi (2010-05-03 15:08:40)
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
Maybe you should run the script in the given dirs, collect all the output files, add the keywords to the end of the file(s) and 'cat list1 list2 ...'?
thats more or less what i am asking about. Its about around 1000 directories so it needs to be automatic
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
> Its about around 1000 directories
Cool :-)
You can still use Procyon's script, just
echo -e "\nEOI\n"
Offline
write_tags() {
# put your $1/* based tag logic here
}
prev_dir=''
while IFS=$'\n' read -r this_dir; do
if [[ -n "$prev_dir" ]] && [[ "$this_dir" != "$prev_dir" ]]; then
echo -e"\nEOI\n" >> file
fi
write_tags "$this_dir" >> file
prev_dir="$this_dir"
done < <(find ./ -type d)
untested, and off the top of my head. but it should work.
Last edited by brisbin33 (2010-05-03 15:17:40)
//github/
Offline
The dir structure can be tricky
[karol@black music]$ l cd_music/Queen/
total 12K
drwxr-xr-x 2 4.0K Sep 6 2009 Greatest Hits [Parlophone]
drwxr-xr-x 2 4.0K Sep 6 2009 Greatest Hits, Vol. 3
drwxr-xr-x 2 4.0K Sep 6 2009 Platinum Collection, Vol. 1-3 Disc 2
I keep my collection of ripped CD's in cd_music. One of them is a 3 CD album Queen - The Greatest Hits. The folder 'Queen' doesn't have any mp3s (as you can see on the listing), but the subfolders do. You may have a different scheme 'Queen - Greatest Hits, Vol. 3' etc. with no top 'Queen' folder - which will make things easier.
audiopath="/home/karol/music"
list="/home/karol/my_list"
for dir in $(find $audiopath -type d); do
mutagen-inspect $dir/* | grep -E '^artist=|^album=|^title|^date|^genre|^totaltracks' | sort | uniq | sed 's/=/::/' >> $list
echo -e "\nEOI\n" >> $list
done
It wouldn't work for me because of the spaces in filenames and foldernames ;P
Offline
Don't forget possible directories inside the album directory for instance for scans of the booklet.
It would be better to look for any tagged audio files and only use the directories those are in.
for mdir in $(
for mfile in find -iname '*.mp3' -o -iname '*.ogg' -o -iname '*.flac' -o -iname '*.whatever I missed'
do dirname "$mfile"
done | sort | uniq
); do script "$mdir"; done
Offline
It would be better to look for any tagged audio files and only use the directories those are in.
That's what I was talking about.
The folder 'Queen' doesn't have any mp3s (as you can see on the listing), but the subfolders do. You may have a different scheme 'Queen - Greatest Hits, Vol. 3' etc. with no top 'Queen' folder - which will make things easier.
Offline
while IFS=$'\n' read -r var; do
# stuff with $var
done < <(find ./ --all-those-options -exec dirname {} \; | sort -u)
would handle spaces and might be more efficient; though, the bikeshed's about the same .
Last edited by brisbin33 (2010-05-03 16:42:08)
//github/
Offline
@karol, yeah the first line was to you, but I forgot that later.
@brisbin33, nice one and certainly setting the IFS is important.
Offline