#!/bin/bash #.Y / 70 83 / / / / 105 / / / / / / ;A4_QUER.Y #.YT 3 2 0 0 3 3 1 / / / #.H!a!0:linux//io/video/dvb_/THIS!0.!c # # copyright : (C) 2011 by Thomas Bruecker =: tbrue # email : public0x05bf@bluewin.ch # # tbrue 09dec2011 # # video dvb_ THIS : dvb-functions # +++++++++++++++++++++++++++++++ # # MyHash("linux//io/video/dvb_/THIS") = 0x0XXX # # * for every function: # * if returned result is not commented, the function returns 0 on no-error. SCRIPTS=root/bin . /$SCRIPTS/io/usb/THIS . /$SCRIPTS/time/cron/THIS ConfigurationPath0x0XXX="/usr/local/etc/dvb" ChannelsFile0x0XXX="${ConfigurationPath0x0XXX}/Channels.CONF" StationsFile0x0XXX="${ConfigurationPath0x0XXX}/Stations.CONF" # ^conditional dvb_+stick() # * loads the modules for dvb-stick. # * returns "1" if some module may not be loaded. # * for pinnacle em28xx-dvb-stick. { local Result0x0XXX if dvb_isPCTV320e ; then /sbin/modprobe em28xx_dvb Result0x0XXX=$? if [ ! "$Result0x0XXX" = "0" ]; then # error in modprobe: return $Result0x0XXX fi /sbin/modprobe snd-usb-audio return # result of # "modprobe snd-usb-audio". else return 0 fi } dvb_-stick() # * unloads the modules for dvb-stick. # * returns "1" if some module may not be unloaded. # * for pinnacle PCTV320e-dvb-stick. { local Result0x0XXX if dvb_isPCTV320e ; then /sbin/modprobe -r \ cxd2820r \ dvb_core \ em28xx \ em28xx_dvb \ ir_jvc_decoder \ ir_lirc_codec \ ir_mce_kbd_decoder \ ir_nec_decoder \ ir_rc5_decoder \ ir_rc6_decoder \ ir_sony_decoder \ lirc_dev \ mt352 \ rc_core \ snd_rawmidi \ snd_usb_audio \ snd_usbmidi_lib \ tuner \ tuner_xc2028 \ tveeprom \ tvp5150 \ v4l2_common \ videobuf_core \ videobuf_vmalloc \ zl10353 Result0x0XXX=$? echo you may now safely remove the tv-usb-stick. return $Result0x0XXX # result of # "modprobe -r [...]". else return 0 fi } dvb_2PidFileName() # $1: start-time as "canonical time0" (e.g. "14jun2012-10h36m02"), # $2: station-name. # * writes the pid-file-name to "stdout". # * returns # * "0" if everything is ok. # * "1" on invalid start-time. { local Name Result Station Time Station="$2" Time=$( time_canonicalTime0_2Time "$1" ) Result=$? if [ 0 != $Result ]; then # error in time-command. return $Result fi # else Time="$( time_2sortableTime0 "$Time" )" Result=$? if [ 0 != $Result ]; then # error in time-command. return 1 fi # else echo "${Station}${Time}" return # return result of previous # command. } dvb_isPCTV320e() # returns # * "0" if it is a Pinnacle PCTV320e-stick, # * "1" if it is another stick. { usb_isDevice eb1a 2881 # return result of } # "usb_isDevice ...". dvb_PlanRecord() # $1: start-time as "canonical time0" (e.g. "14jun2012-10h36m02"), # $2: stop-time as "canonical time0", # $3: station-name. # * writes a cron-table-entry to record an emission at the # station = from to . # * returns # * "0" if everything is ok, # * "1" on invalid start-time, # * "2" on invalid stop-time, # * "3" on invalid station, # * "4" on error on pid-filename-generation, # * "5" on error 'adding "start-time" to cron-table', # * "6" on error 'adding "stop-time" to cron-table'. { local PidFileName Result StartTime Station StopTime Station="$3" StartTime="$1" StopTime="$2" cron_2Time "$StartTime" > /dev/null # check time. Result=$? if [ 0 != $Result ]; then # error in time-command. echo "Error: Invalid Start-Time." > /dev/stderr return 1 fi # else cron_2Time "$StopTime" > /dev/null # check time. Result=$? if [ 0 != $Result ]; then # error in time-command. echo "Error: Invalid Stop-Time." > /dev/stderr return 2 fi # else dvb_station2channel "$Station" > /dev/null # check station. Result=$? if [ 0 != $Result ]; then # error in time-command. echo "Error: Station not found." > /dev/stderr return 3 fi # else PidFileName="$(dvb_2PidFileName "$StartTime" "$Station")" Result=$? if [ 0 != $Result ]; then # error in 2Pid... return 4 # should have been checked fi # earlier. # else cron_add "$StartTime" "/root/tmp/dvb/record.bat SF1 $PidFileName" Result=$? if [ 0 != $Result ]; then # error in cron-command. echo -e "Error adding \"Start-Time\" to Cron-table." > /dev/stderr return 5 fi # else cron_Add "$StopTime" "/root/tmp/dvb/StopRecord.BAT $PidFileName" # "Add": ... and reload Result=$? # cron-tables. if [ 0 != $Result ]; then # error in cron-command. echo -e "Error adding \"Stop-Time\" to Cron-table." > /dev/stderr return 6 fi # else return 0 } dvb_station2channel() # maps station-name to channel-name and prints it to stdout. # $1 : station-name. # returns # * "0" if station is found, # * "1" if station is not found. { local False_CONST0xXXX I0x0XXX NotFinished0x0XXX Result0x0XXX local Station0x0XXX True_CONST0x0XXX # constants: False_CONST0x0XXX=0 True_CONST0x0XXX=1 Station0x0XXX="$1" # get stations file: . "${StationsFile0x0XXX}" # for-loop to convert station to channel: NotFinished0x0XXX=${True_CONST0x0XXX}; # allow loop to proceed. for(( I0x0XXX = 0; NotFinished0x0XXX; I0x0XXX++ )); do # terminate loop if "${Channels0x0XXX[$I0x0XXX]}" is empty # -- and perform copy only if ... is not empty: if [ "${Channels0x0XXX[$I0x0XXX]}" == "" ]; then NotFinished0x0XXX=$False_CONST0x0XXX Result0x0XXX=1 else # echo ${Channels0x0XXX[$I0x0XXX]} if [ "${Stations0x0XXX[ ${I0x0XXX} ]}" == "$Station0x0XXX" ] \ ; then echo "${Channels0x0XXX[$I0x0XXX]}" NotFinished0x0XXX=$False_CONST0x0XXX Result0x0XXX=0 fi fi done return $Result0x0XXX }