PDA

View Full Version : Linux mp3 server status script


spankers
03-02-2005, 09:09 AM
How many of you have
(a)large mp3 collections and
(b)use a Linux box as a mp3 server?

I set up an old POS 300 MHz AMD K6 box as a mp3 server, Samba (Windows Network) server, and print server for my house. With Samba (http://us1.samba.org/samba/) running under Linux you can use networked mp3 players like the Audiotron (http://www.turtlebeach.com/site/products/audiotron/) that only work with Windows networking.

While I was ripping about 300 of my girlfriend's CD's I thought it would be nice to have the server create a current list of songs, calculate the size of the collection, calculate recent changes, report mp3 errors, and email me the results... so I wrote a not-so-beautiful shell script called by cron once a day. Here it is:
#!/bin/bash

cd /music
MP3SPACERAW=`du -s | tr -d "."`
MP3SPACEMB=`echo "scale=1; $MP3SPACERAW/1024" | bc`
MP3ARTISTS=`find /music -type d -maxdepth 1 | grep -c ""`
MP3DIRS=`find /music -type d -mindepth 2 | grep -c ""`
MP3SONGS=`find /music ! -type d -name "*.mp3" | grep -c ""`
MP3DIRAVG=`echo "scale=1; $MP3SPACEMB/$MP3DIRS" | bc`
MP3SONGAVG=`echo "scale=1; $MP3SPACEMB/$MP3SONGS" | bc`

DATE=`date "+%G%m%d-%R"`
FILEDATE=`date "+%g%m%d%k%M"`

cp /public/stats/mp3list.txt /public/stats/archive/mp3list-$FILEDATE.txt

printf "Summary information for the MP3 collection on server SATURN follows: \n" > /public/stats/summary.txt
printf "Artists/Top Level Directories: $MP3ARTISTS\t Albums: $MP3DIRS\t Songs: $MP3SONGS\n" >> /public/stats/summary.txt
printf "MP3 space used on partition: $MP3SPACEMB megabytes\n" >> /public/stats/summary.txt
printf "Average Album Size: $MP3DIRAVG megabytes\t Average Song Size: $MP3SONGAVG megabytes\n\n" >> /public/stats/summary.txt
printf "Recent changes (in diff format) and ID3 tag errors below.\n" >> /public/stats/summary.txt
printf "See attached ZIP file for latest song list.\n\n\n" >> /public/stats/summary.txt

find /music ! -type d -name "*.mp3" -exec mp3info -p "%-33a%-33l%02n %-30t\t[%r k]\n" {} \; \
2> /public/stats/mp3error.txt | sort > /public/stats/mp3list.txt.new

diff /public/stats/mp3list.txt /public/stats/mp3list.txt.new > /public/stats/mp3diff.txt
cat /public/stats/mp3diff.txt | cut -d "[" -f 1 > /public/stats/mp3updates.txt
cp /public/stats/mp3list.txt.new /public/stats/mp3list.txt

zip -jf /public/stats/mp3list /public/stats/mp3list.txt

cat /public/stats/summary.txt \
/public/stats/mp3updates.txt \
/public/stats/mp3error.txt | \
/usr/local/bin/nail \
-s "Saturn MP3 statistics for $DATE" \
-a /public/stats/mp3list.zip \
-r edward.xxxx@xxxx.net \
edward.xxxx@xxxx.net

sleep 10

/usr/local/sbin/nullmailer-send

It uses three programs that are not standard on most Linux boxes but are readily available on the net--
mp3info, a VERY flexible id3 tag tool
nail, a command line replacement for mail
nullmailer, a single shot SMTP program... I have not need for sendmail or exim.

The mail it sends:
Summary information for the MP3 collection on server SATURN follows:
Artists/Top Level Directories: 307 Albums: 589 Songs: 8186
MP3 space used on partition: 53952.3 megabytes
Average Album Size: 91.5 megabytes Average Song Size: 6.5 megabytes

Recent changes (in diff format) and ID3 tag errors below.
See attached ZIP file for latest song list.

3514a3515,3526
> Jack Kevorkian and Morpheus Qu A Very Still Life 01 Whispering-Came Violets
> Jack Kevorkian and Morpheus Qu A Very Still Life 02 Summertooth
> Jack Kevorkian and Morpheus Qu A Very Still Life 03 Brotherhood Of
> Jack Kevorkian and Morpheus Qu A Very Still Life 04 A Very Still Life
> Jack Kevorkian and Morpheus Qu A Very Still Life 05 August To Amber
> Jack Kevorkian and Morpheus Qu A Very Still Life 06 Fuguetta Caffeine
> Jack Kevorkian and Morpheus Qu A Very Still Life 07 Interlude-unfinished minuet
> Jack Kevorkian and Morpheus Qu A Very Still Life 08 In Strange Loops
> Jack Kevorkian and Morpheus Qu A Very Still Life 09 Back At Abby's
> Jack Kevorkian and Morpheus Qu A Very Still Life 10 Interlude-gavat
> Jack Kevorkian and Morpheus Qu A Very Still Life 11 Geoff's Mood
> Jack Kevorkian and Morpheus Qu A Very Still Life 12 Une Lettre de Jean
5036d5047
< Pink Floyd The Wall 01 Hey You
5038d5048
< Pink Floyd The Wall 02 Is There Anybody Out There
5041d5050
< Pink Floyd The Wall 03 Nobody Home
5043d5051
< Pink Floyd The Wall 04 Vera
5045,5046d5052
< Pink Floyd The Wall 05 Bring The Boys Back Home
< Pink Floyd The Wall 06 Comfortably Numb
5049d5054
< Pink Floyd The Wall 07 The Show Must Go On
5051,5052d5055
< Pink Floyd The Wall 08 In The Flesh
< Pink Floyd The Wall 09 Run Like Hell
5055d5057
< Pink Floyd The Wall 10 Waiting For The Worms
5057d5058
< Pink Floyd The Wall 11 Stop
5059d5059
< Pink Floyd The Wall 12 The Trial
5061c5061,5073
< Pink Floyd The Wall 13 Outside The Wall
---
> Pink Floyd The Wall 14 Hey You
> Pink Floyd The Wall 15 Is There Anybody Out There
> Pink Floyd The Wall 16 Nobody Home
> Pink Floyd The Wall 17 Vera
> Pink Floyd The Wall 18 Bring The Boys Back Home
> Pink Floyd The Wall 19 Comfortably Numb
> Pink Floyd The Wall 20 The Show Must Go On
> Pink Floyd The Wall 21 In The Flesh
> Pink Floyd The Wall 22 Run Like Hell
> Pink Floyd The Wall 23 Waiting For The Worms
> Pink Floyd The Wall 24 Stop
> Pink Floyd The Wall 25 The Trial
> Pink Floyd The Wall 26 Outside The Wall

/music/Firewater/Psychopharmacology/02-Psychopharmacology.mp3 is corrupt or is not a standard MP3 file.
/music/Rasputina/How We Quit the Forest/16-silence.mp3 is corrupt or is not a standard MP3 file.
/music/Tom Waits/Small Change/03-Jitterbug Boy Sharing A Curbstone With Chuck E Weiss Robert Marchese Paul Bo.mp3 is corrupt or is not a standard MP3 file.


Like I said, the script is not-so-beautiful but does the job and hopefully it provides some ideas for your mp3 server.

spankers
03-02-2005, 09:14 AM
Oh... and here's a sample of the mp3 list the script generates.

Asylum Street Spankers Hot Lunch 01 Cakewalk [256 k]
Asylum Street Spankers Hot Lunch 02 I Don't Wanna [256 k]
Asylum Street Spankers Hot Lunch 03 Trippin' Over You [256 k]
Asylum Street Spankers Hot Lunch 04 U.F.O. Attack [256 k]
Asylum Street Spankers Hot Lunch 05 If I Were You [256 k]
Asylum Street Spankers Hot Lunch 06 Colonel Josh's B.B.Q. [256 k]
Asylum Street Spankers Hot Lunch 07 Hot Lunch [256 k]
Asylum Street Spankers Hot Lunch 08 Blue Prelude [256 k]
Asylum Street Spankers Hot Lunch 09 Smells Like Thirty-Something [256 k]
Asylum Street Spankers Hot Lunch 10 Fanny [256 k]
Asylum Street Spankers Hot Lunch 11 Island Angel [256 k]
Asylum Street Spankers Hot Lunch 12 A Smo-o-oth One [256 k]
Asylum Street Spankers Hot Lunch 13 Bijou [256 k]
Asylum Street Spankers Hot Lunch 14 Sad Bomber [256 k]

dang
03-02-2005, 09:19 AM
thats pretty cool!

spankers
03-02-2005, 09:37 AM
Thanks! Like I said... it needs cleaning. I could add
PATH=
MP3PATH=
MP3STATPATH=

etc, ad nauseum....

spankers
03-02-2005, 09:55 AM
The mp3 list again... the format gets screwed up when pasted to a web page... I use a monospace font in the editor I use: