You are not logged in.

#1 2011-08-27 07:33:33

Murray_B
Member
From: Germany
Registered: 2008-07-29
Posts: 134

tv-star.sh, a little script for managing tv.

Hi altogether!

I wanted a very small app to watch and record tv with my dvb-t stick, so I created tv-star.sh:

#!/bin/bash
#
# Befor you start, you need to edit the 2 
# variables SCANBASE and MOVIEFOLDER
#
# This is the base-file for the frequency-scan.
# Chose the one corresponding to your location.
SCANBASE="/usr/share/dvb/dvb-t/de-Schleswig-Holstein"

# Folder where the movies are stored.
# IMPORTANT: Use the full path, don't use ~ for your home!
# Example:
# MOVIEFOLDER="/home/tux/tv/"
MOVIEFOLDER=""


echo -e "\n***********************************"
echo "***        tv-star 0.5          ***"
echo "***     by Thomas Schuetz       ***"
echo "***********************************"

MAINLOOP=1
if [ "$MOVIEFOLDER" == "" ]; then
   MAINLOOP=0
   echo -e "\nYou need to edit the variables SCANBASE and MOVIEFOLDER in the top of the script before you can use it.\n"
fi


while [ ${MAINLOOP} -gt 0 ]; do
   echo -e "\n"
   echo "1) Watch TV"
   echo "2) Record a movie"
   echo "3) Cancel the record of a movie"
   echo "4) Watch recorded movie"
   echo "5) Delete recorded movie"
   echo "8) Show informationen about tv-star.sh"
   echo "9) Create new channel.conf"
   echo "0) Quit"
   echo -e -n "\nYour choice: "
   read INPUT
   echo -e "\n"
   case $INPUT in
      1) echo "Please chose the station you want to watch:"
         NUMBER=0
         for LINE in `cat ~/.mplayer/channels.conf | sed  s/:.*//`; do
            NUMBER=$((NUMBER+1))
            echo -n ${NUMBER}") "
            echo ${LINE};
         done
         echo -e -n "\nYour choice: "
         read STATION
         STATIONNAME=`tail -n +$STATION ~/.mplayer/channels.conf | head -n 1 | sed s/:.*//`
         mplayer dvb://${STATIONNAME}
         ;;
      2) echo "Please chose the station where you want to record a movie:"
         NUMBER=0
         for LINE in `cat ~/.mplayer/channels.conf | sed  s/:.*//`; do
            NUMBER=$((NUMBER+1))
            echo -n ${NUMBER}") "
            echo ${LINE};
         done
         echo -e -n "\nYour choice: "
         read STATION
         RECORDSTATION=`tail -n +${STATION} ~/.mplayer/channels.conf | head -n 1 | sed s/:.*//`
         echo -e -n "\nWhen do you want to start the record (Format: 20:15)? "
         read RECORDSTART
         echo -e -n "\nWhen do you want to end the record (Format: 22:00)? "
         read RECORDEND
         echo -e -n "\nHow should the file be named? "
         read RECORDFILE
         echo "mplayer -quiet dvb://${RECORDSTATION} -dumpstream  -dumpfile ${MOVIEFOLDER}${RECORDFILE}" | at ${RECORDSTART}
         echo "killall mplayer" | at ${RECORDEND}
         echo 
         ;;
      3) echo "Available at-jobs:"
         atq
         echo "I will always cancel the start- and the end-job, please only enter the number of the start-job (the one with the lower number)!"
         echo -e -n "\nWhich job do you want to cancel (0 = none): "
         read JOB
         if [ ${JOB} -gt 0 ]; then
            atrm ${JOB}
            KILLJOB=$((${JOB}+1))
            atrm ${KILLJOB}
         fi
         ;;
      4) echo "Recorded movies:"
         NUMBER=0
         for LINE in `ls ${MOVIEFOLDER}`; do
            NUMBER=$((NUMBER+1))
            echo -n ${NUMBER}") "
            echo ${LINE};
         done
         echo -e -n "\nWhich movie do you want to watch (0 = none): "
         read MOVIEFOLDERNUMBER
         NUMBER=0
         if [ ${MOVIEFOLDERNUMBER} -gt 0 ]; then
            for LINE in `ls ${MOVIEFOLDER}`; do
               NUMBER=$((NUMBER+1))
               if [ $((NUMBER)) == $((MOVIEFOLDERNUMBER)) ]; then
                  MOVIEFOLDERNAME=${LINE}
               fi
            done
            mplayer ${MOVIEFOLDER}${MOVIEFOLDERNAME}
         fi
         ;;
      5) echo "Recorded movies:"
         NUMBER=0
         for LINE in `ls ${MOVIEFOLDER}`; do
            NUMBER=$((NUMBER+1))
            echo -n ${NUMBER}") "
            echo ${LINE};
         done
         echo -e -n "\nWhich movie do you want to delet (0 = none): "
         read MOVIEFOLDERNUMBER
         NUMBER=0
         if [ ${MOVIEFOLDERNUMBER} -gt 0 ]; then
            for LINE in `ls ${MOVIEFOLDER}`; do
               NUMBER=$((NUMBER+1))
               if [ $((NUMBER)) == $((MOVIEFOLDERNUMBER)) ]; then
                  MOVIEFOLDERNAME=${LINE}
               fi
            done
            rm -i ${MOVIEFOLDER}${MOVIEFOLDERNAME}
         fi
         ;;
      8) echo "About tv-star.sh 0.5 by Thomas Schuetz, 2011-08-27:"
         echo "---------------------------------------------------"
         echo -n "There are great mediacenter-projects like MythTV, but they are too big for "
         echo -n "my simple needs. In fact, you only need one single line to record a movie, "
         echo -n "but I was too lazy to type the long line always by myself, so I created this "
         echo "little script and put everything in it, I need for handling tv."
         echo -n "The script itself is very simple, it only needs mplayer, the scan-command "
         echo -n "from the dvb-apps and some standard shell-commands. Before you really use it, "
         echo "you need to edit the variables SCANBASE and MOVIEFOLDER in the top of the script."
          ;;
      9) echo -e "Creating a new channel.conf, please wait a while!\n"
         rm -f ~/.mplayer/channels.conf.old
         mv ~/.mplayer/channels.conf ~/.mplayer/channels.conf.old
         scan $SCANBASE | sed -e 's/\ /_/g' -e 's/\//_/g' -e 's/\*//' > ~/.mplayer/channels.conf
         ;;
      0) echo -e "Thank you for using tv-star.sh!\n"
         MAINLOOP=0
         ;;
      *) echo -e "Wrong input, please chose again!\n"
         ;;
   esac
