a small contribution and a question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear VDR hobbyists,

   I would like to contribute a small and simple /bin/bash script that 
imports EPG for Russian channels on HotBird satellities (RTVi*, RTR,
ORT) that only provide program listings via HTTP AFAIK.

   The script should be able to handle other listings, as the only 
Russian-specific part is deduction of the "short description" data
based on the "long description".

   Also, I've got a question about dual DVB-S setup that people may
have installed. Any recommendation on FF/budget card combination is
welcome!

Greetings,

Pjotr Kourzanov
-------------- next part --------------
S13.0E-9472-4688-13 	http://www.rtvi.ru/print/i/e/${Y1}${m1}${d1}_${Y2}${m2}${d2} +0400 RTVi
S13.0E-9472-4688-16 	http://www.rtvi.ru/print/p/e/${Y1}${m1}${d1}_${Y2}${m2}${d2} +0400 RTVi Nashe Kino
S13.0E-9472-4688-18 	http://www.rtvi.ru/print/d/e/${Y1}${m1}${d1}_${Y2}${m2}${d2} +0400 RTVi Detsky Mir
S13.0E-9472-4688-18 	http://www.rtvi.ru/print/r/e/${Y1}${m1}${d1}_${Y2}${m2}${d2} +0400 RTVi TeleClub
S13.0E-176-12600-1708	http://www.rtr-planeta.com/schedule_text?sch_duble=5&flag=2&prg_sel=11 +0400 RTR-Planeta
S13.0E-318-9400-8208	http://www.channelonerussia.com/main.php?allweek=1 +0200 ORT
-------------- next part --------------
#!/bin/bash
wget="/usr/bin/wget -q"
recode="/usr/bin/recode"
awk="/usr/bin/awk"
date="/bin/date"
sort="/usr/bin/sort"
sed="/bin/sed"
tee="/usr/bin/tee"
tail="/usr/bin/tail"
cat="/bin/cat"
netcat="/bin/netcat"
address=/etc/vdr/epg.address
tmp=/tmp/getepg.$$

onexit() { rm -f $tmp; }
trap onexit 0 1 2 3 9 15

a1=(`$date -d 'this monday' +'%Y %m %d'`)
a2=(`$date -d 'this sunday' +'%Y %m %d'`)
today=`$date +'%u'`
Y1=${a1[0]}
m1=${a1[1]}
d1=${a1[2]}
Y2=${a2[0]}
m2=${a2[1]}
d2=${a2[2]}

