SHARE
TWEET

Azerthoth

a guest Jan 15th, 2010 731 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # a simple script to watch tv with the ability to play/pause using mplayer
  4. # can be run as a script or put in /usr/bin and run as an application
  5. # if in /usr/bin be sure to chmod 755 what ever you name this so that it will be executable
  6. #
  7. # written by Jim Cook
  8. # azerthoth@gmail.com
  9. #
  10. # Script Version 2 added file rename, cleaned things up for those not using xdialog
  11. #               broke mencoder command apart for easier reading and added deinterlacing
  12. #
  13. # first we flush to make sure we wont be catching the wrong resources
  14. killall mplayer > /dev/null 2>&1
  15. killall mencoder > /dev/null 2>&1
  16.  
  17. # set the location to save the file to. This MUST be set even if you have no intention of keeping any of the programming you watch
  18. location=/mnt/tvstor
  19.  
  20. # set filename
  21. filename=$(date +%H:%M:%S@%d-%h-%Y)
  22.  
  23. # start mencoder
  24. # tv card on composite input and ntsc, mpeg format and mp3 audio
  25. # some of these settings may need to be changed to match your system or your personal preferences
  26. ((mencoder tv:// -tv driver=v4l2:input=1:norm=0:device=/dev/video0:adevice=/dev/dsp:forceaudio \
  27.   -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1200 -vf pp=ci,scale=640:480 \
  28.   -oac mp3lame \
  29.   -o $location/$filename.avi -v &) &)
  30.  
  31. # give mencoder time to start before starting mplayer. too short a time will trigger the kill due to mplayer not finding a file to play
  32. sleep 5
  33.  
  34. # start watching the TV show
  35. ((mplayer $location/$filename.avi &) &)
  36.  
  37. # give mplayer a moment to start before watching for its pid
  38. sleep 1
  39.  
  40. # watch for mplayer close and then close mencoder
  41. while [ "$(pidof mplayer)" ]
  42. do
  43.         sleep 1
  44. done
  45. killall mencoder
  46.  
  47. # pause to let mencoder shut down, not needed if using xdialog
  48. sleep 1
  49.  
  50. # graphical save/rename or delete file.
  51. # change DIALOG=Xdialog to DIALOG=dialog if you want the box in the terminal session. Only if script is started via a terminal.
  52. # we put clear here to get rid of random text from terminal, not needed if running xdialog
  53. clear
  54. DIALOG=${DIALOG=Xdialog}
  55. $DIALOG --title "Save TV Show" --clear \
  56.         --yesno "Do you wish to keep the file ?" 8 60
  57.  
  58. case $? in
  59.   0)
  60.     tempfile=`tempfile`
  61.     $DIALOG --title "Rename Video File" --clear \
  62.             --inputbox "Rename $filename.avi\n
  63.             Adding .avi is not needed" 10 55 2> $tempfile
  64.     retval=$?
  65.     rename=`cat $tempfile`
  66.       if [ -n "$rename" ];
  67.         then rename=$rename
  68.         else rename=$filename
  69.       fi
  70.     mv $location/$filename.avi $location/$rename.avi;;
  71.   1)
  72.     rm $location/$filename.avi;;
  73. esac
  74. # clear terminal if no using xdialog
  75. clear
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top