Music Organizer Script. Don't know where to begin.

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Music Organizer Script. Don't know where to begin.
# 1  
Old 04-04-2012
Music Organizer Script. Don't know where to begin.

I'm having problems with this assignment. I know how to do these basic unix "if" and "then" statements) What I am having trouble with is putting my script together. I started with #!/bin/bash and not sure how to continue. I have to indicate the source and destination folders, and make each a parameter, which I dont know how to do. So could please someone guide me on how to get this script started the right way?

1. The problem statement, all variables and given/known data:

Code:
#!/bin/bash

#########################################################################
# DO NOTE REMOVE OR CHANGE THIS BLOCK WHILE YOU COMPLETE THE ASSIGNMENT
# ASSIGNMENTS COMPLETED WITHOUT THIS BLOCK INTACT WILL NOT BE GRADED
#
# ULI101 - WINTER 2012
# ASSIGNMENT 2 BY: John Doughtski
#
#
# PLEASE REMEMBER THAT SHARING YOUR SOLUTION WITH ANOTHER STUDENT
# IN PART OR IN ENTIRETY IS A VIOLATION OF THE ACADEMIC POLICY
#
# BIGBROTHER COMMAND VERIFIES THAT YOU COMPLETE THE WORK INDEPENDENTLY
# BY RECORDING YOUR PROGRESS AND COLLECTING STATISTICAL DATA
#
# IF YOU DELETE OR DAMAGE THE COMMAND BELOW BY ACCIDENT, YOU CAN RETRIEVE
# THE ORIGINAL BY ISSUING THE ASSIGNMENT START COMMAND AGAIN
bigbrother e5679c3fd97e3d34182b727a9241a3bc4b9db131 momo
#########################################################################

# ASSIGNMENT 2 INSTRUCTIONS, PERSONALIZED FOR jdoughtski

# Create a BASH shell script called momo (My Own Music Organizer)
# in ~/uli101.a2/ directory according to the following specifications:"

# 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
# - .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 2 if no parameters are given
# - Display an error message and exit with status 3 if source is not a directory
# - Display an error message and exit with status 4 if destination
#   does not exist or is not a directory

# TIP: Keep a secure backup of your script outside of other users' access.

# Practice files can be found on matrix in ~uli101/public/songs[1-5]
# directories.  Although they are not actual mp3 files, they contain
# valid ID3v1 tags.

# In addition to creating a directory/file structure, your script must create
# a valid HTML 5 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.

# Although it is not a requirement, feel free to set colours, fonts and other
# visual attributes of your report.


# Place the report file in the output directory and call it: .index.html
# TIP: Have a dedicated testing directory for output and make a symbolic link
# in your ~/public_html directory to your report file in there.
# This way it will be easy to view and validate the report using your browser.

# 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.

# Check your progress using the following command: uli101.a2.check
# Submit your completed assignment using the following command: uli101.a2.submit

# PLEASE NOTE THAT PLAGIARISM CASES WILL BE HANDLED ACCORDING TO THE ACADEMIC
# POLICY. YOUR SCRIPT MUST BE WRITTEN WITHOUT HELP FROM OTHERS AND YOU ARE NOT
# ALLOWED TO ACCESS OTHER STUDENTS' ASSIGNMENTS
# DO NOT SHARE YOUR SOLUTION. ASK ONLY YOUR PROFESSOR FOR HELP.

