Archive

Archive for the ‘Tech Talk’ Category

Turning a protected RTSP stream into an iTunes PodCast (with linux and OSX)

January 1st, 2009 Bed 1 comment

A friend of mine does a radio show interstate that interests me. Unfortunately, being a late night show (midnight) and interstate, for me to listen to this live would require me being awake at 4am or so. Due to record label copyright permissions, this show is not available as a podcast download – its only available for live or delayed streaming. Undeterred, I wanted to automatically grab the stream and make it available on my iPhone for listening when it suited me, while out and about.

Getting the stream as a file with linux

The availability of the delayed stream, means this problem can be tackled with a cronjob on my gentoo linux server. This particular stream is served with the Real Time Streaming Protocol which means all we really need is the live555 media libraries. For Gentoo this was as easy as issuing “emerge live” as root on the commandline. For Ubuntu this would be “apt-get install liblivemedia-utils”.

Then its as simple as calling openRTSP with the stream url. ie:

openRTSP -4 -a -t -d 3900 rtsp://streaming.server.com.au:80/streaming.server.com.au/name.mp4 1>name.mp4

This will write the audio stream  as a file.

The next step is to automate this process with a script being launched by cron. In this case, the name of the stream is in the format radioshow_YY_MM_DD.mp4. So my script will grab today’s stream.
radioshow.sh:

#!/bin/sh
filename="radioshow_"`eval date +%Y-%m-%d`".mp4"
openRTSP -a -t -4 -d 7300 rtsp://streaming.server.com.au:80/streaming.server.com.au/$filename > /mnt/download/radioshow/$filename

Since this show is a weekly one, my crontab is setup to download the stream at 1:30pm every thursday.

crontab line:

#download behind the mirror every thursday at 1:30pm
30 13 * * 4       /home/bed/radioshow.sh

Converting to a PodCast with OSX

Once we have the files, I wanted to put it in my iTunes library flagged as a PodCast. A commandline tool AtomicParsley enables us to set the appropriate mp4 tags so iTunes sees the file as a PodCast, however AtomicParsley doesn’t like the mp4 tags created by openRTSP. To get around this we can load our file in QuickTime, and then re-export it to mp4. This will now be a file with mp4 tags that AtomicParsley can modify. We can then execute the following command:

AtomicParsley name.mp4 --podcastFlag true --artist name --title name --advisory explicit --description name --podcastURL name --podcastGUID 1 --year "2008-12-25" --overWrite

This will create a new file, which we can then drag into iTunes. This will now show up as a proper PodCast, so it will automatically sync to my iPhone and then be removed once I’ve listened to it.

Now that’s a fair bit of manual mucking around, so we can use AppleScript to automate all of this in one nice move, which can be the scheduled with launchd to occur at a convenient time:

-- This script does the following:
-- + looks in a directory in my file server and copies it file locally,
-- + loads it into quick time, and exports it to add proper tags
-- + sets podcast tags with AtomicPasley
-- + imports it into iTunes
-- + cleans up files

mount volume "afp://bedentoo/download" as user name "XXXXXXXX" with password "YYYYYYYYY"
tell application "Finder"
	repeat until ((name of every disk contains "download") as boolean)
		delay 2
	end repeat
end tell

set source_location to "download:radioshow"

tell application "Finder"
	set new_file to {get name of files of folder source_location} as text
	with timeout of 7200 seconds --2 hour timeout, incase we're copying over a VPN or something
		copy {file new_file of folder source_location} to desktop
	end timeout
end tell

-- Use QuickTime to export it (to set proper mp4 tags)
set user to do shell script "whoami"
set local_new_file to {"/Users/" & user & "/Desktop/" & new_file} as text
set local_fixed_file to {"/Users/" & user & "/Desktop/" & new_file & ".fixed.mp4"} as text
tell application "QuickTime Player"
	activate
	close every window
	open local_new_file
	with timeout of 1800 seconds -- half hour timeout incase export takes a while
		export front document to local_fixed_file as MPEG4 using default settings
	end timeout
end tell
quit application "QuickTime Player"

-- our file is always the format of ccccccccccccccccYYYY-MM-DD.mp4 so lets extract the date
copy characters 17 through 26 of new_file as string to datestamp

-- run AtomicParsley (located in ~/scripts/) to flag it as a podCast
set run_ap to {"/Users/" & user & "/scripts/AtomicParsley " & local_fixed_file & " --podcastFlag true --artist radioshow --title 'radioshow '" & datestamp & " --advisory explicit --album radioshow --description radioshow --podcastURL 'http://www.url.au/shows/radioshow' --podcastGUID 1234 --year '" & datestamp & "' --overWrite"} as text
do shell script run_ap

-- import file into iTunes
tell application "iTunes"
	activate
	add ({POSIX file local_fixed_file})
end tell

--cleanup!
tell application "Finder"
	delete {POSIX file local_new_file}
	delete {POSIX file local_fixed_file}
	delete {file new_file of folder source_location}
end tell

Lastly, the applescript is saved as an .app and scheduled with launchd via lingon, which runs at 8am friday morning.

Backing up an OSX profile to a linux server with rsync

December 31st, 2008 Bed 3 comments

TimeMachine is some nice software, but its overkill for me. I’ve previously written about this and how I put together a rsync solution and why I did so. In the case that anyone might be interested in doing the same, here is my setup.

Linux Server
I have a gentoo linux server, but this should be a mostly generic rsync server setup. My rsyncd.conf looks like this

