XMLTV Updater Germany / TV-Spielfilm (1 Viewer)

M

mcbyte

Guest
Hi, i made a small PHP script that creates XMLTV Data from the german www.tvspielfilm.de site.
I'd like to post the package somewhere, so other german users can use it, but as i know that tvspielfilm etc. do not like such grabbers, i dont want to put it on my server.
Is there a way to attach a ZIP to a post or something?
 

user_99

Portal Pro
August 13, 2005
78
1
Austria, Graz
mcbyte said:
Hi, i made a small PHP script that creates XMLTV Data from the german www.tvspielfilm.de site.
I'd like to post the package somewhere, so other german users can use it, but as i know that tvspielfilm etc. do not like such grabbers, i dont want to put it on my server.
Is there a way to attach a ZIP to a post or something?
That sounds great. You can try to upload your files to Mytempdir.com or Rapidshare.de to share it with other users.
 
M

mcbyte

Guest
Here is the code. Its quite beta but maybe it helps someone ;)

Needs PHP 5+

xmltv.php:
Code:
<?php

$channels = array(
	'RTL' 		=> array('id' => 'rtl.de',			'name' => 'RTL Television',		'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/rtl.gif'),
	'RTL2' 		=> array('id' => 'rtl2.de',			'name' => 'RTL2',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/rtl2.gif'),
	'SUPER' 	=> array('id' => 'superrtl.de',		'name' => 'Super RTL',			'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/ruper.gif'),
	'VOX' 		=> array('id' => 'vox.de',			'name' => 'VOX',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/vox.gif'),
	'ZDF' 		=> array('id' => 'zdf.de',			'name' => 'ZDF',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/zdf.gif'),
	'VIVA' 		=> array('id' => 'viva.tv',			'name' => 'VIVA',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/viva.gif'),
	'N24' 		=> array('id' => 'n24.de',			'name' => 'N24',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/n24.gif'),
	'PRO7' 		=> array('id' => 'prosieben.de',	'name' => 'ProSieben',			'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/pro7.gif'),
	'K1' 		=> array('id' => 'kabel1.de',		'name' => 'KABEL1',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/k1.gif'),
	'SAT1' 		=> array('id' => 'sat1.de',			'name' => 'SAT.1',				'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/sat1.gif'),
	'ARD' 		=> array('id' => 'ard.de',			'name' => 'Das Erste',			'icon' => 'http://i.tvspielfilm.de/tvs/sender/pics/ard.gif')
);

function getURL_saveCache()
{
	global $getURL_cache;
	file_put_contents('getURL.cache', serialize($getURL_cache));
}

function getURL($url)
{
	global $getURL_cache;
	if (!$getURL_cache) {
		$getURL_cache = unserialize(file_get_contents('getURL.cache'));
		register_shutdown_function('getURL_saveCache');
	}
	$id = md5($url);
	if (!isset($getURL_cache[$id])) {
		echo "[" . $url . "]\n";
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$res = curl_exec($ch);
		curl_close($ch);
		$getURL_cache[$id] = gzcompress($res);
	} else {
		$res = gzuncompress($getURL_cache[$id]);
	}
	return $res;
}

function unhtmlspecialchars($s)
{
	$s = str_replace('', ' ', $s);
	$t = html_entity_decode($s);
	$u = "";
	for ($i=0; $i<strlen($t); $i++) {
		if ($t[$i] == "&" && $t[$i+1] == "#") {
			$i+=2;
			$x = "";
			while ($t[$i] != ";" && $i < strlen($t)) {
				$x .= $t[$i];
				$i++;
			}
			$u .= chr($x+0);
		} else {
			$u .= $t[$i];
		}
	}
	return $u;
}

function importProgram($date, $id)
{
	global $tvData, $channels;
	
	$data = getURL('http://tvspielfilm.msn.de/programm/tagesprogramm?sendungs_id='.$id);
	$data = str_replace("\n", " ", $data);
	$res = array();

	// channel | <span class="sender">SWR</span>
	preg_match('#<span class="sender">([^<]+)</span>#', $data, $m);
	
	if (!isset($channels[strtoupper(trim(unhtmlspecialchars($m[1])))])) return;
	$res['channel'] = $channels[strtoupper(trim(unhtmlspecialchars($m[1])))]['id'];
	
	// date | <span class="tagesprogramm-bold">am</span>:10.Sep
	preg_match('#<span class="tagesprogramm-bold">am</span>:([^&]+)#', $data, $m);
	list($day,$month) = explode('.', $m[1]);
	$monthNames = array('Jan', 'Feb', 'Mrz', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez');
	$month = array_search($month, $monthNames)+1;
	$dmy = sprintf('%04d-%02d-%02d', date('Y', $date), $month, $day);
	
	// start | <span class="stunde">05</span><span class="minute">00</span>
	preg_match('#<span class="stunde">([^<]+)</span><span class="minute">([^<]+)</span>#', $data, $m);
	$res['start'] = strtotime($dmy.' '.sprintf('%02d:%02d:00', $m[1], $m[2]));
	
	preg_match('#<span class="tagesprogramm-bold">bis</span>:([0-9:]+)#', $data, $m);
	if (sizeof($m) < 2) {
		$fp = fopen('tmp.html', 'w'); fputs($fp, $data); fclose($fp);
		exit;
	}
	list($hour, $minute) = explode(':', $m[1]);
	
	$res['end'] = strtotime($dmy.' '.sprintf('%02d:%02d:00', $hour, $minute));
	if ($res['end'] < $res['start']) $res['end'] += 24*60*60;
	
	// title | programm-artikel-headline">Treffpunkt Stadion</span>
	preg_match('#programm-artikel-headline">([^<]+)</span>#', $data, $m);
	$res['title'] = trim(unhtmlspecialchars($m[1]));
	
	// image | [img]http://i.tvspielfilm.de/img/gen/B/B/HBBBAfmay8G_Pxgen_r_177x117.jpg[/img]
	preg_match('#[img]([^[/img]#', $data, $m);
	$res['image'] = (sizeof($m) == 2) ? trim(unhtmlspecialchars($m[1])) : '';
	
	// type | <span class="c-filmart">Kinder</span>
	preg_match('#<span class="c-filmart">([^<]+)</span>#', $data, $m);
	$res['category'] = (sizeof($m) == 2) ? trim(unhtmlspecialchars($m[1])) : '';
	
	// orig-title | <span class="normal-bold">O: Disney's Art Attack, GB1998-2004</span>
	preg_match('#<span class="normal-bold">O: ([^<]+)</span>#', $data, $m);
	$res['originalTitle'] = (sizeof($m) == 2) ? trim(unhtmlspecialchars($m[1])) : '';

	// FSK | <span class="tagesprogramm-bold">FSK</span>:6</span>
	preg_match('#<span class="tagesprogramm-bold">FSK</span>:([0-9]+)#', $data, $m);
	$res['fsk'] = (sizeof($m) == 2) ? ($m[1]+0) : '';
	
	// description | <td width="290" class="gross">Verwechslungskomödie (USA 1986). Bibliothekar Joe (Judge Reinhold) verkleidet sich als Polizist und verguckt sich in  eine "Kollegin" (Meg Tilly)... In Nebenrollen spielen Harvey Keitel, Joe Mantegna und John Turturro. (Wdh. am 2.3.)</td>
	preg_match('#<td width="290" class="gross">([^<]+)</td>#', $data, $m);
	$res['description'] = (sizeof($m) == 2) ? trim(unhtmlspecialchars($m[1])) : 'Keine Beschreibung verfügbar';
	
	// year/country
	preg_match('#([A-Z]*)[, ]*(19[0-9]{2}|200[0-9]{1})#', $res['originalTitle'].' '.$res['description'], $m);
	$res['country'] = (sizeof($m) == 3) ? trim(unhtmlspecialchars($m[1])) : '';
	$res['year'] = (sizeof($m) == 3) ? ($m[2]+0) : '';
	
	// stars 
	preg_match('#http://i.tvspielfilm.de/tvs/programm/pics/daumen_26x26_([a-z]+)\.gif#', $data, $m);
	$res['rating'] = (sizeof($m) == 2) ? (($m[1]=='tief') ? 0 : (($m[1]=='quer') ? 1 : (($m[1]=='hoch') ? 3 : ''))) : '';
	// quer, hoch, tief
	
	$tvData[$date][$res['channel']][] = $res;
}

function importDate($date)
{
	global $channels;
	for ($page=1; $page<100; $page++) {
		$data = getURL('http://tvspielfilm.msn.de/programm/tagesprogramm?sart_id=SP&sart_id=RE&sart_id=SE&sart_id=U&sart_id=KIN&sart_id=SPO&spartentipp=&date='.date('Ymd',$date).'&startzeit=ganztag&sender='.implode('%2C', array_keys($channels)).'&go=1&type=sparten&highlight=&order=sndg.anfangszeit&max=20&page='.$page);
		preg_match_all('#http://tvspielfilm.msn.de/programm/tagesprogramm\?sendungs_id=([0-9]+)#', $data, $m);
		$m = $m[1];
		foreach ($m as $id) importProgram($date, $id);
		if (sizeof($m) < 20) break;
	}
}

echo "load xmltv.dat\n";
$curDate = strtotime(date('Y-m-d'));
$tvData = @unserialize(file_get_contents('xmltv.dat'));
if (is_array($tvData)) foreach (array_keys($tvData) as $date) if ($date < $curDate) unset($tvData[$date]);
$date = $curDate;
while ($date <= $curDate+24*60*60*14) {
		if (!isset($tvData[$date])) {
			echo "update day ".date('Y-m-d', $date)."\n";
			importDate($date);
		}
		$date += 24*60*60;
}
echo "save xmltv.dat\n";
file_put_contents('xmltv.dat', serialize($tvData));

echo "create TvGuide.xml\n";
$fp = fopen('TvGuide.xml', 'w');
fputs($fp, '<?xml version="1.0" encoding="iso-8859-1" ?>'."\n");
fputs($fp, '<tv>'."\n");
foreach ($channels as $channel)
{
	fputs($fp, "\t".'<channel id="'.$channel['id'].'">'."\n");
	fputs($fp, "\t\t".'<display-name>'.htmlspecialchars($channel['name']).'</display-name>'."\n");
	if ($channel['icon']) fputs($fp, "\t\t".'<icon src="'.htmlspecialchars($channel['icon']).'" />'."\n");
	fputs($fp, "\t".'</channel>'."\n");
}
foreach ($tvData as $date => $dateData) {
	foreach ($dateData as $channelID => $channelData) {
		foreach ($channelData as $programData) {
			fputs($fp, "\t".'<programme channel="'.htmlspecialchars($channelID).'" start="'.date('YmdHis', $programData['start']).'" stop="'.date('YmdHis', $programData['end']).'">'."\n");
			fputs($fp, "\t\t".'<title>'.htmlspecialchars($programData['title']).'</title>'."\n");
			if ($programData['description']) fputs($fp, "\t\t".'<desc>'.htmlspecialchars($programData['description']).'</desc>'."\n");
			if ($programData['category']) fputs($fp, "\t\t".'<category>'.htmlspecialchars($programData['category']).'</category>'."\n");
			if ($programData['year']) fputs($fp, "\t\t".'<year>'.htmlspecialchars($programData['year']).'</year>'."\n");
			if ($programData['country']) fputs($fp, "\t\t".'<country>'.htmlspecialchars($programData['country']).'</country>'."\n");
			if ($programData['rating'] !== '') fputs($fp, "\t\t".'<star-rating><value>'.$programData['rating'].'/3</value></star-rating>'."\n");
			if ($programData['fsk'] !== '') fputs($fp, "\t\t".'<rating system="FSK"><value>'.$programData['fsk'].'</value></rating>'."\n");
			fputs($fp, "\t".'</programme>'."\n");
		}
	}
}
fputs($fp, '</tv>'."\n");
fclose($fp);

echo "done\n";

?>

xmltv.cpp (so you have a xmltv.exe runnable by mediaportal)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argC, char* argV[])
{
	for (int i=0; i<argC; i++) if (!stricmp(argV[i], "--configure")) return 0;
	system("xmltv.bat");
	return 0;
}

xmltv.bat
Code:
@echo off
C:\Programme\PHP\PHP.EXE xmltv.php

[/code]
 

andinaegnaeg

Portal Member
February 2, 2005
41
0
Kempten, Germany
Has someone tried it?

Where do I have to place the script? To run the php I have to insstall apache fro example.
Please tell us how you get it to work.

Is it faster than the xmltv grabber? that thing is damn slow!

Regards,
Andinaegnaeg
 

smuliv

New Member
October 30, 2005
1
0
after searching a grabber which also gets data for atv+ for days now i finally found your post. many thx for this nice script. the feedback i can give you until now is that your grabber sometimes misses some programs and always puts 3 entrys for each fetched program in the xml-file. i could not figure out why - maybe you can have a look at this.

andinaegnaeg: yes - its faster than the xmltv-grabber - and provides more information. its worth trying it.

regards
smu
 

Users who are viewing this thread

Similar threads

MP1 MP2 MP2 DLNA status? DE
What I meant is that we have a MP2 plugin called UPnP Render that can play media from DLNA servers if I remember correctly. I don't know the current state of the plugin though. That's why MP2 probably never will be certified. ;) Yes, that was also the idea, but it is a big job as all TV's, software etc. seems to not do everything...
What I meant is that we have a MP2 plugin called UPnP Render that can play media from DLNA servers if I remember correctly. I don't...
So I'm wondering what the state of play is with MP2 and DLNA functionality? When I started this post, I did see some posts...
Replies
10
Views
1K
Thank you for performing this test, and confirming @joecrow 's suspicion as to the cause of the problem. In principle the same problem exists with other EPG sources, such as the broadcast EPG that I use with DVB-T/T2. When a programme first appears in the EPG (7 days ahead of its broadcast time), some programmes have a generic...
Thank you for performing this test, and confirming @joecrow 's suspicion as to the cause of the problem. In principle the same...
TV Server 1.25. Windows 10. This has been an issue for many years, if not since inception, and I hoped it would be resolved...
Replies
10
Views
2K
OK, this is specifically for people in Belgium (Vlaanderen) who are using Telenet Cable with MediaPortal 2. Next year (Edit: this year, in march 2020) the Telenet provider will stop broadcasting Analog TV and Radio signals on their cable, and make the switch to Digital (DVB-C). The radio signals will disappear completely, so you'll...
OK, this is specifically for people in Belgium (Vlaanderen) who are using Telenet Cable with MediaPortal 2. Next year (Edit: this...
OK, this is specifically for people in Belgium (Vlaanderen) who are using Telenet Cable with MediaPortal 2. Next year (Edit: this...
Replies
0
Views
916
EPG Collector can grab the DVB EPG and save it as an XMLTV file, which both TVServer and many other TV backends can import. EPG Collector can also extract episode and season info from titles and descriptions for OpenTV (maybe MHEG5 too) and place them into the episode num tag. Perhaps you could contact Steve Bickell to see if you...
EPG Collector can grab the DVB EPG and save it as an XMLTV file, which both TVServer and many other TV backends can import. EPG...
Hi, I know this post is very long, so I have highlighted some parts of the text as a TL;DR version. I have been using MP 1 since...
Replies
2
Views
2K
Yes, better there.
Yes, better there.
NOTE: Original post edited to update on each issue. Hi all, This is my first post on here, having just come from a fairly well...
Replies
19
Views
4K
Top Bottom