done

I am no programmer, so if you have any ideas how I can make the script better, please tell me!

Offline

#2 2011-08-27 08:25:38

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: tv-star.sh, a little script for managing tv.

Some improvements:

diff --git a/tv-star.sh b/tv-star.sh
index a9b6666..3bfe603 100644
--- a/tv-star.sh
+++ b/tv-star.sh
@@ -8,25 +8,16 @@
 SCANBASE="/usr/share/dvb/dvb-t/de-Schleswig-Holstein"
 
 # Folder where the movies are stored.
-# IMPORTANT: Use the full path, don't use ~ for your home!
-# Example:
-# MOVIEFOLDER="/home/tux/tv/"
-MOVIEFOLDER=""
+MOVIEFOLDER=~/tv/
+mkdir -p $MOVIEFOLDER
 
-
-echo -e "\n***********************************"
+echo
+echo "***********************************"
 echo "***        tv-star 0.5          ***"
 echo "***     by Thomas Schuetz       ***"
 echo "***********************************"
 
-MAINLOOP=1
-if [ "$MOVIEFOLDER" == "" ]; then
-   MAINLOOP=0
-   echo -e "\nYou need to edit the variables SCANBASE and MOVIEFOLDER in the top of the script before you can use it.\n"
-fi
-
-
-while [ ${MAINLOOP} -gt 0 ]; do
+while :; do
    echo -e "\n"
    echo "1) Watch TV"
    echo "2) Record a movie"
@@ -40,7 +31,7 @@ while [ ${MAINLOOP} -gt 0 ]; do
    read INPUT
    echo -e "\n"
    case $INPUT in
-      1) echo "Please chose the station you want to watch:"
+      1) echo "Please choose the station you want to watch:"
          NUMBER=0
          for LINE in `cat ~/.mplayer/channels.conf | sed  s/:.*//`; do
             NUMBER=$((NUMBER+1))
@@ -139,9 +130,9 @@ while [ ${MAINLOOP} -gt 0 ]; do
          scan $SCANBASE | sed -e 's/\ /_/g' -e 's/\//_/g' -e 's/\*//' > ~/.mplayer/channels.conf
          ;;
       0) echo -e "Thank you for using tv-star.sh!\n"
-         MAINLOOP=0
+         break
          ;;
       *) echo -e "Wrong input, please chose again!\n"
          ;;
    esac

Last edited by JohannesSM64 (2011-08-27 08:30:45)

Offline

Board footer

Powered by FluxBB