/download/cache.php
PHP | 2059 lines | 1623 code | 145 blank | 291 comment | 229 complexity | 42c0c722c880a2dbc835193e5baf8bc0 MD5 | raw file
Possible License(s): GPL-3.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- This file is part of NZ XMLTV Listings.
- NZ XMLTV Listings is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- NZ XMLTV Listings is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with NZ XMLTV Listings. If not, see <http://www.gnu.org/licenses/>.
- */
- include '../libs/nzxmltv.php';
- ob_start();
- connectToDB();
- DeclareConstants;
- /* Generic Functions */
- function echoIfNotSilent($string)
- {
- echo (runSilently != 'yes' ? $string : NULL);
- ob_flush();
- flush();
- }
- function sqlOR($orarray, $fieldName)
- {
- foreach ($orarray as $or)
- {
- $sqlStatement = $sqlStatement . $fieldName . "='" . $or . "' OR ";
- }
- return substr($sqlStatement, 0, -4);
- }
- function GetPage($url, $saveTo = NULL, $saveFilename = NULL, $minimumFileSize = 2048) //Get a page of data, either from the local filesystem or a website
- {
- if ($saveTo == '' OR $saveTo == NULL)
- {
- unset($saveTo);
- }
- if ($saveFilename == '' OR $saveFilename == NULL)
- {
- $localFilename = $saveTo . basename($url);
- }
- else
- {
- $localFilename = $saveTo . $saveFilename;
- }
- $fileType = strtolower(pathinfo($localFilename, PATHINFO_EXTENSION));
- if (isset($saveTo) AND file_exists($localFilename)) //If the file already exists locally
- {
- $url = $localFilename; // Change the URL to point to the local version
- }
- $datapage = file_get_contents($url); //Get the page content
- if ($datapage <> '' AND $datapage <> FALSE AND strlen($datapage) > $minimumFileSize) //If the page isn't empty
- {
- if (isset($saveTo) AND !file_exists($localFilename))
- {
- if (!file_exists($saveTo)) //If the folder doesn't exist
- {
- mkdir($saveTo, 0777, true); //Recursively make the folder
- }
- file_put_contents($localFilename, $datapage); //Save a copy
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Cached file ' . $localFilename . '<br />' . "\n");
- }
- }
- if ($fileType <> 'jpg' AND $fileType <> 'jpeg' AND $fileType <> 'gif' AND $fileType <> 'png')
- {
- $datapage = FixBadCharacters(stripslashes($datapage));
- }
- return $datapage; //Return the contents of the page
- }
- }
- function DBInsert($table, $sqlArray, $verbose = FALSE)
- {
- foreach ($sqlArray as $insert => $value)
- {
- $inserts = $inserts . $insert . ",";
- $values = $values . ((is_null($value) OR trim($value)=='') ? "NULL" : "'" . mysql_real_escape_string(trim(html_entity_decode(stripslashes($value)))) . "'") . ",";
- }
- $sqlQuery = "REPLACE INTO " . $table . " (" . rtrim($inserts, ",") . ") VALUES (" . rtrim($values, ",") . ")";
- if ($verbose)
- {
- //print_r($sqlArray);
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- }
- mysql_query($sqlQuery) or die(mysql_error());
- }
- function DBUpdate($table, $sqlArray, $whereArray)
- {
- foreach ($sqlArray as $column => $value)
- {
- $values = $values . $column . "=" . ((is_null($value) OR trim($value)=='') ? 'NULL' : "'" . mysql_real_escape_string(trim(html_entity_decode(stripslashes($value)))) . "'") . ",";
- }
- foreach ($whereArray as $column => $value)
- {
- $wheres = $wheres . $column . "=" . ((is_null($value) OR trim($value)=='') ? 'NULL' : "'" . mysql_real_escape_string($value) . "'") . " AND ";
- }
- $sqlQuery = "UPDATE " . $table . " SET " . rtrim($values, ",") . " WHERE " . substr($wheres, 0, -5) . ")";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- }
- function CreateList($inputArray, $element, $separator)
- {
- if (is_array($inputArray))
- {
- foreach ($inputArray as $arrayElement)
- {
- if (($element = "") or (empty($element)))
- {
- $item = $arrayElement;
- }
- else
- {
- $item = $arrayElement->$element;
- }
- if (is_string($item))
- {
- if (trim($item) <> "")
- {
- $outputList = $outputList . trim($arrayElement->$element) . $separator;
- }
- }
- }
- return rtrim($outputList, ",");
- }
- }
- function BlankValue($value, $nullvalue)
- {
- $return = (($value == $nullvalue OR trim($value) == "") ? "" : $value);
- return $return;
- }
- /* Data scraping */
- function TelstraGetListings($datadate, $hours, $package) //Get TV listings for a specified date and number of hours
- {
- return GetPage(telstraDataURL . 'tvg-gridlist-base.cfm?v=l&c=' . $package . '&h=1&f=' . $hours . '&d=' . $datadate, listingsFolder); //Return the page for relevant day and number of hours (v = view, c = channels, h = hour start, f = number of hours, d = date )
- }
- /* Channels */
- function TelstraGrabChannelPackages()
- {
- $optionsURL = telstraDataURL . "tvg-grid-top.cfm";
- preg_match_all('~<option value="pkg-' .
- '(?P<package>.*?)' .
- '">~ism',
- GetPage($optionsURL /*, listingsFolder */), $packages, PREG_SET_ORDER);
- foreach ($packages as $package)
- {
- preg_match_all('~<td rowspan="1000" align="center" valign="top"><img src="' .
- '(?P<url>.*?)' . //Channel Image URL
- '" alt="' .
- '(?P<name>.*?)' . //Name of channel
- '"~ism',
- TelstraGetListings(currentDate, 24, 'pkg-' . urlencode($package[package])), $programs, PREG_SET_ORDER); //1 = URL of channel image, 2 = Name of channel, 4 = Details URL for first programme
- $packageChannels = '';
- foreach ($programs as $program)
- {
- $result = mysql_query("Select TC_id FROM xmltvChannels WHERE display_name='$program[name]'") or die(mysql_error());
- $row = mysql_fetch_assoc($result);
- $packageChannels .= $row[TC_id] . ",";
- }
- $packageChannels = rtrim($packageChannels, ",");
- if ($packageChannels <> "")
- {
- mysql_query("INSERT INTO ChannelPackages (provider,package,channels) VALUES('Telstra','$package[url]','$packageChannels')") or die(mysql_error());
- }
- }
- }
- function MergeChannelsTables($source) //Merge data from the Channels table (manually updated) into the Channels table (auto-generated).
- {
- global $availableSources;
- $availableNumbers = array('Sky', 'Freeview', 'Analogue', 'All');
- $channels = mysql_query("SELECT * FROM Channels WHERE " . $source . "_id IS NOT NULL");
- while ($channel = mysql_fetch_assoc($channels))
- {
- $channel = CleanQuoteArray($channel);
- $saveSources = "";
- foreach ($availableSources as $availableSource)
- {
- $saveSources .= ", " . $availableSource . "_id=" . $channel[$availableSource . '_id'];
- }
- $saveNumbers = "";
- foreach ($availableNumbers as $number)
- {
- $saveNumbers .= ", " . $number . "_number=" . $channel[$number . '_number'];
- }
- mysql_query("UPDATE xmltvChannels SET display_name=" . $channel['display_name'] . $saveSources . $saveNumbers . ", large_icon=" . $channel[large_icon] . ", url=" . $channel['url'] . " WHERE " . $source . "_id=" . $channel[$source . '_id']); // or die(mysql_error());
- foreach(array('small_icon','genre') as $field)
- {
- if ($channel[$field] <> 'NULL')
- {
- mysql_query("UPDATE xmltvChannels SET " . $field . "=" . $channel[$field] . " WHERE " . $source . "_id=" . $channel[$source . '_id']); // or die(mysql_error());
- }
- }
- }
- }
- function UpdateChannelsTable($display_name, $source, $channel_id, $genre = NULL, $small_icon = NULL)
- {
- mysql_query("UPDATE xmltvChannels SET display_name='$display_name' WHERE " . $source . "_id='" . $source . "-" . $channel_id . "'"); // or die(mysql_error());
- mysql_query("UPDATE xmltvChannels SET " . $source . "_id='" . $source . "-" . $channel_id . "' WHERE display_name='$display_name'"); // or die(mysql_error());
- if ($genre <> NULL)
- {
- $extraFields = ',genre,small_icon';
- $extraFieldValues = ",'" . $genre . "','" . $small_icon . "'";
- }
- mysql_query("INSERT INTO xmltvChannels (" . $source . "_id,display_name" . $extraFields . ") VALUES('" . $source . "-" . $channel_id . "','$display_name'" . $extraFieldValues . ")"); // or die(mysql_error());
- }
- function TelstraGrabChannelList()
- {
- $source = 'TC';
- $provider = 'Telstra';
- $genresURL = telstraDataURL . "tvg-grid-top.cfm";
- $channelsURL = telstraDataURL . "tvg-channel-favourites.cfm?v=ga&mf=1";
- echoIfNotSilent('<p>');
- preg_match_all('~<option value="genre-(?P<code>.*?)">(?P<name>.*?)</option>~ism', GetPage($genresURL, listingsFolder), $genres, PREG_SET_ORDER);
- foreach ($genres as &$genre)
- {
- $genrelist[$genre[code]] = $genre[name];
- }
- preg_match_all('~\'\)"><img src="' .
- '(?P<image>.*?)' .
- '" alt="' .
- '(?P<id>.*?)' .
- '" width="47" height="47" vspace="4" border="0"><a></a><br>' .
- '.*?' .
- 'value="' .
- '(?P<name>.*?)' .
- '" genre="' .
- '(?P<genre>.*?)' .
- '"~ism',
- GetPage($channelsURL, listingsFolder), $channels, PREG_SET_ORDER);
- foreach ($channels as $channel)
- {
- $genre = $genrelist[ltrim($channel[genre], "g")];
- mysql_query("UPDATE xmltvChannels SET Telstra_genre='" . $genre . "' WHERE " . $source . "_id='" . $source . "-" . $channel[id] . "'");
- UpdateChannelsTable($channel[id], $source, $channel[name], $genre, mysql_real_escape_string($channel[image]));
- $channelList[$channel[name]] = Array("source" => $source, "name" => $channel[id], "genre" => $genre, "image" => mysql_real_escape_string($channel[image]));
- echoIfNotSilent('Added ' . $provider . ' channel ' . $channel[name] . '<br />' . "\n");
- }
- preg_match_all('~<td rowspan="1000" align="center" valign="top"><img src="' .
- '(?P<image>.*?)' . //Channel Image URL
- '" alt="' .
- '(?P<name>.*?)' . //Name of channel
- '" width="47" height="47">' .
- '.*?' .
- 'openBrWindow\(\'' .
- '(?P<url>.*?)' . //Details URL for first programme
- '\',~ism',
- TelstraGetListings(currentDate, 1, 'all'), $programs, PREG_SET_ORDER); //1 = URL of channel image, 2 = Name of channel, 4 = Details URL for first programme
- foreach ($programs as $program)
- {
- preg_match('~<strong>Channel: </strong></td>' .
- '.*?' .
- '<strong>' .
- '(?P<name>.*?)' . //Channel Name
- ' \(' .
- '(Channel|Digital|Analogue) ' .
- '(?P<number>.*?)' . //Channel Number
- '\) </strong></td>~ism',
- GetPage(telstraDataURL . $program[url], programsFolder), $channelNumber);
- mysql_query("UPDATE xmltvChannels SET " . $provider . "_number='" . $channelNumber[number] . "' WHERE " . $source . "_id='" . $source . "-" . GrabTelstraID($program[4]) . "'");
- $channelList[GrabTelstraID($program[url])]["number"] = $channelNumber[number];
- }
- MergeChannelsTables($source);
- echoIfNotSilent('</p>' . "\n");
- return $channelList;
- }
- function YahooGrabChannelList($channelSet)
- {
- $source = 'YH';
- $provider = 'Yahoo';
- echoIfNotSilent('<p>');
- $channelsURL = "http://nz.tv.yahoo.com/tv-guide/?hour=00&min=00&date=" . date('d') . "&mon=" . date('m') . "&year=" . date('Y') . "&tvrg=" . $channelSet;
- //echo $channelsURL . "<br />\r\n";
- preg_match_all('~<div class="lt-listing-wrapper"><a href="http://nz.tv.yahoo.com/tv-guide/search/index.html\?venue=' .
- '(?P<id>.*?)' .
- '&now=' .
- '.*?' .
- '">' .
- '(?P<name>.*?)' .
- '</a></div>~ism',
- GetPage($channelsURL, listingsFolder), $matches, PREG_SET_ORDER);
- foreach ($matches as $match)
- {
- if ($channelSet . "-" . $match[id] <> "2-20") //If the channel's not a duplicate of TAB Trackside
- {
- UpdateChannelsTable($match[name], $source, $channelSet . "-" . $match[id]);
- $channelList[$channelSet . "-" . $match[is]] = Array("source" => $source, "name" => $match[name]);
- echoIfNotSilent('Added ' . $provider . ' channel ' . $match[name] . '<br />' . "\n");
- }
- }
- MergeChannelsTables($source);
- echoIfNotSilent('</p>' . "\n");
- }
- function FreeViewGrabChannelList()
- {
- $source = 'FV';
- $provider = 'Freeview';
- echoIfNotSilent('<p>');
- $pageXML = new SimpleXMLElement(GetPage('http://freeviewnz.tv/epg_data.php', listingsFolder));
- foreach ($pageXML->item as $channel)
- {
- preg_match('~http://listings.tvnz.co.nz/freeview/(?P<id>.*?)_7days.xml~ism', $channel->url, $tvnzidArray);
- /*if ($channel->name == 'TV3 PLUS 1')
- {
- $tvnzidArray[id] = 'tv3plus1';
- }*/
- UpdateChannelsTable($channel->name, $source, $tvnzidArray[id]);
- echoIfNotSilent('Added ' . $provider . ' channel ' . $channel->name . '<br />' . "\n");
- }
- MergeChannelsTables($source);
- echoIfNotSilent('</p>' . "\n");
- }
- function SatelliteGrabChannelList()
- {
- }
- function GrabIcons()
- {
- echoIfNotSilent('<h1>Caching Icons...</h1>' . "\n" . '<p>' . "\n");
- foreach (array('small', 'large') as $iconSize)
- {
- $result = mysql_query("SELECT " . $iconSize . "_icon FROM xmltvChannels WHERE " . $iconSize . "_icon IS NOT NULL");
- while ($row = mysql_fetch_assoc($result))
- {
- GetPage($row[$iconSize . '_icon'], iconsFolder . $iconSize . '/');
- }
- }
- $result = mysql_query("SELECT icon FROM ProgramRatings WHERE icon IS NOT NULL");
- while ($row = mysql_fetch_assoc($result))
- {
- GetPage($row[icon], ratingsFolder);
- }
- echoIfNotSilent('</p>' . "\n");
- }
- /* Programs */
- function TelstraGrabProgramList($day)
- {
- $dataDate = date('Y-m-d', strtotime(currentDateSQL . " +" . $day . " days"));
- if (preg_match_all('~<td valign="top" class="tvgtime">' .
- '(?P<startalt>.*?)' . //Start Time
- '</td>' .
- '.*?' .
- 'onmouseover="return escape\(\'' .
- '(?P<genres>.*?)' . //Genre(s)
- '<br><b>' .
- '(?P<title>.*?)' . //Title
- '</b><br><b>' .
- '(?P<channel>.*?)' . //Channel
- '</b><br><b>' .
- '(?P<start>.*?)' . //Start Time
- '-' .
- '(?P<end>.*?)' . //End Time
- '</b>' .
- '.*?' .
- 'openBrWindow\(\'' .
- '(?P<url>.*?)' . //Details URL
- '\',' .
- '.*?' .
- //'<span class="tvgclassification">\(' .
- '</a>' .
- '(?P<rating>.*?)' . //Age Classification
- //'\)</span>~ism',
- '</td>~ism',
- TelstraGetListings($dataDate, 24, 'all'), $programs, PREG_SET_ORDER) > 0) // 1 = Start Time, 2 = Genre(s), comma delimited, 3 = Title, 4 = Channel, 5 = Start Time, 6 = End Time, 7 = Details URL, 8 = Age Classification
- {
- foreach ($programs as $program)
- {
- unset($listing);
- $listing['file'] = trim($program[url]);
- $programResult = mysql_query("SELECT file FROM xmltvSourcePrograms WHERE file='" . $listing['file'] . "'") or die(mysql_error());
- if (mysql_num_rows($programResult) < 1)
- {
- //$listing['date'] = $dataDate;
- preg_match('~&ds=(?P<date>.*?)&st=~ism', $listing['file'], $dateArray);
- $startdate = $dateArray[date];
- $startTime = FixTime(trim($program[start]));
- $stopTime = FixTime(trim($program[end]));
- $listing['title'] = trim(htmlspecialchars_decode($program[title]));
- $listing['start'] = date('Y-m-d H:i:s', strtotime($startdate . ' ' . $startTime));
- //$listing['stop'] = date('Y-m-d H:i:s', strtotime($startdate . ' ' . $stopTime));
- $stopDate = $startdate;
- if (strtotime($startTime) >= strtotime($stopTime))
- {
- $stopDate = date('Y-m-d', strtotime($startdate . " +1 day"));;
- }
- $listing['stop'] = date('Y-m-d H:i:s', strtotime($stopDate . ' ' . $stopTime));
- $listing['channel_id'] = "TC-" . GrabTelstraID($listing['file']);
- $channelnameresult = mysql_query("SELECT All_id FROM xmltvChannels WHERE TC_id = '" . $listing['channel_id'] . "'") or die(mysql_error());
- $channelnamerow = mysql_fetch_assoc($channelnameresult);
- $listing['channel'] = $channelnamerow['All_id'];
- //$listing['rating'] = trim($program[8]);
- preg_match('~<span class="tvgclassification">\((?P<rating>.*?)\)</span>~ism', trim($program[rating]), $ratingArray);
- $listing['rating'] = $ratingArray[rating];
- if (preg_match('~<td valign="top"><span class="tvbluesml"><strong class="tvhdrpurple"> <br>' . "\r" .
- '(?P<title>.*?)' . // Title
- '</strong></span>' .
- '.*?' .
- '<strong class="tvhdrpurple"><img src="' .
- telstraImagesURL .
- '(?P<image>.*?)' . // TV Channel Image
- '" alt="Logo" width="47" height="47"' .
- '.*?' .
- '<strong>Channel: </strong></td>' .
- '.*?' .
- '<strong>' .
- '(?P<channel>.*?)' . //Channel Name
- ' \(' .
- '(Channel|Digital|Analogue) ' .
- '(?P<number>.*?)' . //Channel Number
- '\) </strong></td>' .
- '.*?' .
- '<strong>Playing: </strong></td>' .
- '.*?' .
- '<td><strong class="tvbluesml">' .
- '(?P<day>.*?)' . //Broadcast Day
- ' at ' .
- '(?P<time>.*?)' . //Broadcast time
- '<!---' .
- '.*?' .
- '---></strong></td>' .
- '.*' .
- '<strong>Duration: </strong>' .
- '.*?' .
- '<td class="tvbluesml">' .
- '(?P<duration>.*?)' . //Duration in minutes
- ' Minutes</td>' .
- '.*?' .
- '<strong>Genre: </strong>' .
- '.*?' .
- '<td class="tvbluesml">' .
- '(?P<genre>.*?)' . //Genre
- '</td>' .
- '.*?' .
- '</table>' .
- '(?P<description>.*?)' . //Description
- '<br>~ism',
- GetPage(telstraDataURL . $listing['file'], programsFolder), $details) <> 0) // 1 = Title, 2 = Channel ID, 3 = Channel Name, 4 = Channel Number, 5 = Broadcast Day, 6 = Broadcast time, 7 = Duration in Minutes, 8 = Genre, 9 = Description
- {
- //$listing['title'] = trim($details[title]);
- if (substr($listing['title'], strlen($listing['title']) - 8, 8) == '« ') { $listing['title'] = substr($listing['title'], 8, strlen($listing['title']) - 8); }
- if (substr($listing['title'], 0, 8) == ' »') { $listing['title'] = substr($listing['title'], 0, strlen($listing['title']) - 8); }
- /*preg_match('~ \((.*?)\)$~ism', $listing['title'], $rating);
- if (isset($rating[1]))
- {
- $listing['rating'] = trim($rating[1]);
- }*/
- //$listing['day'] = trim($details[day]);
- //$listing['duration'] = trim($details[duration]);
- $listing['category'] = trim($details[genre]);
- /*
- if ($listing['category'] == 'undefined, default value')
- {
- unset($listing['category']);
- }
- */
- $listing['description'] = trim(htmlspecialchars_decode($details[description]));
- /*
- if ($listing['category'] <> "Radio")
- {
- //$listing['quality'] = 'SD';
- }
- */
- /*
- foreach ($listing as $insert => $value)
- {
- $inserts = $inserts . $insert . ",";
- $values = $values . $value . ",";
- }
- mysql_query("INSERT INTO xmltvSourcePrograms (" . rtrim($inserts, ",") . ") VALUES(" . rtrim($values, ",") . ")") or die(mysql_error());
- */
- DBInsert("xmltvSourcePrograms", $listing);
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Grabbed program ' . $listing['file'] . '<br />' . "\n");
- }
- }
- else
- {
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Failed to grab program ' . $listing['file'] . '<br />' . "\n");
- }
- }
- }
- else
- {
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Already grabbed program ' . $listing['file'] . '<br />' . "\n");
- }
- }
- }
- }
- else
- {
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Failed to grab any program listings for day ' . $day . '<br />' . "\n");
- }
- }
- }
- function YahooGrabProgramList($day)
- {
- foreach (array('0', '2') as $channelSet)
- {
- for ( $hour = 00; $hour <= 23; $hour += 1)
- {
- $programsURL = "http://nz.tv.yahoo.com/tv-guide/1/" . $channelSet . "/" . $day . "/" . $hour . "/";
- //echoIfNotSilent('<a href="' . $programsURL . '">' . $programsURL . "</a><br />\r\n");
- preg_match('~<input type="hidden" id="tvguide-form-start" value="' .
- '(?P<time>.*?)' .
- '"><input value="' .
- '(?P<offset>.*?)' .
- '" type="hidden" id="tvguide-form-offset">~ism',
- GetPage($programsURL, listingsFolder, $channelSet . "-" . $day . "-" . $hour . ".html", 25000), $programlist);
- //echoIfNotSilent($programlist['time'] . "<br />\r\n");
- $yesterday = date('Y-m-d', strtotime(date('Y-m-d', $programlist['time'] + ($programlist['offset'] * 60)) . " +" . strval($day - 1) . " days"));
- $today = date('Y-m-d', strtotime(date('Y-m-d', $programlist['time'] + ($programlist['offset'] * 60)) . " +" . strval($day) . " days"));
- $tomorrow = date('Y-m-d', strtotime(date('Y-m-d', $programlist['time'] + ($programlist['offset'] * 60)) . " +" . strval($day + 1) . " days"));
- preg_match_all('~<h3><a href="/tv-guide/channel/' .
- '(?P<id>.*?)' .
- '/">' .
- '(?P<details>.*?)' .
- '</ul></div>~ism',
- GetPage($programsURL, listingsFolder, $channelSet . "-" . $day . "-" . $hour . ".html"), $channels, PREG_SET_ORDER);
- foreach ($channels as $channel)
- {
- //echoIfNotSilent($channel['id'] . "<br />\r\n");
- //echoIfNotSilent(strlen($channel['details']) . "<br />\r\n");
- preg_match_all('~<h4 class="title"><a href="/tv-guide/search/' .
- '.*?' .
- '/">' .
- '(?P<title>.*?)' .
- '</a></h4>' .
- '.*?' .
- '<span class="stamp">' .
- '(?P<start>.*?)' .
- ' - ' .
- '(?P<stop>.*?)' .
- '</span>' .
- '.*?' .
- '<dl class="info">' .
- '(?P<info>.*?)' .
- '</dl>' .
- '.*?' .
- '<p class="abstract">' .
- '(?P<description>.*?)' .
- '</p>~ism',
- $channel['details'], $programs, PREG_SET_ORDER);
- foreach ($programs as $programDetails)
- {
- unset($sqlArray);
- $sqlArray['channel_id'] = "YH-" . $channelSet . "-" . $channel['id'];
- $sqlArray['file'] = $sqlArray['channel_id'] . " " . $day . " " . $programDetails[start];
- //echoIfNotSilent($sqlArray['file'] . "<br />\r\n");
- $channeldetails = mysql_query("SELECT All_id FROM xmltvChannels WHERE YH_id = '" . $sqlArray['channel_id'] . "'") or die(mysql_error());
- $channeldetailsrow = mysql_fetch_assoc($channeldetails);
- preg_match_all('~<dt>' .
- '(?P<item>.*?)' .
- ':</dt>' .
- '.*?' .
- '<dd>' .
- '(?P<content>.*?)' .
- '</dd>~ism',
- $programDetails[info], $info, PREG_SET_ORDER);
- foreach ($info as $infoitem) //Classified, Genre
- {
- $infoarray[$infoitem[item]] = $infoitem[content];
- }
- $sqlArray['title'] = $programDetails['title'];
- $sqlArray['description'] = $programDetails['description'];
- $sqlArray['category'] = $infoarray['Genre'];
- $sqlArray['channel'] = $channeldetailsrow['All_id'];
- $startday = $today;
- $stopday = $today;
- /*
- if (strtotime($programDetails['stop']) < strtotime($programDetails['start']))
- {
- if ($hour <= 12)
- {
- $startday = $yesterday;
- }
- else
- {
- $stopday = $tomorrow;
- }
- }
- elseif (strtotime($programDetails['start']) < strtotime(strval($hour) . ":00:00 am"))
- {
- $startday = $tomorrow;
- $stopday = $tomorrow;
- }
- */
- if ($hour > 12)
- {
- if (strtotime($programDetails['start']) < strtotime("12:00:00"))
- {
- //echoIfNotSilent("Start: " . strtotime($programDetails['start']) . " < " . strtotime("02:00:00") . "<br />\r\n");
- $startday = $tomorrow;
- }
- if (strtotime($programDetails['stop']) < strtotime("12:00:00"))
- {
- //echoIfNotSilent("Stop: " . strtotime($programDetails['stop']) . " < " . strtotime("04:00:00") . "<br />\r\n");
- $stopday = $tomorrow;
- }
- }
- elseif ($hour < 12)
- {
- if (strtotime($programDetails['start']) > strtotime("12:00:00"))
- {
- //echoIfNotSilent("Start: " . strtotime($programDetails['start']) . " > " . strtotime("20:00:00") . "<br />\r\n");
- $startday = $yesterday;
- }
- if (strtotime($programDetails['stop']) > strtotime("12:00:00"))
- {
- //echoIfNotSilent("Stop: " . strtotime($programDetails['stop']) . " > " . strtotime("22:00:00") . "<br />\r\n");
- $stopday = $yesterday;
- }
- }
- $sqlArray['start'] = date('Y-m-d H:i:s', strtotime($startday . " " . $programDetails['start']));
- $sqlArray['stop'] = date('Y-m-d H:i:s', strtotime($stopday . " " . $programDetails['stop']));
- //echoIfNotSilent($sqlArray['start'] . " - " . $sqlArray['stop'] . "<br />\r\n");
- $sqlArray['rating'] = $infoarray['Classified'];
- DBInsert("xmltvSourcePrograms", $sqlArray);
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Grabbed program ' . $filename . '<br />' . "\n");
- }
- }
- }
- }
- }
- }
- function FreeViewGrabProgramList()
- {
- $result = mysql_query("SELECT FV_id, All_id FROM xmltvChannels WHERE FV_id IS NOT NULL") or die(mysql_error());
- while ($row = mysql_fetch_assoc($result))
- {
- $tvnzArray = explode("-", $row[FV_id]);
- if ($tvnzArray[1] <> '' AND $tvnzArray[1] <> NULL)
- {
- $programsURL = "http://listings.tvnz.co.nz/freeview/" . $tvnzArray[1] . "_7days.xml";
- /*if ($tvnzArray[1] == 'tv3plus1')
- {
- $programsURL = "http://listings.tvnz.co.nz/freeview/tv3_7days.xml";
- }*/
- $freeviewPage = "";
- $freeviewPage = GetPage($programsURL, listingsFolder);
- if ($freeviewPage <> "")
- {
- $pageXML = new SimpleXMLElement($freeviewPage);
- foreach ($pageXML->channel->programmes->programme as $program)
- {
- $filename = CleanString($tvnzArray[1] . ' ' . $program['datetime_start']);
- $programResult = mysql_query("SELECT file FROM xmltvSourcePrograms WHERE file='" . $filename . "'") or die(mysql_error());
- if (mysql_num_rows($programResult) < 1)
- {
- /*
- mysql_query("INSERT INTO xmltvSourcePrograms (file,title,description,channel,start,stop,rating,quality,subtitles,url) VALUES('" . $filename . "','" . CleanString($program->title) . "'," . NullQuoteString(CleanString($program->synopsis)) . ",'" . $row[FV_id] . "','" . FreeViewToSQLTime($program['datetime_start']) . "','" . FreeViewToSQLTime($program['datetime_end']) . "'," . NullQuoteString($program['classification']) . "," . ($program['hd'] == 'Y' ? "'HDTV'" : "NULL") . "," . ($program['captioned'] == 'Y' ? "'teletext'" : "NULL") . "," . NullQuoteString(trim($program['website'])) . ")"); //or die(mysql_error());
- if ($tvnzArray[1] == 'tv3plus1')
- {
- mysql_query("UPDATE xmltvSourcePrograms SET start=start + INTERVAL 1 HOUR, stop=stop + INTERVAL 1 HOUR WHERE file='" . $filename . "'") or die(mysql_error());
- }
- */
- $freeViewStartTime = FreeViewToSQLTime($program['datetime_start']);
- $freeViewEndTime = FreeViewToSQLTime($program['datetime_end']);
- /*if ($tvnzArray[1] == 'tv3plus1')
- {
- $freeViewStartTime = date('Y-m-d H:i:s', strtotime($freeViewStartTime . ' +1 hour'));
- $freeViewEndTime = date('Y-m-d H:i:s', strtotime($freeViewEndTime . ' +1 hour'));
- }*/
- $sqlArray['file'] = $filename;
- $sqlArray['title'] = $program->title;
- $sqlArray['description'] = $program->synopsis;
- $sqlArray['channel_id'] = $row['FV_id'];
- $sqlArray['channel'] = $row['All_id'];
- $sqlArray['start'] = $freeViewStartTime;
- $sqlArray['stop'] = $freeViewEndTime;
- $sqlArray['rating'] = $program['classification'];
- $sqlArray['quality'] = ($program['hd'] == 'Y' ? "'HD'":"");
- $sqlArray['subtitles'] = ($program['captioned'] == 'Y' ? "'teletext'":"");
- $sqlArray['url'] = $program['website'];
- DBInsert("xmltvSourcePrograms", $sqlArray);
- //mysql_query("INSERT INTO xmltvSourcePrograms (file,title,description,channel_id,channel,start,stop,rating,quality,subtitles,url) VALUES('" . $filename . "','" . CleanString($program->title) . "'," . NullQuoteString(CleanString($program->synopsis)) . ",'" . $row['FV_id'] . "','" . $row['All_id'] . "','" . $freeViewStartTime . "','" . $freeViewEndTime . "'," . NullQuoteString($program['classification']) . "," . ($program['hd'] == 'Y' ? "'HD'" : "NULL") . "," . ($program['captioned'] == 'Y' ? "'teletext'" : "NULL") . "," . NullQuoteString(trim($program['website'])) . ")"); //or die(mysql_error());
- //
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Grabbed program ' . $filename . '<br />' . "\n");
- }
- }
- else
- {
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Already grabbed program ' . $filename . '<br />' . "\n");
- }
- }
- }
- }
- }
- echoIfNotSilent('<h2>Grabbed Freeview data for channel ' . $tvnzArray[1] . '</h2>' . "\n");
- }
- }
- function GeekNZGrabProgramList()
- {
- //GetPage('http://epg.pvr.geek.nz/epg/listings-all.xml.gz', listingsFolder);
- //$fp = gzopen(listingsFolder . 'listings-all.xml.gz', "r");
- $fp = gzopen('http://epg.pvr.geek.nz/epg/listings-all.xml.gz', "r");
- $contents = gzread($fp, 100000000);
- $pageXML = new SimpleXMLElement($contents);
- foreach ($pageXML->programme as $program)
- {
- $start = substr($program['start'], 0, -6);
- $stop = substr($program['stop'], 0, -6);
- mysql_query("INSERT INTO xmltvSourcePrograms (file,title,description,channel,channel_id,start,stop,url) VALUES('" . $program['channel'] . "-" . $start . "','" . CleanString($program->title) . "'," . NullQuoteString(CleanString($program->desc)) . ",'" . $channel . "','" . $program['channel'] . "','" . $start . "','" . $stop . "'," . NullQuoteString(trim($program->url)) . ")"); //or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Grabbed program ' . $program['channel'] . "-" . $start . '<br />' . "\n");
- }
- }
- $channelNames = mysql_query("SELECT All_id,geeksky_id FROM xmltvChannels WHERE geeksky_id IS NOT NULL"); //or die(mysql_error());
- while ($channelName = mysql_fetch_assoc($channelNames))
- {
- mysql_query("UPDATE xmltvSourcePrograms SET channel='" . $channelName['All_id'] . "' WHERE channel_id='" . $channelName['geeksky_id'] . ".sky.co.nz'"); //or die(mysql_error());
- }
- $channelNames = mysql_query("SELECT All_id,geekfv_id FROM xmltvChannels WHERE geekfv_id IS NOT NULL"); //or die(mysql_error());
- while ($channelName = mysql_fetch_assoc($channelNames))
- {
- mysql_query("UPDATE xmltvSourcePrograms SET channel='" . $channelName['All_id'] . "' WHERE channel_id='" . $channelName['geekfv_id'] . ".freeviewnz.tv'"); //or die(mysql_error());
- }
- }
- function SatellitePerlGrabProgramList()
- {
- $pageXML = new SimpleXMLElement(GetPage('TVGuide.xml', '/home/administrator/D2XMLTV/'));
- foreach ($pageXML->programme as $program)
- {
- /*if ($current_channel <> $program['channel'])
- {
- $channelrow = mysql_query("SELECT All_id FROM xmltvChannels WHERE satellite_id='" . $program['channel'] . "'");
- $channel_id = mysql_fetch_assoc($channelrow);
- $channel = $channel_id['All_id'];
- }
- $current_channel = $program['channel'];*/
- mysql_query("INSERT INTO xmltvSourcePrograms (file,title,description,channel,channel_id,start,stop,url) VALUES('" . $program['channel'] . "-" . $program['start'] . "','" . CleanString($program->title) . "'," . NullQuoteString(CleanString($program->desc)) . ",'" . $channel . "','" . $program['channel'] . "','" . $program['start'] . "','" . $program['stop'] . "'," . NullQuoteString(trim($program->url)) . ")"); //or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Grabbed program ' . $program['channel'] . "-" . $program['start'] . '<br />' . "\n");
- }
- }
- $channelNames = mysql_query("SELECT All_id,satellite_id FROM xmltvChannels WHERE satellite_id IS NOT NULL"); //or die(mysql_error());
- while ($channelName = mysql_fetch_assoc($channelNames))
- {
- mysql_query("UPDATE xmltvSourcePrograms SET channel='" . $channelName['All_id'] . "' WHERE channel_id='" . $channelName['satellite_id'] . "'"); //or die(mysql_error());
- }
- }
- function AvenardGrabProgramList()
- {
- //http://www.avenard.org/iptv/tpg-guide.php
- }
- /* Fixes */
- function FreeViewFixRNZNTimes()
- {
- $rnznresult = mysql_query("SELECT file, start, stop FROM tempSourcePrograms WHERE channel = 'national'"); //or die(mysql_error());
- while ($rnznrow = mysql_fetch_assoc($rnznresult))
- {
- $changedTime = FALSE;
- $roundedstart = date('Y-m-d H:i:s', round(strtotime($rnznrow['start']) / (60 * 5)) * 60 * 5);
- if ($rnznrow['start'] <> $roundedstart)
- {
- $rnznrow['start'] = $roundedstart;
- $changedTime = TRUE;
- }
- $roundedstop = date('Y-m-d H:i:s', round(strtotime($rnznrow['stop']) / (60 * 5)) * 60 * 5);
- if ($rnznrow['stop'] <> $roundedstop)
- {
- $rnznrow['stop'] = $roundedstop;
- $changedTime = TRUE;
- }
- if ($changedTime == TRUE)
- {
- mysql_query("UPDATE tempSourcePrograms SET start = '" . $rnznrow['start'] . "', stop = '" . $rnznrow['stop'] . "' WHERE file = '" . $rnznrow['file'] . "'") or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Fixed time for Radio NZ National program ' . $rnznrow['file'] . '<br />' . "\n");
- }
- }
- }
- }
- function ReplaceTV1BBCWorld()
- {
- $channel = 'tv1';
- $idsresult = mysql_query("SELECT TC_id, YH_id, FV_id FROM xmltvChannels WHERE All_id = '" . $channel . "'") or die(mysql_error());
- $row = mysql_fetch_assoc($idsresult);
- $availableSources = array('TC', 'YH', 'FV');
- $bbcSource = "TC-BBCV";
- foreach ($availableSources as $source)
- {
- //$channelnameresult = mysql_query("SELECT id FROM xmltvChannels WHERE " . $source . "_id = '" . $row[$source . '_id'] . "'") or die(mysql_error());
- //$channelnamerow = mysql_fetch_assoc($channelnameresult);
- //$channelid = $channelnamerow['id'];
- $bbcresult = mysql_query("SELECT file, start, stop FROM tempSourcePrograms WHERE channel_id = '" . $row[$source . '_id'] . "' AND title LIKE 'BBC World%'"); //or die(mysql_error());
- while ($bbcrow = mysql_fetch_assoc($bbcresult))
- {
- mysql_query("DELETE FROM tempSourcePrograms WHERE file = '" . $bbcrow[file] . "'") or die(mysql_error());
- $programsresult = mysql_query("SELECT * FROM tempSourcePrograms WHERE channel_id = '" . $bbcSource . "' AND stop > '" . $bbcrow[start] . "' AND start < '" . $bbcrow[stop] . "' ORDER BY start") or die(mysql_error());
- unset($programArray);
- while ($programrow = mysql_fetch_assoc($programsresult))
- {
- $programArray[] = $programrow;
- }
- if (count($programArray) >= 1)
- {
- $programArray[0][start] = $bbcrow[start];
- if (count($programArray) >= 2)
- {
- $programArray[count($programArray) - 1][stop] = $bbcrow[stop];
- }
- foreach ($programArray as $program)
- {
- $program[file] = $row[$source . '_id'] . " " . $program[start];
- $program[channel] = $row[$source . '_id'];
- $program = CleanArray($program);
- mysql_query("INSERT INTO tempSourcePrograms (file,title,description,channel_id,channel,start,stop,category,rating) VALUES('" . $program[file] . "', '" . $program[title] . "', " . NullQuoteString($program[description]) . ", '" . $program[channel] . "', '" . $channel . "', '" . $program[start] . "', '" . $program[stop] . "', " . NullQuoteString($program[category]) . ", " . NullQuoteString($program[rating]) . ")"); //or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Inserted BBC Program ' . $program[file] . '<br />' . "\n");
- }
- }
- }
- }
- }
- }
- function FixTitles()
- {
- $fixesresult = mysql_query("SELECT * FROM ProgramTitleFixes") or die(mysql_error());
- while ($fix = mysql_fetch_assoc($fixesresult))
- {
- mysql_query("UPDATE tempSourcePrograms SET title=$fix[title] WHERE title REGEXP $fix[regex]") or die(mysql_error());
- }
- }
- function FixProblemChannelTimes()
- {
- //$channelsArray[] = "ctv2";
- //$channelsArray[] = "ctv3";
- //$channelsArray[] = "discovery";
- $channels = mysql_query("SELECT All_id FROM xmltvChannels WHERE fix_times = '1'"); //or die(mysql_error());
- while ($channel = mysql_fetch_assoc($channels))
- {
- FixTimes($channel['All_id']);
- }
- }
- function FixTimes($channel_id)
- {
- $programsresult = mysql_query("SELECT file, start, stop FROM tempSourcePrograms WHERE channel_id = '" . $channel_id . "' ORDER BY start"); //or die(mysql_error());
- while ($program = mysql_fetch_assoc($programsresult))
- {
- $programdata[] = $program;
- }
- for ($i = 0; $i < count($programdata) - 1; $i++)
- {
- //if ($programdata[$i]['start'] == date('Y-m-d H:i:s', strtotime($programdata[$i]['stop'] . " -1 minute")) AND $programdata[$i]['stop'] <> $programdata[$i + 1]['start'])
- if ($programdata[$i]['stop'] < $programdata[$i + 1]['start'])
- {
- mysql_query("UPDATE tempSourcePrograms SET stop = '" . $programdata[$i + 1]['start'] . "' WHERE file = '" . $programdata[$i]['file'] . "'") or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Fixed time for program ' . $programdata[$i]['file'] . '<br />' . "\n");
- }
- }
- if ($programdata[$i]['stop'] > $programdata[$i + 1]['start']) //If start and stop are one minute apart
- {
- mysql_query("UPDATE tempSourcePrograms SET stop = '" . $programdata[$i + 1]['start'] . "' WHERE file = '" . $programdata[$i]['file'] . "'") or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent('Fixed time for program ' . $programdata[$i]['file'] . '<br />' . "\n");
- }
- }
- }
- }
- function FixBadCharacters($text)
- {
- /*
- $characters['“'] = '"'; // left side double smart quote
- $characters['â€'] = '"'; // right side double smart quote
- $characters['‘'] = "'"; // left side single smart quote
- $characters['’'] = "'"; // right side single smart quote
- $characters['…'] = "..."; // elipsis
- $characters['—'] = "-"; // em dash
- $characters['–'] = "-"; // en dash
- */
- $find = array('‘', '’', '“', '”', '…', '—', '–');
- //$find2 = array('‘', '’', '“', 'â€', '…', '—', '–');
- //$find3 = array('‘', '’', '“', 'â€Â', '…', '—', '–');
- $find2 = array("\\xe2\\x80\\x98", "\\xe2\\x80\\x99", "\\xe2\\x80\\x9c", "\\xe2\\x80\\x9d", "\\xe2\\x80\\xa6", "\\xe2\\x80\\x94", "\\xe2\\x80\\x93");
- //é = e acute
- $replace = array("'", "'", '"', '"', "...", "-", "-");
- return str_replace($find, $replace, str_replace($find2, $replace, $text));
- //return str_replace($find, $replace, str_replace($find2, $replace, str_replace($find3, $replace, $text)));
- }
- function FixDBBadCharacters()
- {
- /*
- $characters['â€Â'] = "â€";
- $characters['“'] = '"'; // left side double smart quote
- $characters['â€'] = '"'; // right side double smart quote
- $characters['‘'] = "'"; // left side single smart quote
- $characters['’'] = "'"; // right side single smart quote
- $characters['…'] = "..."; // elipsis
- $characters['—'] = "-"; // em dash
- $characters['–'] = "-"; // en dash
- */
- /*
- $characters['’'] = "'";
- $characters['‘'] = "'";
- $characters['“'] = '"';
- $characters['”'] = '"';
- $characters['…'] = "...";
- $characters['–'] = "-";
- $characters['—'] = "-";
- print_r($characters);
- unset($characters);
- */
-
- $characters[] = '‘';
- $characters[] = '’';
- $characters[] = '“';
- $characters[] = '”';
- $characters[] = '…';
- $characters[] = '—';
- $characters[] = '–';
- foreach (array("title", "description") as $field)
- {
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '‘', '\'') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '’', '\'') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '“', '\"') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '”', '\"') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '…', '...') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '—', '-') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '–', '-') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
-
- foreach ($characters as $find => $replace)
- {
- //echo "123";
- //mysql_query("UPDATE tempSourcePrograms SET " . $field . "=REPLACE(" . $field . ", '" . $find . "', '" . $replace . "') WHERE " . $field . " LIKE '%€%'") or die(mysql_error());
- }
- }
- }
- function RemoveGenericTitles()
- {
- $channels = mysql_query("SELECT All_id, remove_generic FROM xmltvChannels WHERE remove_generic IS NOT NULL"); //or die(mysql_error());
- while ($channel = mysql_fetch_assoc($channels))
- {
- RemoveProgram($channel['All_id'], $channel['remove_generic']);
- }
- }
- function RemoveProgram($channel, $title)
- {
- $deleteresult = mysql_query("DELETE FROM tempSourcePrograms WHERE channel = '" . $channel . "' AND title='" . $title . "'") or die(mysql_error());
- if (verboseOutput == 'yes')
- {
- echoIfNotSilent($deleteresult . '<br />' . "\n");
- }
- }
- function CleanNullValues()
- {
- $replacearray[] = "For details please refer to www.wtv.co.nz";
- $replacearray[] = "No Description Available";
- $replacearray[] = "C42 plays back-to-back alternative music 24-hours a day.";
- $replacearray[] = "CCTV International offers a Chinese perspective on international and national events. Available globally, presenting News with in-depth reports, expert analysis and features.";
- $replacearray[] = "Direct feed from CCTV4";
- $replacearray[] = "Direct feed from MBC";
- $replacearray[] = "Direct feed from NHK";
- $replacearray[] = "For all the latest sports news from New Zealand and around the world, catch Sport 365 Headlines.";
- $replacearray[] = "Programme to be determined.";
- $replacearray[] = "STAR PLUS the flagship channel of the STAR network is the undisputed king of Hindi general entertainment in India. Over 65 million viewers tune-in to India's No 1 channel. More info www.startv.com";
- $replacearray[] = "Phone the studio on 09 360 4444 or email the dj studio@georgefm.co.nz Visit www.georgefm.co.nz for show schedules.";
- $replacearray[] = "100% New Zealand Music";
- $replacearray[] = "TBN is the world's largest religious network and America's most watched faith channel. TBN offers 24 hours of commercial-free inspirational programming that appeal to people in a wide variety of Protestant, Catholic and Messianic Jewish denominations.";
- $replacearray[] = "Direct feed from MBC";
- $replacearray[] = "Wild TV ceased broadcast on July 1st. We apologise for any inconvenience.";
- $replacearray[] = "For full programme schedules visit: http://www.dw-world.de/";
- $replacearray[] = "What's happening with the weather in your neck of the woods? We bring you the latest in weather information with regular updates from Metservice.";
- $replacearray[] = "Your tourism guide to Canterbury. 24 hours a day, 7 days a week.";
- //Remove all descriptions where
- foreach ($replacearray as $replace)
- {
- mysql_query("UPDATE tempSourcePrograms SET description=NULL WHERE description= '" . mysql_real_escape_string($replace) . "'") or die(mysql_error());
- }
- mysql_query("UPDATE tempSourcePrograms SET description=NULL WHERE title = 'Song listings on skytv.co.nz'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET category=NULL WHERE category = 'undefined, default value'") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET category='Special Interest' WHERE category = 'Special Interest '") or die(mysql_error());
- }
- function FixEmptyTVNZSportExtra()
- {
- $sportresult = mysql_query("SELECT * FROM tempSourcePrograms WHERE channel = 'FV-tvnzsportextra'"); //or die(mysql_error());
- if (mysql_num_rows($sportresult) < 1)
- {
- }
- }
- function FixTitleSuffixes()
- {
- foreach (Array("The", "A") as $prefix)
- {
- $sqlQuery = "UPDATE tempSourcePrograms SET title=TRIM(CONCAT('" . $prefix . " ', SUBSTR(title, 0, " . strval(0 - (strlen($prefix) + 2)) . "))) WHERE title LIKE '%, " . $prefix . "'";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- }
- }
- function FixMoviePrefixes()
- {
- foreach (Array("Popcorn Sessions:", "MTV Movie:", "World Cinema:", "Short Film:", "British Theatre:", "Classic Film:", "Real View:", "MOVIE:", "Rialto Premiere:") as $prefix)
- {
- $sqlQuery = "UPDATE tempSourcePrograms SET title=TRIM(SUBSTR(title, " . strval(strlen($prefix) + 1) . ")), category='Movies' WHERE title LIKE '" . mysql_real_escape_string($prefix) . "%'";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- }
- }
- function GetProgramMetadataRepeated()
- {
- $metadataSuffix[0]['searchValue'] = " HD";
- $metadataSuffix[0]['metadataField'] = "quality";
- $metadataSuffix[0]['metadataValue'] = "HD";
- $metadataSuffix[1]['searchValue'] = " (WS)";
- $metadataSuffix[1]['metadataField'] = "aspect";
- $metadataSuffix[1]['metadataValue'] = "16:9";
- foreach (Array("title", "description") as $sourceField)
- {
- foreach ($metadataSuffix as $dataset)
- {
- foreach (Array("", ".") as $valueEnd)
- {
- mysql_query("UPDATE tempSourcePrograms SET " . $dataset['metadataField'] . "='" . $dataset['metadataValue'] . "' WHERE " . $sourceField . " LIKE '%" . $dataset['searchValue'] . $valueEnd . "' AND " . $dataset['metadataField'] . " IS NULL") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $sourceField . "=TRIM(LEFT(" . $sourceField . ", LENGTH(" . $sourceField . ") " . strval(0 - strlen($dataset['searchValue'])) . ")) WHERE " . $sourceField . " LIKE '%" . $dataset['searchValue'] . $valueEnd . "'") or die(mysql_error());
- }
- }
- }
- $metadataPrefix[0]['searchValue'] = "All New ";
- $metadataPrefix[0]['metadataField'] = "premiere";
- $metadataPrefix[0]['metadataValue'] = "1";
- foreach ($metadataPrefix as $dataset)
- {
- foreach (Array("", ".") as $valueEnd)
- {
- mysql_query("UPDATE tempSourcePrograms SET " . $dataset['metadataField'] . "='" . $dataset['metadataValue'] . "' WHERE " . $sourceField . " LIKE '" . $dataset['searchValue'] . $valueEnd . "%' AND " . $dataset['metadataField'] . " IS NULL") or die(mysql_error());
- mysql_query("UPDATE tempSourcePrograms SET " . $sourceField . "=TRIM(RIGHT(" . $sourceField . ", LENGTH(" . $sourceField . ") " . strval(0 - strlen($dataset['searchValue'])) . ")) WHERE " . $sourceField . " LIKE '" . $dataset['searchValue'] . $valueEnd . "%'") or die(mysql_error());
- }
- }
- $sqlQuery = "UPDATE tempSourcePrograms SET year=RIGHT(description, 4), description=TRIM(LEFT(description, LENGTH(description) - 4)) WHERE description RLIKE '(19|20)[0-9]{2}$'";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- foreach (Array(".", "") as $yearend)
- {
- $sqlQuery = "UPDATE tempSourcePrograms SET year=CONVERT(SUBSTRING(description, LENGTH(description) " . strval(0 - strlen("1948)" . $yearend) + 2) . ", 4), UNSIGNED INTEGER), description=TRIM(LEFT(description, LENGTH(description) " . strval(0 - strlen("(1984)" . $yearend)) . ")) WHERE description RLIKE '(19|20)[0-9]{2}" . $yearend . "$'";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- }
- foreach (Array("Starring:", "Starring ", "Stars:") as $starringtext)
- {
- $programs = mysql_query("SELECT file, description FROM tempSourcePrograms WHERE description RLIKE '" . $starringtext . "[[:alpha:][.space.][.comma.][.hyphen.][.apostrophe.]]+[[.period.]]{0,1}$'") or die(mysql_error());
- while ($program = mysql_fetch_assoc($programs))
- {
- preg_match("~" . $starringtext . "(?P<actors>[a-zA-Z ,\-\']+\.{0,1})$~ism", $program['description'], $result);
- if (!is_null($result))
- {
- $sqlQuery = "UPDATE tempSourcePrograms SET actors='" . mysql_real_escape_string(trim(rtrim(str_replace(", ", ",", $result['actors']), "."))) . "', description=TRIM(LEFT(description, LENGTH(description) " . strval(0 - strlen($starringtext . $result['actors'] . ".")) . ")) WHERE file='" . mysql_real_escape_string($program['file']) . "'";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- }
- }
- }
- foreach (Array("Director:", "Dir:", "Directed by ") as $directortext)
- {
- $programs = mysql_query("SELECT file, description FROM tempSourcePrograms WHERE description RLIKE '" . $directortext . "[[:alpha:][.space.][.comma.][.hyphen.][.apostrophe.]]+[[.period.]]{0,1}$'") or die(mysql_error());
- while ($program = mysql_fetch_assoc($programs))
- {
- preg_match("~" . $directortext . "(?P<directors>[a-zA-Z ,\-\']+\.{0,1})$~ism", $program['description'], $result);
- if (!is_null($result))
- {
- $sqlQuery = "UPDATE tempSourcePrograms SET directors='" . mysql_real_escape_string(trim(rtrim(str_replace(", ", ",", $result['directors']), "."))) . "', description=TRIM(LEFT(description, LENGTH(description) " . strval(0 - strlen($directortext . $result['directors'] . ".")) . ")) WHERE file='" . mysql_real_escape_string($program['file']) . "'";
- //echoIfNotSilent($sqlQuery . "<br />\r\n");
- mysql_query($sqlQuery) or die(mysql_error());
- }
- }
- }
- //Description starting with:
- //FV - 'Jack's Back'.
- //mgm on YH - 2001: or 2001. for films
- //Drama: for YH films
- //Part x:
- //Pt x.
- //Pt 3 of 3. Time:
- //Description ending with:
- // Starring: Julia Roberts. (WS). HD.
- // (2007)
- // Starring: Sean Connery, Michelle Pfeiffer.
- // Starring: Julia Roberts.
- //Thriller: 1988: A jaded New Yorker thinks she has found tranquility in a suburban Arizona town but starts to suspect her husband may be a vicious serial killer as he tries to prove his innocence. Starring: David Keith, Cathy Moriarty
- }
- function GetProgramMetadata()
- {
- $advertArray = Array("Infomercials", "Infomercials.", "Infomercials for your shop at home pleasure.");
- mysql_query("UPDATE tempSourcePrograms SET category='Shopping', description=NULL WHERE " . sqlOR($advertArray, "description")) or die(mysql_error());
- $advertArray = Array("Infomercials", "Home Shopping", "Infomercial 2003");
- mysql_query("UPDATE tempSourcePrograms SET category='Shopping', description=NULL WHERE " . sqlOR($advertArray, "title")) or die(mysql_error());
- foreach (Array(":", ".", " ") as $subtitleend)
- {
- $programs = mysql_query("SELECT file, description FROM tempSourcePrograms WHERE description LIKE '\'%\'" . $subtitleend . "%' AND sub_title IS NULL") or die(mysql_error());
- while ($program = mysql_fetch_assoc($programs))
- {
- preg_match("~^'(?P<subtitle>.*?)'" . $subtitleend . "~ism", $program['description'], $result);
- if (!is_null($result))
- {
- mysql_query("UPDATE tempSourcePrograms SET sub_title='" . mysql_real_escape_string(trim($result['subtitle'])) . "', descr…
Large files files are truncated, but you can click here to view the full file