### 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 path in $(### TO DO: Get the list of mp3 files in the source directory)
do
        # Extract the ID3 TAG from file
        tag=$(tail -c 128 $path)

        # Extract the song name and trim space padding
        song_name=$(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
<!DOCTYPE html>
<html>
<head>
        <title>ID3 Report Page</title>
</head>
<body>
        <h2>ID3 Report Page</h2>
TOP

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

### 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

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

2. Relevant commands, code, scripts, algorithms:
Vi editor, basic unix scripting.



3. The attempts at a solution (include all code and scripts):
Code:
!#/bin/bash

momo source_directory [destination directory]

source="/home/uli101/public/songs1"
destination="/home/jdoughski/uli101.a2"

#Check if at least 1 parameter is supplied, exit on error
if [ $# -lt 1 ]
then
        echo "No parameters found, add at least 1 parameter"
        exit 2
fi

# Make sure first parameter(source) is a directory, exit on error
if [ ! -d "$0" ]
then
        echo "First paramer must be a directory"
        exit 3
fi

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


4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Seneca @ York, Toronto, Ontario, Canada, Mark Buchner, ULI101C


Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by methyl; 04-06-2012 at 12:58 PM.. Reason: insert code tags for readability
# 2  
Old 04-05-2012
I don't think we can help.
Quote:
# PLEASE NOTE THAT PLAGIARISM CASES WILL BE HANDLED ACCORDING TO THE ACADEMIC
# POLICY. YOUR SCRIPT MUST BE WRITTEN WITHOUT HELP FROM OTHERS AND YOU ARE NOT
# ALLOWED TO ACCESS OTHER STUDENTS' ASSIGNMENTS
# DO NOT SHARE YOUR SOLUTION. ASK ONLY YOUR PROFESSOR FOR HELP.
# 3  
Old 04-06-2012
Code:
### TO DO: Check if destination exists and is a directory, exit on error

for path in $(### TO DO: Get the list of mp3 files in the source directory)

You need to edit the supplied script and substitute suitable unix commands wherever the the lecturer has placed a comment line "### TO DO".

For the above command, after editing it might read something like:
Code:
for path in $(find "${source}" -follow -type f -name "*.mp3" -print)

The sample script is correctly structured. You don't need to change the order of the commands - just find the appropriate command each time the lecturer has given a sample line or asked you to insert a line which you have written from scratch.
Big Hint: Comment out the lecturer's incomplete sample lines until you can edit the script to produce valid syntax. This will enable you to build the script line-by-line with valid syntax and debug from the top down.
Another hint: Use echo or printf statements to check the value of variables while you are testing the script.

Quote:
# The script usage will be as follows:
# momo source_directory [destination directory]
In your sample code, the source and destination directories have been set to hard values rather than from parameters supplied when the script was invoked ($1 and optionally $2). This is not correct. There is a lot of useful information in the comments in the lecturer's script.

Good luck.

Last edited by methyl; 04-06-2012 at 01:34 PM.. Reason: grammar, typos
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

2. Programming

Will pay someone to write a script for my music app

Hey guys, not sure I am in the right forum for this, just trying a shot in the dark here. I am using an app on my android to control certain functions on my pc's music player but need to have the app perform 2 specific tasks within my music player so I am looking around for a coder or programmer... (2 Replies)
Discussion started by: mikehende
2 Replies

3. Shell Programming and Scripting

In ksh script what is this BEGIN and END in this function?

Can Someone please explain why BEGIN and END statement is used inside function? How does that help in scripting? function fileformatting { CleanupMask="xXxX" sed 's/^.//' < ${AllFile} > ${AllFile}.tmp echo $(wc -l ${AllFile}.tmp) `awk -v CleanupMask=${CleanupMask} ' BEGIN... (2 Replies)
Discussion started by: later_troy
2 Replies

4. Fedora

Shell Script - awk, begin, for and print

pointsb=`awk -v a2="$a2" -v b2="$b2" -v c2="$c2" -v yb="$yb" -v yc="$yc" \ 'BEGIN { for (y=yc; y<=yb; y++) { x = a2*y*y+b2*y+c2; print x, y }; }'` I am learning shell script. I was reading a script and got confused in this line. I understood that awk is allowing to assign the variable. But... (10 Replies)
Discussion started by: agriz
10 Replies

5. Shell Programming and Scripting

Filter file by length, looking only at lines that don't begin with ">"

I have a file that stores data in pairs of lines, following this format: line 1: header (preceded by ">") line 2: sequence Example.txt: >seq1 name GATTGATGTTTGAGTTTTGGTTTTT >seq2 name TTTTCTTC I want to filter out the sequences and corresponding headers for all sequences that are less... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

6. Shell Programming and Scripting

Building a script to share music with SoundCloud

Thread removed (6 Replies)
Discussion started by: awc228
6 Replies

7. Shell Programming and Scripting

How to skip lines which don't begin with a number

Hi, I have a file: file.txt 1 word 2 word word word 3 word 4 word and I would like to create a set: set number = `cut -d" " -f1 ${1}` #${1} is the text file but it should only contain the lines which begin with numbers, and another set which contains the lines which begin with... (10 Replies)
Discussion started by: shira
10 Replies

8. Shell Programming and Scripting

how to start SCRIPT command at begin of TERMINAL?

Hello sir, I want to monitor my work on the terminal.I know we can use script command.But every time when I start the terminal, I have to type script to start it.I want to automate it. So where should I include this command so that it will start as soon as I start the terminal ???? (2 Replies)
Discussion started by: nsharath
2 Replies
Login or Register to Ask a Question