process() {
	echo "C $id $name"
	$awk $awk_opt -vzone=$zone -vdate=$date -vtoday=$today '
BEGIN {
	day=1-today
	next_day=0
	D["C"]="¼ãÛìâØÚØ" #"Cartoon"
	D["Ä"]=D["F"]="ÄØÛìÜ" #"Film"
	D["¸"]=D["I"]="¸ÝäÞàÜÐæØÞÝÝÐï ßÕàÕÔÐçÐ" #"Info"
	D["Á"]=D["S"]="ÁÕàØÐÛ" #"Series"
	D["Â"]=D["T"]="±Ð×Ðà" #"Talkshow"
	D["R"]="ÀÐ×ÒÛÕÚÐâÕÛìÝÐï ßÕàÕÔÐçÐ" #"Entertainment"
}
function append(a,b)
{
	return a (a ? " " : "") b
}
function process_event(text,descr)
{
	if (!text) return
		
	n=split(text,a,"[ \t\r\n]+")

	for (i=1; i<=n; i++) 
		descr=append(descr,a[i])

	desc[event]=descr
	desc[event]=append(desc[event],"(" specs[event] ")")
	
	for (i=1; i<=n; i++) if (a[i] ~ /^"/) do {
		el=a[i]
		gsub(/"/,"",el)
		title[event]=append(title[event],el)
		if(a[i] ~ /"[.,]?$/) break
		i++
	} while(i<=n)

	if (!title[event]) title[event]=descr
	gsub(/[.,][ \t\r\n]*$/,"",title[event])
	
	if (length(a[n])==1 && a[n] ~ /[FISTĸÁÂ]/) short[event]=D[a[n]]; else
	if (descr ~ /[¼Ü]ãÛìâ[Ää]ØÛìÜ/) short[event]=D["C"]; else #/[Mm]ul.?tfil.?m/
	if (descr ~ /[¼Ü]ãÛìâ[Áá]ÕàØÐÛ/) short[event]=D["C"]; else #/[Mm]ul.?tserial/
	if (descr ~ /Å\/ä/) short[event]=D["F"]; else #/H\/f/
	if (descr ~ /[ºÚ]ØÝÞßÞÒÕáâ/) short[event]=D["F"]; else #/[Ff]il.?m/
	if (descr ~ /[Ää]ØÛìÜ/) short[event]=D["F"]; else #/[Ff]il.?m/
	if (descr ~ /[Áá]ÚÐ×Ú/) short[event]=D["F"]; else #/[Ss]kazk/
	if (descr ~ /[¼Ü]ÕÛÞÔàÐÜ/) short[event]=D["F"]; else #/[Mm]elodram/
	if (descr ~ /[´Ô]àÐÜ/) short[event]=D["F"]; else #/[Mm]elodram/
	if (descr ~ /[´Ô]ÕâÕÚâØÒ/) short[event]=D["F"]; else #/[Dd]etektiv/
	if (descr ~ /[ºÚ]ÞÜÕÔØ/) short[event]=D["F"]; else #/[Kk]omedi/
	if (descr ~ /[Ââ]ÕÐâà/) short[event]=D["R"]; else #/[Tt]eatr/
	if (descr ~ /[ºÚ]ÞÝæÕàâ/) short[event]=D["R"]; else #/[Kk]oncert/
	if (descr ~ /[Ää]ÕáâØÒÐÛ/) short[event]=D["R"]; else #/[Ff]estival/
	if (descr ~ /[Èè]Þã/) short[event]=D["R"]; else #/[Shsh]ow/
	if (descr ~ /[ºÚ]²½/) short[event]=D["R"]; else #/[Kk]VN/
	if (descr ~ /[Îî]ÜÞà/) short[event]=D["R"]; else #/[Juju]mor/
	if (descr ~ /[Áá]ÕàØÐÛ/) short[event]=D["S"]; else #/[Ss]erial/
	if (descr ~ /[²Ò]ÕáâØ/ ) short[event]=D["I"]; else #/Vesti/
	if (descr ~ /[½Ý]ÞÒÞáâØ/) short[event]=D["I"]; else #/Novosti/
	if (descr ~ /[²Ò]àÕÜï/) short[event]=D["I"]; else #/Vremja/
	if (descr ~ /[0-9][0-9][0-9][0-9]/) short[event]=D["F"]
}
match($0,"^[ \t\r\n]*[0-9][0-9]?[.:][0-9][0-9][ \t\r\n]+") {
	time=substr($0,RSTART,RLENGTH)
	gsub(/[ \t\r\n]*/,"",time)
	sub(/\./,":",time)
	sep=index(time,":")
	hour=substr(time,1,sep-1)
	min=substr(time,sep+1)
	oldmins=mins
	mins=hour*60+min
	if (mins < oldmins) next_day=1 
	if (next_day) { 
		day++
		next_day=0
	}
	spec=(day < 0 ? "" : "+") day " day " time " " zone
	cmd=date " -d \"" spec "\" +%s"
	cmd | getline time_t
	close(cmd)
	process_event(text)
	event++
	start[event]=time_t
	specs[event]=spec
	text=""
	$0=substr($0,RSTART+RLENGTH)
}
event in start {
	text=append(text,$0)
}
END {
	process_event(text)
	for (e=1; e <=event; e++) {
		n=e+1
		len=60*60
		if (n in title) len=start[n]-start[e]
		if (len>60*60*3) len=60*60*3
		if (!len || !desc[e]) continue
		print "E",e,start[e],len
		print "T",title[e]
		if (short[e]) print "S",short[e]
		print "D",desc[e]
		print "e"
	}
}
'	< $cache
	echo "c"
}

oid=
i=1

{ 
	echo "pute"
$sort $address | while read id addr zone name; do
	url=
	eval url=$addr
	[[ -z "$url" ]] && url=$addr
	awk_opt=""
	[[ $oid == $id ]] && awk_opt="-vevent=$last_event"
	oid=$id
	echo $id $url $name >/dev/stderr
	cache=/var/cache/vdr/epg/$i.$id.${Y1}${m1}${d1}_${Y2}${m2}${d2}
	[ -r $cache ] || {
		echo -n getting $url... >/dev/stderr
		$wget -O - $url\
		| $sed -e 's,<[^>]*>,,g;s,&quot;,",g;s,&nbsp;,,g'\
		| $recode -f cp1251..iso8859-5 > $cache
		echo done >/dev/stderr
	}
	last_event=`process $cache | $tee $tmp | $sed -ne 's,^E \([0-9]*\) .*,\1,p' | $tail -1`
	$cat $tmp
	i=$[$i+1]
done 
	echo "."
	echo "quit"
} | $netcat -q10 localhost 2001


[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux