Hacky Scripts: GetRAM and LoadGuest/SaveGuestPresented at Gloucestershire Linux User Group 17 February 2009 by Andrew Oakley. This was an evening of show-and-tell "Hacky Scripts"; small utility scripts that the speakers had developed themselves and now couldn't live without, but which lacked polish for general release to the public. As such you may find these scripts half-finished, lacking functionality and documentation. The talks aimed to inspire people and spread ideas, rather than present fully-finished products. OpenOffice Presentation: Script source codes: Hacky Scripts
GetRAM Aims
GetRAM
GetRAM Source Code
#!/bin/bash ..lots of setup snipped... # Dump the RealAudio stream # Using -t for timeout after N seconds? if [ "$timeout" == "0" ]; then mplayer -nojoystick -nomouseinput -nolirc -quiet $bandwidthflag -cache 128 -vc null -vo null -dumpstream -dumpfile $filename.rm $ramfile else mplayer -nojoystick -nomouseinput -nolirc -quiet $bandwidthflag -cache 128 -vc null -vo null -dumpstream -dumpfile $filename.rm $ramfile & playerpid=$! sleep $timeout kill $playerpid fi # Convert the RealAudio stream to a PCM file mplayer -nojoystick -nomouseinput -nolirc -quiet -ao pcm:file=$filename.pcm -vo null $filename.rm if [ "$mono" == "y" ]; then # Convert to a mono MP3 lame -h -b $monorate -m m $filename.pcm -o $outfile else # Convert to a stereo MP3 lame -h -b $stereorate -m s $filename.pcm -o $outfile fi # Delete temporary files rm -f $filename.ram rm -f $filename.rm rm -f $filename.pcm # Create MP3 ID3 tags mp3info -a "$artist" -l "$album" -g "Speech" -t "$filename" -y "`date +\"%Y\"`" $outfile echo "Saved as $outfile - done" GetRAM Command Linegetram [-d] [-m] [-t N] http://site/path/filename.ram [outputfilename] -d datestamps yyyymmdd-outputfilename
-m mono 24 kbit/s (default is stereo 96 kbit/s)
-t timeout (stop recording) after N seconds outputfilename is optional. If not given, it will create a default filename YYYYMMDD-HHMMSS-NNNN.mp3 where NNNN is unique-ish based on nanoseconds. Input URL may be a .ra or a .ram URL. If it is a .ram URL, it will attempt to determine the .ra URL. MP3 tags for artist, album and genre are constants in the script. MP3 tag title is exactly as the outputfilename . GetRAM Usage IdeasFor example, a crontab line to record part of The Today Programme on BBC Radio 4, in low bitrate mono, every Monday through Saturday from 7:59am for 35 minutes, and overwrite the previous recording:
#m hh dd mo day command
To record Paul McGann as the Eighth Doctor on BBC7, in medium bitrate stereo, for an hour plus a minute padding each side, on Saturday evenings at 6pm, and datestamp the recording for archival: 59 17 * * SAT /usr/local/bin/getram -d -t 3720 "http://www.bbc.co.uk/bbc7/realplayer/dsatg2.ram" R7-Doctor-Who.mp3 GetRAM Usage Tips
GetRAM To Do List
SaveGuest / LoadGuestLoadGuest / SaveGuestSaveGuest source code#!/bin/bash username=$1 if [[ "$username" == "" ]] then username=visitor fi if [[ -d /home/$username ]] then cd /home mv -f $username.tar.gz $username-old.tar.gz tar cvzf $username.tar.gz $username --exclude="*/.thumbnails/*" --exclude="*cache*" --exclude="*Cache*" chmod 664 $username.tar.gz else echo "/home/$username does not exist or is not a directory" echo "Usage: saveguest [username]" echo "Assumes username 'visitor' if no username supplied" fi LoadGuest source code#!/bin/bash # Goes in /etc/gdm/PostLogin/Default: # #!/bin/bash # if [[ "$LOGNAME" == "visitor" ]] # then # /usr/local/bin/loadguest # fi username=$1 if [[ "$username" == "" ]] then username=visitor fi if [[ -f /home/$username.tar.gz ]] then cd /home rm -rf $username/* tar xvfz /home/$username.tar.gz else echo "/home/$username.tar.gz does not exist or is not a regular file" fi Public Domain - Andrew Oakley - 2009-02-17
Top -
More Broadcasting Articles -
More Computing Articles -
Article Index -
aoakley.com
|