You are not logged in.
My music library is organized in this (generic) manner: ~/music/artists/albums. I want to show my entire library in a HTML format, which resides in ~/music, let's call it library.html. I want the html file to contain the info as follows:
<div class="loop1">
<h3>the_artist</h3>
<div class="loop2">
<h4>the_album</h4>
<img src="the_folder.jpg" />
</div>
</div>
Just a rough script. What I want to know is, is there a way to parse the directory structure and the files inside them and generate a html file that reflects the actual folder organization? For example, if I have these folders (in each of the "albums" folder, there's a folder.jpg):
music/
--bond
----born
----classified
----shine
then the script would generate:
<div class="loop1">
<h3>bond</h3>
<div class="loop2">
<h4>born</h4>
<img src="bond/born/folder.jpg" />
</div>
<div class="loop2">
<h4>classified</h4>
<img src="bond/classified/folder.jpg" />
</div>
<div class="loop2">
<h4>shine</h4>
<img src="bond/shine/folder.jpg" />
</div>
</div>
The path to the .jpg would be relative to the html file. I hope you understand what I mean, with bad english and all, and any help is appreciated. If you have any question, please ask. Thank you.
Where's my sig?
Offline
Were you after help writing the script, or generating the thumbnail?
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Well, both. The point is to generate a html files that lists the folder names (and subfolders), and shows <img> tag that points to a folder.jpg of the corresponding subfolders. And as of how to achieve that, I still don't know. Any shed of light? How to do this with a script? Manually entering the artis/album/folder.jpg entries would be very daunting task since I currently have a quite large library.
For an example, i have uploaded a "test" folder with the html file, that pretty much shows what I mean. It's here on box.net.
Last edited by prasetyams (2008-07-30 07:40:25)
Where's my sig?
Offline
Something like this? Works on your test file you uploaded.
Just change START_DIR and OUTPUT_FILE to something appropriate.
Now I must go cook dinner for the missus!
#!/bin/bash
function doArtist() {
# Loops through all the albums in the directory passed, then calls doAlbum
ARTIST=$1
echo "<p>" >> $OUTPUT_FILE
echo " <h1>Artist: ${ARTIST}</h1>" >> $OUTPUT_FILE
for ALBUM_DIR in $(${LS} ${START_DIR}${ARTIST}) ; do
echo " Found album ${ALBUM_DIR}... Processing..."
doAlbum $ALBUM_DIR
done
echo "</p>" >> $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
}
function doAlbum() {
# Writes album and image (if present) tags to HTML file
ALBUM=$1
echo " <h2>Album: ${ALBUM}</h2>" >> $OUTPUT_FILE
if [ -f "${START_DIR}${ARTIST_DIR}/${ALBUM}/folder.jpg" ] ; then
echo " Writing image tag"
echo " <img src='${ARTIST_DIR}/${ALBUM}/folder.jpg'>" >> $OUTPUT_FILE
fi
}
# Config Vars
START_DIR='/home/user/Music/' # Make sure it has a trailing slash
OUTPUT_FILE='library.html'
# Binaries
LS='/bin/ls'
CAT='/bin/cat'
# Create or Empty the output file
OUTPUT_FILE=${START_DIR}${OUTPUT_FILE}
echo -n "Creating $OUTPUT_FILE... "
$CAT /dev/null > $OUTPUT_FILE
echo "<html>" >> $OUTPUT_FILE
echo "<head>" >> $OUTPUT_FILE
echo "</head>" >> $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
echo "<body>" >> $OUTPUT_FILE
echo "Done"
# Need to change bash's IFS variable so the for loops will
# handle files and directories with spaces in their name.
IFS="
"
# Start looping through our directories
for ARTIST_DIR in $(${LS} $START_DIR) ; do
if [ -d "$START_DIR$ARTIST_DIR" ] ; then
# This is a directory of an artist
echo "Found artist ${ARTIST_DIR}... Procesing..."
doArtist $ARTIST_DIR
fi
done
# Close off the HTML
echo "</body>" >> $OUTPUT_FILE
echo "</html>" >> $OUTPUT_FILE
exit 0
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
I planed a fews ago to code something similar like this in python. Only difference is to keep a sqlite db up to date and generate some html pages from it. With ID3 tags, etc
Public Key 0x24685E35 available from any key server you trust.
IRC: ssimon/Nesrecar
Offline
@fukawi2: It works. There's a small glitch with apostrophes on folder names though, I need to use %27 in place of apostrophes in the resulting html file. Still wondering how to do that in the script (detect if there's an apostrophe and replace it with %27). I'm learning the script now, and will post the result. Thanks a bunch.
@nesrecar: That would be cool, back in Windows world I used to use iTunes to print albums list.
Last edited by prasetyams (2008-07-30 09:39:40)
Where's my sig?
Offline
Bash string substitution:
VARIABLE=${VARIABLE/\'/%27}
Note the ' is escaped with a back slash. Not sure if that's required, I assume it is. You might need to escape the % too maybe?
Last edited by fukawi2 (2008-07-30 09:41:59)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Um, how to implement the Bash string subst?
Anyway, the result so far is here.
Last edited by prasetyams (2008-07-31 01:46:15)
Where's my sig?
Offline
http://tldp.org/LDP/abs/html/string-manipulation.html
Look at the "Substring Replacment" section (above 9.2.1 near the bottom)
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Okay, I learn a bit. One of the albums contains two apostrophes, so I end up replacing any ' found in the string, just in case. I replaced %27 with its equivalent HTML charset (can't display it here), it works well.
${ALBUM//\'/CHARSET}
Thanks a lot for the help. .
Last edited by prasetyams (2008-07-31 04:43:41)
Where's my sig?
Offline
Pleasure
Are you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline