Friday, August 13, 2010

Still adding to the server... Using Mimms to Record MMS Audio Streams in Ubuntu Lucid 10.04

I like to listen to a couple radio shows that stream on the internet, so I am putting all that unused power in my little'ol server to use. I tried to use Mplayer and VLC to record streams, but they seemed too sensitive to connection issues for my taste, so I decided on something made just for the purpose. Mimms. After recording and converting the file to mp3, I save it to a couple of places, like my Dropbox... Now I don't have to remember to sync the player before work.

Mimms is in the repos, but it needs python 2.5 and that isn't, so you need to drop to the command line and do the following
  • sudo nano /etc/apt/sources.list
  • add the following to the end of the file
deb lucid main
deb-src lucid main
  • press O to save (thats the letter)
  • press X to exit
  • Now get the packages with the following
sudo apt-get mimms python25

Now here is an example of my script I use to record a radio show:

#record an audio mms stream and convert it to mp3
#then copy them to a network share, then move them to my Dropbox
#Scott Goodgame 2010
TIMESTAMP=$(date +”%b-%d-%y”)

#(use mimms to record the show for 243 minutes)
mimms -t 243 "mms://AStreamNameGoesHere" /home/jack/radio-to-radio-$TIMESTAMP

#convert asf to wav and then from wav to mp3 (if anybody has a better way to do this, let me know!)
mplayer /home/jack/radio-to-radio-$TIMESTAMP -ao pcm:file=/home/jack/radio-to-radio-$TIMESTAMP.wav
lame /home/jack/radio-to-radio-$TIMESTAMP.wav /home/jack/radio-to-radio-$TIMESTAMP.mp3
#copy the file to the network share, move it to a daily directory and move it to my dropbox, then clean up the mess
cp radio-to-radio-$TIMESTAMP.mp3 /home/jack/Dropbox
cp radio-to-radio-$TIMESTAMP.mp3 /media/other/Audio/Today
mv radio-to-radio-$TIMESTAMP.mp3 /media/other/Audio/Podcasts/radio

rm /home/jack/radio-to-radio-$TIMESTAMP
rm /home/jack/radio-to-radio-$TIMESTAMP.wav

Now, just paste that into a file, put a stream in the mimms line and edit the time on the same line.

My particular show plays every night, so I made it a cron job to run every night- here is the relevant line from my crontab:

# m h dom mon dow command
57 00 * * * /home/jack/bin/record-raido-show

My show starts at 1am, but I start the job early because sometimes it takes a few seconds for mimms to connect and I don't like to miss anything.

I was going to tell you about editing the crontab file, but why reinvent the wheel? Here is a really nice link to get you started....

Happy recording!


A Scanner Server for the, uhm, Server...

I went to to find out how to add a scanner server to my setup, and the directions worked perfectly (almost) I had to add two steps to the setup for it to work on my Ubuntu Lucid 10.04 Server setup, so I am going to mirror his steps and just add my little bit. I have no idea if this situation was caused by an Ubuntu thing, my dumb mistake or some minor oversight in the directions, but either way here we go...

First of all I am installing two scanners to the machine, why you ask? Well because I have two within reach and too much time on my hands at the moment.

First you need to make sure you are ready for the scanner so drop to a command line and do the following.

sudo apt-get install libsane sane-utils

First is a Mustek BearPaw 1200CU Plus like so.

Go ahead and get a file called PS1Dfw.usb from and move it to /usr/share/sane/gt68xx/ then sudo chmod a+w it.

Type sudo scanimage -L and you should see something like this...

device `gt68xx:libusb:001:003' is a Mustek Bearpaw 1200 CU Plus flatbed scanner

What you need to know the numbers immediately following gt68xx:libusb:, in my case 000:003 and try to scan the image from the command line.

sudo chmod a+w /dev/bus/usb/001/003
sudo scanimage gt68xx:libusb:001:003 --resolution 300 --format png > ~/test.png

Of course you want to replace the 001:003 with the numbers you got.

The scanner should work now, so if you happen to be have X installed, simply try to scan with your favorite software. If you happen to be at the command line, then you can test it with this the following.

One scanner down, one to go.. If you are just setting up this scanner, read the little bit after I set up the next scanner. It might apply to you.

Next is a HP Photosmart 2610 all-in one. (the printer installs just fine with cups and is probably auto-detected and set up for you if using the desktop version.
Install the HP software.

sudo apt-get install hplip

Now to find out where on the USB bus it is...


You'll get something like this.

Bus 001 Device 002: ID 03f0:4511 Hewlett-Packard PhotoSmart 2600

You'll need to know the first two numbers 001 and 002 in this case and substitute them into the following command.

sudo hp-makeuri 001:002

Now is time for the actual Scanner Server. The steps I added are in a different font.
sudo su

apt-get install netpbm sane-utils tesseract-ocr-eng apache2

groupadd scanner

adduser www-data scanner

echo 'AddHandler cgi-script .cgi' >> /etc/apache2/apache2.conf

cat /etc/apache2/sites-available/default | sed
's/FollowSymLinksMultiViews/FollowSymLinks MultiViews ExecCGI/g' > /tmp/default

mv /tmp/default /etc/apache2/sites-available/default

/etc/init.d/apache2 restart

cd /var/www


tar -xvvf scan_*.tar

rm scan_*.tar
chmod a+w /dev/bus/usb/001:002

Now that the Server is up, just open a page to the machine running the server like this..

If all went well you are almost done, just one more thing...

Now that the scanner is installed and working, you will need (at least I did) to make the chmod a+w /dev/bus/..... permanent. To do this I modified /etc/rc.local to include the two chmod lines I issued to make them work.

chmod a+w /dev/bus/usb/001/003
chmod a+w /dev/bus/usb/001/002