Subdomain Posts
None | 54 days ago
Bash | 55 days ago
None | 99 days ago
None | 158 days ago
Recent Posts
None | 5 sec ago
None | 15 sec ago
None | 16 sec ago
None | 16 sec ago
None | 16 sec ago
None | 17 sec ago
None | 17 sec ago
None | 17 sec ago
None | 18 sec ago
None | 19 sec ago
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Azerthoth on the 15th of Jan 2010 07:03:28 AM Download | Raw | Embed | Report
  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
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: