-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtvmaze.php
More file actions
63 lines (59 loc) · 2.04 KB
/
tvmaze.php
File metadata and controls
63 lines (59 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/* new code to parse JSON from tvmaze.com API */
$date = "";
$showtext = "";
$networktext = "";
$airtimes = array();
$networks = array();
$networks2 = array();
$networkshows = array();
$times = array();
$endtimes = array();
$shows = array();
$networkcount = 0;
$id = 0;
$json_url = file_get_contents("http://api.tvmaze.com/schedule");
$json_a = json_decode($json_url, true);
foreach ($json_a as $key => $val) {
$airtimes[$id] = $val['airtime'];
$date = $val['airdate'];
$networks2[$val['show']['network']['name']] = $val['show']['network']['name'];
$time = strtotime($val['airtime']);
$endTime = date("H:i", strtotime('+'.$val['runtime'].' minutes', $time));
$endtimes[$id] = $endTime;
if ($val['summary'] != "") {
$summary = $val['summary'];
} else {
$summary = $val['show']['summary'];
}
$showtext2 = "<event start=\"".$val['airtime']."\" end=\"".$endTime."\">
<title>".str_replace('&', '&', $val['show']['name'])."</title>
<subtitle>Season ".$val['season']." Episode ".$val['number']."</subtitle>
<description><![CDATA[".$summary."]]></description>
<link>".$val['url']."</link>
</event>";
$shows[$id] = $showtext2;
$showtext .= $showtext2;
$networkshows[$val['show']['network']['name']] .= $showtext2;
$id++;
}
foreach ($networks2 as $network2) {
$network = "<location name=\"".str_replace('&', '&', $network2)."\" subtext=\"\">
".$networkshows[$network2]."
</location>";
$networktext .= $network;
$networks[$networkcount] = $network;
$networkcount++;
}
header('Content-Type: text/xml; charset=utf-8');
$finalxml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<timetable start=\"".$airtimes[0]."\" end=\"".end($endtimes)."\" interval=\"2\" title=\"".$date."\">";
foreach($networks as $network) {
$finalxml .= $network;
}
$finalxml .= "</timetable>";
echo $finalxml;
$fp = fopen('output.xml', "w");
fwrite($fp, $finalxml);
fclose($fp);
?>