Before the lab you should re-read the relevant lecture slides and their accompanying examples.
Create a new directory for this lab called lab03, change to this directory, and fetch the provided code for this week by running these commands:
$ mkdir lab03
$ cd lab03
$ 2041 fetch lab03
Or, if youre not working on CSE, you can download the provided code as a zip file or a tar file.
Write a shell script jpg2png.sh which converts all images in JPEG format in the current directory to PNG format.
You can assume that JPEG files and only JPEG files have the suffix jpg.
If the conversion is succesful the JPEG file should be removed.
Your script should stop with the error message shown below and exit status 1 if the PNG file already exists.
$ wget https://cgi.cse.unsw.edu.au/~cs2041/20T2/activities/jpg2png/images.zip$ unzip images.zip Archive: images.zip inflating: Johannes Vermeer The Girl With The Pearl Earring.jpg inflating: nautilus.jpg inflating: panic.jpg inflating: penguins.jpg inflating: shell.jpg inflating: stingray.jpg inflating: treefrog.jpg$ ./jpg2png.sh$ lsJohannes Vermeer The Girl With The Pearl Earring.png jpg2png.sh panic.png shell.png treefrog.png images.zip nautilus.png penguins.png stingray.png $ wget https://cgi.cse.unsw.edu.au/~cs2041/20T2/activities/jpg2png//penguins.jpg$ lsJohannes Vermeer The Girl With The Pearl Earring.png jpg2png.sh panic.png penguins.png stingray.png images.zip nautilus.png penguins.jpg shell.png treefrog.png$ ./jpg2png.sh penguins.png already exists |
When you think your program is working, you can use autotest to run some simple automated tests:
$ 2041 autotest jpg2png
Autotest Results
95% of 447 students who have autotested jpg2png.sh so far, passed all autotest tests.
97% passed test jpg2png_0
96% passed test jpg2png_1
97% passed test jpg2png_2
96% passed test jpg2png_3
When you are finished working on this exercise, you must submit your work by running give:
$ give cs2041 lab03_jpg2png jpg2png.sh
before Tuesday 23 June 17 59 to obtain the marks for this lab exercise.
Write a shell script email_image.sh which given a list of image files as arguments displays them one-by-one. After the user has viewed each image the script should prompt the user for an e-mail address. If the user does enter an email address, the script should prompt the user for a message to accompany the image and then send the image to the specified e-mail address.
$ ./email_image.sh penguins.png treefrog.png
Address to e-mail this image to? [email protected] Message to accompany image? Penguins are cool. penguins.png sent to [email protected]
Address to e-mail this image to? [email protected] Message to accompany image? This is a White-lipped Tree Frog treefrog.png sent to [email protected]
Hints
The program display(1) can be used to view image files
The program mutt(1) can be used to send mail from the command line including attachments, for example:
$ echo Penguins are cool.|mutt -s penguins! -e set copy=no -a penguins.png [email protected]
There is no autotest and no automarking of this question.
When you are finished working on this exercise, demonstrate your work to another student in your lab and ask them to enter a peer assessment. It is preferred you do this during your lab, but if this is not possible you may demonstrate your work to any other COMP(2041|9044) student before Tuesday 23 June 17 59. Note, you must also submit the work with give.
When you are finished working on this exercise, you must submit your work by running give:
$ give cs2041 lab03_email_image email_image.sh
before Tuesday 23 June 17 59 to obtain the marks for this lab exercise.
Write a shell script date_image.sh which, given a list of image files as arguments, changes each file so it has a label added to the image indicating the time it was taken. You can assume the last-modification time of the image file is the time it was taken.
So for example if we run these commands:
$ cp -p /web/cs2041/20T2/activities/date_image/penguins.jpg .
$ ls -l penguins.jpg
-rw-rr 1 andrewt andrewt 58092 Mar 16 16:08 penguins.jpg
$ ./date_image.sh penguins.jpg
$ display penguins.jpg
There is no autotest and no automarking of this question.
When you are finished working on this exercise, demonstrate your work to another student in your lab and ask them to enter a peer assessment. It is preferred you do this during your lab, but if this is not possible you may demonstrate your work to any other COMP(2041|9044) student before Tuesday 23 June 17 59. Note, you must also submit the work with give.
When you are finished working on this exercise, you must submit your work by running give:
$ give cs2041 lab03_date_image date_image.sh
before Tuesday 23 June 17 59 to obtain the marks for this lab exercise.
Andrew regularly spends time far from the internet and streaming music services such as Spotify, so he has a large collection of MP3 files containing music.
Andrew has a problem: the ID3 tags in the MP3 files in his music collection are incorrect. Unfortunately Andrews favourite player software organises music using the information from these ID3 tags. Your task it to fix Andrews problem by set the ID3 tags to the correct values. Fortunately the correct value for the tags can be retrieved from the file names and the names of the directories the files are in.
Your task is to write a shell script tag_music.sh, which sets the ID3 tags of MP3 files using the information from file names and directory names.
Youll first need to make a copy of Andrews music collection.
Download music.zip, or copy it to your CSE account using the following command:
$ cp -n /web/cs2041/20T2/activities/tag_music/music.zip .
You assume the names of files and directories follow a standard format. You can determine this format by look at ethe files in Andrews music collection.
$ unzip music.zip Archive: music.zip creating: music/ creating: music/Triple J Hottest 100, 2007/ inflating: music/Triple J Hottest 100, 2007/2 Straight Lines Silverchair.mp3 inflating: music/Triple J Hottest 100, 2007/10 Dont Fight It The Panics.mp3
The command id3 can be used to list the value of ID3 tags in an MP3 file. For example:
$ id3 -l music/Triple J Hottest 100, 2013/1 Riptide Vance Joy.mp3 music/Triple J Hottest 100, 2013/1 Riptide Vance Joy.mp3:
Title : Andrew Rocks Artist: Andrew
Album : Best of Andrew Year: 2038, Genre: Unknown (255) Comment: Track: 42
But, as you can see, the ID3 tags of this music file have been accidentally over-written. The ID3 tags should be:
$ id3 -l music/Triple J Hottest 100, 2013/1 Riptide Vance Joy.mp3 music/Triple J Hottest 100, 2013/1 Riptide Vance Joy.mp3:
Title : Riptide Artist: Vance Joy
Album : Triple J Hottest 100, 2013 Year: 2013, Genre: Unknown (255) Comment: Track: 1
Fortunately, all the information needed to fix the ID3 tags is available in the name of the file and the name of the directory it is in.
You will write a shell script tag_music.sh which takes the name of 1 or more directories as arguments and fixes the ID3 tags of the all MP3 files in that directory. For example:
$ ./tag_music.sh music/Triple J Hottest 100, 2015$ id3 -l music/Triple J Hottest 100, 2015/4 The Less I Know the Better Tame Impala.mp3 music/Triple J Hottest 100, 2015/4 The Less I Know the Better Tame Impala.mp3:Title : The Less I Know the Better Artist: Tame ImpalaAlbum : Triple J Hottest 100, 2015 Year: 2015, Genre: Unknown (255)Comment: Track: 4$ ./tag_music.sh music/*$ id3 -l music/Triple J Hottest 100, 1995/10 Greg! The Stop Sign!! TISM.mp3 music/Triple J Hottest 100, 1995/10 Greg! The Stop Sign!! TISM.mp3:Title : Greg! The Stop Sign!! Artist: TISMAlbum : Triple J Hottest 100, 1995 Year: 1995, Genre: Unknown (255)Comment: Track: 10$ id3 -l music/Triple J Hottest 100, 1999/1 These Days Powderfinger.mp3 music/Triple J Hottest 100, 1999/1 These Days Powderfinger.mp3:Title : These Days Artist: Powderfinger Album : Triple J Hottest 100, 1999 Year: 1999, Genre: Unknown (255)Comment: Track: 1$ id3 -l music/Triple J Hottest 100, 2012/2 Little Talks Of Monsters and Men.mp3 music/Triple J Hottest 100, 2012/2 Little Talks Of Monsters and Men.mp3: Title : Little Talks Artist: Of Monsters and Men Album : Triple J Hottest 100, 2012 Year: 2012, Genre: Unknown (255)Comment: Track: 2 |
Your script should determine Title, Artist, Track, Album, and Year from the directory and filename.
Your script should not change the Genre or Comment fields.
Hints
$ man id3
cut almost works for extracting Title and Album from the filename.
Handling the few MP3 files correctly where using cut doesnt work will be considered a challenge exercise.
It can be difficult debugging your script on Andrews music collection. In cases like these it usually worth creating a smaller data set for initial debugging. Such a tiny data set is available in tiny_music.zip if you want to use it for debugging. This dataset is used in the first autotests.
2020/7/24first autotests.
Download tiny_music.zip, or copy it to your CSE account using the following command:
$ cp -n /web/cs2041/20T2/activities/tag_music/tiny_music.zip .
$ unzip tiny_music.zip Archive: tiny_music.zip creating: tiny_music/ creating: tiny_music/Album1, 2015/ inflating: tiny_music/Album1, 2015/2 Little Talks Of Monsters and Men.mp3 inflating: tiny_music/Album1, 2015/1 Riptide Vance Joy.mp3 creating: tiny_music/Album2, 2016/ inflating: tiny_music/Album2, 2016/2 Royals Lorde.mp3 inflating: tiny_music/Album2, 2016/1 Hoops The Rubens.mp3$ id3 -l tiny_music/*/*.mp3 tiny_music/Album1, 2015/1 Riptide Vance Joy.mp3: Title : Andrew Rocks Artist: AndrewAlbum : Best of Andrew Year: 2038, Genre: Unknown (255) Comment: Track: 42 tiny_music/Album1, 2015/2 Little Talks Of Monsters and Men.mp3:Title : Andrew Rocks Artist: AndrewAlbum : Best of Andrew Year: 2038, Genre: Unknown (255) Comment: Track: 42 tiny_music/Album2, 2016/1 Hoops The Rubens.mp3: Title : Andrew Rocks Artist: AndrewAlbum : Best of Andrew Year: 2038, Genre: Unknown (255) Comment: Track: 42 tiny_music/Album2, 2016/2 Royals Lorde.mp3:Title : Andrew Rocks Artist: AndrewAlbum : Best of Andrew Year: 2038, Genre: Unknown (255)Comment: Track: 42$ ./tag_music.sh tiny_music/* $ id3 -l tiny_music/*/*.mp3 tiny_music/Album1, 2015/1 Riptide Vance Joy.mp3: Title : Riptide Artist: Vance JoyAlbum : Album1, 2015 Year: 2015, Genre: Unknown (255) Comment: Track: 1 tiny_music/Album1, 2015/2 Little Talks Of Monsters and Men.mp3:Title : Little Talks Artist: Of Monsters and Men Album : Album1, 2015 Year: 2015, Genre: Unknown (255) Comment: Track: 2 tiny_music/Album2, 2016/1 Hoops The Rubens.mp3:Title : Hoops Artist: The Rubens Album : Album2, 2016 Year: 2016, Genre: Unknown (255) Comment: Track: 1 tiny_music/Album2, 2016/2 Royals Lorde.mp3: Title : Royals Artist: Lorde Album : Album2, 2016 Year: 2016, Genre: Unknown (255)Comment: Track: 2 |
When you think your program is working, you can use autotest to run some simple automated tests:
$ 2041 autotest tag_music
Autotest Results
72% of 106 students who have autotested tag_music.sh so far, passed all autotest tests.
79% passed test 1993_7
88% passed test 1994
80% passed test 1995_1996
88% passed test 1999
85% passed test 2009_2
74% passed test all
88% passed test tiny_album1 tiny_album2
84% passed test tiny_both
When you are finished working on this exercise, you must submit your work by running give:
$ give cs2041 lab03_tag_music tag_music.sh
before Tuesday 23 June 17 59 to obtain the marks for this lab exercise.
2020/7/24
The test data for the previous question is not really Andrews music collection. All the mp3 files contain identical contents. The directories and filenames were created from the source of this web page.
Write a shell script create_music.sh which uses the above webpage to create exactly the same directories and files as in the test data set supplied above.
Your script should take 2 arguments: the name of an MP3 file to use as the contents of the MP3 files you create and the directory in which to create the test data. For example:
$ wget https://cgi.cse.unsw.edu.au/~cs2041/20T2/activities/create_music/sample.mp3$ mkdir my_fake_music$ ls my_fake_music$ ./create_music.sh sample.mp3 my_fake_music$ ls my_fake_musicTriple J Hottest 100, 1993 Triple J Hottest 100, 1998 Triple J Hottest 100, 2003 Triple J Hottest 100, 2008 Triple J Hottest 100, 2013Triple J Hottest 100, 1994 Triple J Hottest 100, 1999 Triple J Hottest 100, 2004 Triple J Hottest 100, 2009 Triple J Hottest 100, 2014Triple J Hottest 100, 1995 Triple J Hottest 100, 2000 Triple J Hottest 100, 2005 Triple J Hottest 100, 2010 Triple J Hottest 100, 2015Triple J Hottest 100, 1996 Triple J Hottest 100, 2001 Triple J Hottest 100, 2006 Triple J Hottest 100, 2011 Triple J Hottest 100, 2016Triple J Hottest 100, 1997 Triple J Hottest 100, 2002 Triple J Hottest 100, 2007 Triple J Hottest 100,2012 Triple J Hottest 100, 2017$ ls my_fake_music/Triple J Hottest 100, 20171 Humble Kendrick Lamar.mp3 5 The Deepest Sighs, the Frankest Shadows Gang of Youths.mp310 What Can I Do If the Fire Goes Out? Gang of Youths.mp3 6 Green Light Lorde.mp32 Let Me Down Easy Gang of Youths.mp3 7 Go Bang Pnau.mp33 Chateau Angus & Julia Stone.mp3 8 Sally Thundamentals featuring Mataya.mp34 Ubu Methyl Ethel.mp3 9 Lay It on Me Vance Joy.mp3$ wget https://cgi.cse.unsw.edu.au/~cs2041/20T2/activities/create_music/music.zip$ unzip music.zip $ diff -r music my_fake_music$ |
When you think your program is working, you can use autotest to run some simple automated tests:
$ 2041 autotest create_music
Autotest Results
62% of 32 students who have autotested create_music.sh so far, passed the autotest test.
When you are finished working on this exercise, you must submit your work by running give:
$ give cs2041 lab03_create_music create_music.sh
before Tuesday 23 June 17 59 to obtain the marks for this lab exercise.
When you are finished each exercises make sure you submit your work by running give.
You can run give multiple times. Only your last submission will be marked.
Dont submit any exercises you havent attempted.
2020/7/24
If you are working at home, you may find it more convenient to upload your work via gives web interface.
Remember you have until Tuesday 23 June 17 59 59 to submit your work.
You cannot obtain marks by e-mailing your code to tutors or lecturers.
You check the files you have submitted here.
Automarking will be run by the lecturer several days after the submission deadline, using test cases different to those autotest runs for you. (Hint: do your own testing as well as running autotest.)
After automarking is run by the lecturer you can view your results here. The resulting mark will also be available via gives web interface.
Reviews
There are no reviews yet.