# /etc/rsyncd.conf
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
use chroot = yes
read only = no
uid = bed
gid = bed
hosts allow = 192.168.42.0/24

[bed-backup]
        path=/mnt/backup/bed
        comment = Beds Backup

and of course rsyncd is in my /etc/init.d and starts automatically at boot.

OSX
I have a simple bash script that I can run that will backup the contents of my home directory, called backup_bed.sh. This will turn sleep off, make sure the network is available (as the machine may have been woken from sleep) and then do the backup.

#!/bin/sh
#Bed's rsync backup script

echo `date` Beds Backup > last_backup.log
echo `date` ------------- >> last_backup.log
echo `date` Script Starting at `date` >> last_backup.log

# turn off system sleep
pmset -a sleep 0 2>&1 >> last_backup.log
echo `date` Turned off sleep >> last_backup.log

echo `date` ------------- >> last_backup.log

# wait for network to show up
pingcount=0
trycount=1
failflag=0
while [ $pingcount -eq 0 ]
do
    echo `date` Waiting for network... $trycount >> last_backup.log
    pingcount=$(/sbin/ping -c 3 -o bedentoo | grep "received" | awk -F',' '{ print $2 }' | awk '{ print $1 }')
    trycount=`expr $trycount + 1`
    if [ $trycount -eq 11 ]
    then
        echo `date` network fail - giving up >> last_backup.log
        failflag=1
        pingcount=-1
    fi
done

if [ $failflag -eq 0 ]
then
        #do rsync
        echo `date` RSync started.  >> last_backup.log
        /usr/bin/rsync -a -x -S -v -v --progress --exclude-from=/Users/bed/scripts/backup_excludes.txt  /Users/bed/ bedentoo::bed-backup 2>&1 >> last_backup.log
        echo `date` RSync finished.  >> last_backup.log
fi

#turn system sleep back on
echo `date` ------------- >> last_backup.log
pmset -a sleep 30 2>&1 >> last_backup.log
echo `date` Turned on sleep for 30 min >> last_backup.log

echo `date` Script Finished  >> last_backup.log
echo `date` ------------- >> last_backup.log

I exclude non-essential stuff from my backup, notably temporary files and my virtual machines. These excludes are specified in the backup_excludes.txt file:

- .Trash
- Downloads
- temp
- Caches
- Parallels

And finally, the backup_bed.sh script is run every morning at 8am by launchd. The easiest way to configure launchd is with a nice GUI tool called Lingon. This is created as a User Daemon.

Finally my OSX is configured to automatically wake up a minute before the launchd runs (via System Preferences -> Energy Saver -> Scheduler). If for some reason the machine is actually off, launchd will run the script as soon as it can when the machine is next booted. (launchd is a very nice system).

One note of warning, this setup will not properly support Classic MacOS resource forks. These are nolonger used in OSX, however if you maintain a classic MacOS enviroment, you can backup to a OSX server (not a linux server) and use the -E option of OSX’s rsync.

Categories: Tech Talk Tags: , , , ,

Bed’s Top Five Jailbroken iPhone Apps

December 6th, 2008 Bed 2 comments

The iPhone is my favourite internet-enabled mobile device – and I’ve used quite a few; I write software for Windows Mobile devices at work (and I hate Windows Mobile). But I don’t wear rose-coloured glasses, the iPhone and Apple aren’t flawless. Thus I fill the holes by jailbreaking my phone (running unauthorised by Apple applications). When an iPhone firmware update comes out I patiently wait until the jailbreaking community has updated too. To jailbreak your iPhone browse through the iphone-dev’s blog. Once you’re jailbroken, Cydia is pre-installed, and serves as the equivalent to Apple’s AppStore for getting Apps. Here are my top five reasons to jailbreak my iPhone.

Swirly MMS

Swirly MMS

Swirly MMS

The lack of MMS support on the iPhone has been discussed greatly on the webisphere. Apple made a conscious decision to leave MMS out in favour of encouraging email (which can achieve the same result). However my wife doesn’t have an internet plan enabled on her phone. Now while the only MMS’s we send each other are usually of cute cats or dogs, its nice to be able to do so. Swirly MMS gives full MMS support for US$8, with a free 14 day trial. It works seamlessly and as expected. While you have to manually enter your carrier’s SMS network details, there are numerous listings for all the major carriers for you to reference. MMS notifications come through in a similar manner to standard SMS notifications. 

Read more…

Bed’s Top Five Useful iPhone Apps

December 6th, 2008 Bed No comments

Following on from Bed’s Top Five Essential iPhone Apps, here are my top five useful iPhone Apps. These aren’t used on a daily basis – but are useful to have around for when they may be required.

IM+ Lite

IM+ Lite

IM+ Lite

Its always handy to have an Instant Messenger application around. While I don’t need always-on-push instant messaging on my iPhone – having the ability to log on and talk to someone quickly can be useful. Just the other month I was relaying technical support to a work colleague while in a busy loud shopping mall. It was much easier via IM than trying to talk on the phone through all the noise. IM+ Lite isn’t fancy, but it supports pretty much all IM protocols (AIM®/iChat, MSN®/Windows Live™ Messenger, Yahoo!®, ICQ®, Jabber®, Google™ Talk and MySpaceIM) and is free.

Read more…

Tetris & the iPhone

November 20th, 2008 Bed No comments

A new blog, The Tetromino is detailing the issues surrounding developing a tetris-like game on the iPhone. It looks to be an interesting read in the months ahead.

Categories: Tech Talk, Tetris Tags: , ,