Bash Shell Script + Xhtml Simple Script + Page (1-2 Hours)

Must be completed by November 30th, 2010.

Fix/Complete The script below, sample webpage at http://tinyurl.com/23jgwtu

# Your script will be used to organize a collection of MP3 files.
# Files to be processed are expected to reside in a single directory
# (no sub-directories).

# Your script, must create subdirectories for each artist and
# create symbolic links to each song in appropriate directories.

# The script usage will be as follows:
# momo source_directory [destination directory]

# If the destination directory is not provided, the present working directory
# is the destination.
# The name of the file/link will be based on album and song name
# in the following format: Album – SongTitle.mp3

# Additional information:
# – All song metadata will be based on information in ID3v1 tags
# – Assume that all .mp3 files in the source directory have a valid ID3v1 tag
# (ID3v1 details can be found on-line: http://en.wikipedia.org/wiki/ID3#ID3v1)
# – .mp3 extensions can have any combination of upper- and lower-case letters
# – Assume that you have read permission for the source directory
# and write permission for destination
# – Ignore files in the source directory that do not have the .mp3 extension
# – Display an error message and exit with status 1 if no parameters are given
# – Display an error message and exit with status 2 if source is not a directory
# – Display an error message and exit with status 3 if destination
# does not exist or is not a directory

# In addition to creating a directory/file structure, your script must create
# a valid XHTML report file containing the output of the tree command,
# showing the above structure. The report will also show a footer section
# showing the source directory path, date/time when report was created
# and number of artist and songs organized.

# Your script will produce a single line of output to the shell
# (other than possible error messages), containing two numbers, separated by
# a single space: number of artists processed and number of songs processed.

### TO DO: Check if at least one parameter is supplied, exit on error
if [ $# ]
then
exit
fi

### TO DO: Check if first parameter is a directory, exit on error

# Set the destination to default (pwd) if no destination is provided
if [ $# -lt 2 ]
then
set “$1” .
fi

### TO DO: Check if destination exists and is a directory, exit on error

for song in $(### TO DO: Get the list of mp3 files in the source directory)
do
# Extract the ID3 TAG from file
tag=$(tail -c 128 song)

# Extract the song name and trim space padding
song=$(echo “$tag” | cut -c 4-33 | sed -r ‘s/ +//’)

### TO DO: Extract the artist and album, trim both
### TO DO: Create a directory for artist in the destination directory
### (if not already there)
### TO DO: Create a symbolic link to the song in the artist’s directory
done

### TO DO: Finish the output line to the terminal
echo

cat << TOP > $2/### TO DO: Set the report file name here
<?xml version=”1.0″ encoding=”utf-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en-US” lang=”en-US”>
<head>
<title>ID3 Report Page</title>

### TO DO: Display the tree for the artists/songs directory structure

<style type=”text/css”>
### TO DO: Set the font typeface for the entire report page to $font
### TO DO: Set the font colour for the entire page to $colour
### TO DO: Set the report background to a colour of your choosing
</style>
</head>
<body>
<h2>ID3 Report Page</h2>
TOP

### TO DO: Add the path to the source directory to the report
### TO DO: Add current date/time to the report
### TO DO: Add to the report how many artists and songs were processed
### TO DO: Add the W3C XHTML Validator link and icon to the report
### TO DO: Add the W3C CSS Validator link and icon to the report

echo </body></html> >> $2/### TO DO: Set the report file name here

Leave a Reply

Your email address will not be published. Required fields are marked *