пятница, 14 августа 2009 г.

ТВ программа в Меню и notify_send


Программа с Яндекса, отображает несколько программ в ближайший час
Файл tv.php
#!/usr/bin/php
 ?php
$file = implode("",file("http://tv.yandex.ru"));

preg_match_all('/(? = span class="location">Телеканал ).*(?= \/span>)/',$file, $matches3);
preg_match_all('/(? =id=\d\d\d\d\d\d\d\d">)[0-9][:][0-9][0-9]|[0-9][0-9][:][0-9][0-9](?= \/a>)/',$file, $matches1);
preg_match_all('/(? = \/span> span class="summary">).*(?= \/span> span class="location">)/', $file, $matches2);

for($i=0; $i count($matches1[0]); $i++)
{
if($matches1[0][$i]  = 9) {$tim = "0".$matches1[0][$i];}
else $tim = $matches1[0][$i];
$text = $text.$tim." - ".$matches3[0][$i]." - ".strip_tags($matches2[0][$i])."\n";
}

//echo $text;
$fil = fopen("tv.txt","w+");
$fw=fputs($fil,$text);
fclose($fil);
?>
Файл tv.sh - который положим в меню
#!/bin/bash
if ping -c 1 62.148.128.1 | grep '64 bytes'> /dev/null
then
php tv.php
fi
cat tv.txt | grep `date +%H:` |cut -d = -f 1 >>tv_sort.txt
notify-send "Сейчас по ТВ" "`cat tv_sort.txt`" -t 16000 -i /путь/до/файла/иконки
rm tv_sort.txt &

ТВ программа для кабельного, с сайта www.nsk.tvoe.tv, с возможностью установки нужных каналов:



программа будет содержать: сейчас на тв, или в ближайший час на тв
Файл tv.php
#!/usr/bin/php
 ?php
//Ссылка для программ - сейчас на ТВ - http://www.nsk.tvoe.tv/tv/prog.phtml?daytimes=current&weekday=
//Ссылка для программ - Ближайший час на ТВ - http://www.nsk.tvoe.tv/tv/prog.phtml?daytimes=nearly
//Любую из ссылок вписать с троку ниже

$file = iconv("cp1251","utf8",implode("",file("http://www.nsk.tvoe.tv/tv/prog.phtml?daytimes=current&weekday=")));
preg_match_all('/(? =return false;\">)[^ ,>]*(?= \/a> \/td>)/',$file, $matches3);
preg_match_all('/(? = b>)[0-9][:][0-9][0-9]|[0-9][0-9][:][0-9][0-9](?= \/b> \/a> \/td>)/',$file, $matches1);
preg_match_all('/(? =class=\"td_prog\" width=\"55\%\">).*(?= \/td>)/', $file, $matches2);

for($i=0; $i count($matches1[0]); $i++)
{
$tim = $matches1[0][$i];
$text = $text.$tim." - ".$matches3[0][$i]." - ".strip_tags($matches2[0][$i])."\n";
}

echo $text;
$fil = fopen("~/scripts/tv2.txt","w+");
$fw=fputs($fil,$text);
fclose($fil);
?>
Файл tv.sh
#!/bin/bash
if ping -c 1 62.148.128.1 | grep '64 bytes'> /dev/null
then
php ~/scripts/tv2.php
fi
#Через пробел написать нужные каналы, точно также как они написаны на сайте
for chanal in Первый Россия НТВ Культура Спорт Домашний Viasat History
do
cat ~/tv2.txt | grep $chanal | cut -d = -f 1 >>tv_sort.txt
done

notify-send "Сейчас по ТВ" "`cat tv_sort.txt`" -t 16000 -i /usr/share/icons/Human/48x48/apps/preferences-desktop-screensaver.png
rm tv_sort.txt &

Комментариев нет: