Last active
December 16, 2015 00:49
-
-
Save septor/5350941 to your computer and use it in GitHub Desktop.
Logically parse TVRage's "shows on tonight" RSS feed. Allows you to define a list of shows to be displayed. Display format is as follows: TIME SHOWNAME EPISODE -- 10:00PM Elementary (03x19)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Display a list of configurable shows that is on today. | |
$showList = array | |
( | |
'Supernatural', | |
'Person of Interest', | |
'Elementary', | |
'The Five' | |
); | |
$timeOffset = -6; // in hours, can be negative. | |
/* | |
--------------------- | |
You shouldn't have to modify anything below this line. | |
If you do let me know so I can make the adjustments as well! | |
--------------------- | |
*/ | |
// XML FILE LOL | |
$xml = simplexml_load_file( "http://www.tvrage.com/myrss.php" ); | |
// TVRage has a shitty RSS file. | |
// Let's build a new list to start with. | |
$build = ""; | |
for ( $i = 0; $i <= count($xml->channel->item) - 1; $i++ ) | |
{ | |
$show = $xml->channel->item[$i]->title; | |
if ( substr ( $show, 0, 1 ) == "-" ) | |
{ | |
// Place a single line break between the shows. | |
$build .= str_replace( "- ", "", $show )."\n"; | |
} | |
else | |
{ | |
// Place a double line break after the last show and the new times. | |
// Omitting the first time slot, eg: the first line. | |
if ( $i != 0 ) | |
{ | |
$build .= "\n"; | |
} | |
$build .= $show."\n"; | |
} | |
} | |
// Now that we have our new list, let's put the timeslots (and shows) into an array. | |
$timeslots = explode( "\n\n", $build ); | |
// Loop through all the timeslots.. | |
foreach ( $timeslots as $timeslot ) | |
{ | |
// Put the shows in the timeslot into an array. | |
$shows = explode( "\n", $timeslot ); | |
// Since our first item in the array is the time, let's skip it from the for loop. | |
for ( $x = 1; $x <= count($shows) - 2; $x++ ) | |
{ | |
// We need to remove the spaces, capitalize the meridian, and remove any leading zeros from the hours. | |
$showTime = strtoupper( str_replace( " ", "", ( $shows[0][0] == "0" ? substr( $shows[0], 1 ) : $shows[0] ) ) ); | |
// We don't need to do anything with this. This is for clarity below. | |
$showTitle = $shows[$x]; | |
// Only display shows we care about. | |
foreach ( $showList as $item ) | |
{ | |
if (strpos( $showTitle, $item ) !== false) | |
{ | |
// Only display shows that haven't aired yet. | |
if ( strtotime( date( "h:iA", ( time() + ( $timeOffset * 60 * 60 ) ) ) ) < strtotime( $showTime ) ) | |
{ | |
// Put the time before the show, and then display it. | |
echo $showTime." ".$showTitle."<br />"; | |
} | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment