SHARE
TWEET

Azerthoth

a guest Jan 13th, 2010 560 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. # first we flush to make sure we wont be catching the wrong resources
  11. killall mplayer
  12. killall mencoder
  13.  
  14. # 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
  15. location=/mnt/tvstor
  16.  
  17. # set filename
  18. filename=$(date +%H:%M:%S@%d-%h-%Y)
  19.  
  20. # start mencoder
  21. # tv card on composite input and ntsc, mpeg format and mp3 audio
  22. # some of these settings may need to be changed to match your system or your personal preferences
  23. ((mencoder tv:// -tv driver=v4l2:input=1:norm=0:width=640:height=480:device=/dev/video0:adevice=/dev/dsp:forceaudio -ovc lavc -lavcopts vcodec=mpeg4:vbitrate=1200 -oac mp3lame -o $location/$filename.avi -v &) &)
  24.  
  25. # 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
  26. sleep 5
  27.  
  28. # start watching the TV show
  29. ((mplayer $location/$filename.avi &) &)
  30.  
  31. # give mplayer a moment to start before watching for its pid
  32. sleep 2
  33.  
  34. # watch for mplayer close and then close mencoder
  35. while [ "$(pidof mplayer)" ]
  36. do
  37.         sleep 1
  38. done
  39. killall mencoder
  40.  
  41. # graphical delete or save file using dialog/xdialog
  42. # change DIALOG=Xdialog to DIALOG=dialog if you want the box in the terminal session. Only if script it started via a terminal.
  43. DIALOG=${DIALOG=Xdialog}
  44.  
  45. $DIALOG --title "Save TV Show" --clear \
  46.         --yesno "Do you wish to keep the file ?" 8 60
  47.  
  48. case $? in
  49.   0)
  50.     clear ;;
  51.   1)
  52.     rm $location/$filename.avi ;;
  53. esac
RAW Paste Data
Want to get better at Bash?
Learn to code Bash in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top