Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




Recent Comments

Powered by Disqus




Back to articles

Episode tracker class

Here is Episode tracker class, which can be used to get TV show episodes information from IMDB.

This class uses IMDB API from http://imdbapi.poromenos.org/ which is database of TV series and Episodes updated every day from IMDB interface files

It can search for TV series by exact names or similar names or combined method, return list of episodes and restructure it by seasons

And output restructured array with simple hide/show ability using javascript

It can also check if episode exists in specified TV show, so you can use it as dictionary to rename your existing episodes etc.

Here is an example of website using this class: Episode-tracker.co.cc

Contents

Download

Example codes

<?php
//This is an example usage of Episode tracker class
//There are two type of arrays used in this class
//First type is an episode list in random order, just for dictionary purpose
//Other is restructured array where episodes are grouped in right order by seasons
//There is also an example of using print_episodes method with hide/show ablity


//declaring class instance
include("./ep_track.class.php");
$ep = new ep_track();

/*---------------------------------------------------------------------*/
//Getting similar TV series by specified name,
//if only one found returns episode list
//if multiple, returns TV series names

//$arr = $ep->get_similar_names("Big theory"); //only one found(The Big bang theory)
$arr = $ep->get_similar_names("Lie"); //multiple TV series found
//checking for errors
$errors = $ep->get_errors();
if(!empty($errors))
{
    foreach($errors as $error)
    {
        echo "<p>".$error."</p>";
    }
}
else // no error output array
{
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
    //if multiple TV series provided next step to do is us get_exact_names 
    //for each TV series name
}

/*---------------------------------------------------------------------*/
//Getting TV series by exact name,
//if only one found returns episode list
//if multiple, returns TV series names

//Searching for exact names
$arr = $ep->get_exact_names("How I met your mother"); //only one found
//$arr = $ep->get_exact_names("Iron man"); //multiple TV series found


//checking for errors
$errors = $ep->get_errors();
if(!empty($errors))
{
    foreach($errors as $error)
    {
        echo "<p>".$error."</p>";
    }
}
else // no error output array
{
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}
/*---------------------------------------------------------------------*/
//Restructuring and ordering array with list of episodes

//getting episode list
$arr = $ep->get_exact_names("How I met your mother");

//restructuring array
$arr = $ep->transform($arr);

//checking for errors
$errors = $ep->get_errors();
if(!empty($errors))
{
    foreach($errors as $error)
    {
        echo "<p>".$error."</p>";
    }
}
else // no error
{
    //printing array structure
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}

/*---------------------------------------------------------------------*/
//Using get_episodes method which automatically checks 
//for exact matches and then for similar matches if no exact founds
//and returns restructured array (like after transform method) 
//of episodes of TV series that ar most similar to specified one

//Getting episodes
$arr = $ep->get_episodes("Iron");

//checking for errors
$errors = $ep->get_errors();
if(!empty($errors))
{
    foreach($errors as $error)
    {
        echo "<p>".$error."</p>";
    }
}
else // no error
{
    //printing array structure
    echo "<pre>";
    //print_r($arr);
    echo "</pre>";
    //or using print_episodes method with hide/show ability for seasons using javascript
    //pass false as second parameter if don't want to use hide/show
    $ep->print_episodes($arr, true);
}

/*---------------------------------------------------------------------*/
//Checking if episode with wildcard %name% exists in TV series
//if exists returns array with all episodes mathicng wildcard 
//with exact episode name, season and episode numbers

//Checking if there is an episode with specified substring
$arr = $ep->check_episode("or false", "How I met your mother");

//checking for errors
$errors = $ep->get_errors();
if(!empty($errors))
{
    foreach($errors as $error)
    {
        echo "<p>".$error."</p>";
    }
}
else // no error
{
    echo "<pre>";
    print_r($arr);
    echo "</pre>";
}

?>

Examples in action

Example scripts provided with package in action:

Method list

Get errors

Back to method list

Method nameget_errors()
DescriptionReturns array with errors or empty array if there was no errors
Example output
Array
(
    [0] => No TV series name provided for search
)

Get similar TV show names

Back to method list

Method nameget_similar_names($name)
DescriptionWill check for similar TV show names, method returns array with up to 15 (API limitation) tv series names or faslse if nothing similar found
Input parametersstring $name - Full or part of the name of TV series
Example inputget_similar_names("House")
Example output
Array
(
    [shows] => Array
        (
            [0] => Array
                (
                    [name] => American Playhouse
                    [year] => 1982
                )

            [1] => Array
                (
                    [name] => Anthea Turner: Perfect Housewife
                    [year] => 2006
                )

            [2] => Array
                (
                    [name] => Archie's Fun House
                    [year] => 1970
                )

            [3] => Array
                (
                    [name] => Ask This Old House
                    [year] => 2003
                )

            [4] => Array
                (
                    [name] => BBC2 Playhouse
                    [year] => 1974
                )
			.....
        )

)

Search by exact TV show name

Back to method list

Method nameget_exact_names($name, $year = "")
Description

Will look for exact name matches. Method will return false if nothing found or array of episodes, if only one exact match found or array of TV series names if multiple TV series with same name found (provide year to exclude this situation).

To differ this situation: If first key is 'shows', it means multiple shows with same name were returned, else first key should always be TV show name. Look at examples

Input parameters

string $name - Full or part of the name of TV series

int $year - year of first release of TV show(optional)

Example input for exact matchget_similar_names("How I met your mother")
Example output
 for exact match
Array
(
    [How I Met Your Mother] => Array
        (
            [episodes] => Array
                (
                    [0] => Array
                        (
                            [season] => 2
                            [name] => Aldrin Justice
                            [number] => 6
                        )

                    [1] => Array
                        (
                            [season] => 2
                            [name] => Arrivederci, Fiero
                            [number] => 17
                        )

                    [2] => Array
                        (
                            [season] => 4
                            [name] => As Fast as She Can
                            [number] => 23
                        )

                    [3] => Array
                        (
                            [season] => 2
                            [name] => Atlantic City
                            [number] => 8
                        )

                    [4] => Array
                        (
                            [season] => 2
                            [name] => Bachelor Party
                            [number] => 19
                        )

                    [5] => Array
                        (
                            [season] => 5
                            [name] => Bagpipes
                            [number] => 6
                        )
					.......
				}
		}
}
Example input for exact match of multiple different TV showsget_similar_names("Iron man")
Example output for exact match of multiple different TV shows
 for exact match
Array
(
    [shows] => Array
        (
            [0] => Array
                (
                    [name] => Iron Man
                    [year] => 1966
                )

            [1] => Array
                (
                    [name] => Iron Man
                    [year] => 1994
                )

            [2] => Array
                (
                    [name] => Iron Man
                    [year] => 2010
                )

        )

)

Sort result by seasons and episodes

Back to method list

Method nametransform($arr)
Description

This method restructures episodes and seasons provided in random order by API from get_exact_names result array to sorted array with structure Array(season_number=> Array(episode_number=>episode_name)) like in method get_episodes

Input parameters

array $arr - Result from get_exact_names method

Example inputtransform(get_exact_names("How I met your mother"))
Example output
Array
(
    [How I Met Your Mother (2005)] => Array
        (
            [1] => Array
                (
                    [1] => Pilot
                    [2] => Purple Giraffe
                    [3] => The Sweet Taste of Liberty
                    [4] => Return of the Shirt
                    [5] => Okay Awesome
                    [6] => The Slutty Pumpkin
                    [7] => Matchmaker
                    [8] => The Duel
                    [9] => Belly Full of Turkey
                    [10] => The Pineapple Incident
                    [11] => The Limo
                    [12] => The Wedding
                    [13] => Drumroll, Please
                    [14] => Zip, Zip, Zip
                    [15] => Game Night
                    [16] => Cupcake
                    [17] => Life Among the Gorillas
                    [18] => Nothing Good Happens After 2 AM
                    [19] => Mary the Paralegal
                    [20] => Best Prom Ever
                    [21] => Milk
                    [22] => Come On
                )

            [2] => Array
                (
                    [1] => Where Were We?
                    [2] => The Scorpion and the Toad
                    [3] => Brunch
                    [4] => Ted Mosby, Architect
                    [5] => World's Greatest Couple
                    [6] => Aldrin Justice
                    [7] => Swarley
                    [8] => Atlantic City
                    [9] => Slap Bet
                    [10] => Single Stamina
                    [11] => How Lily Stole Christmas
                    [12] => First Time in New York
                    [13] => Columns
                    [14] => Monday Night Football
                    [15] => Lucky Penny
                    [16] => Stuff
                    [17] => Arrivederci, Fiero
                    [18] => Moving Day
                    [19] => Bachelor Party
                    [20] => Showdown
                    [21] => Something Borrowed
                    [22] => Something Blue
                )
			.....
		}
}

Combined method - exact and similar

Back to method list

Method nameget_episodes($name, $year = "")
Description

This method combines exact and similar searches. It searches for TV series first by exact name matches, if no exact matches found, it searches for similar name matches and getting TV series with most similar name using php similar_text function. Then it restructures array by seasons and episodes using transform method and returns restructured array or returns false if there are no exact and similar matches

Input parameters

string $name - Full or part of the name of TV series

int $year - year of first release of TV show(optional)

Example inputget_episodes("How I met your mother")
Example output
Array
(
    [How I Met Your Mother (2005)] => Array
        (
            [1] => Array
                (
                    [1] => Pilot
                    [2] => Purple Giraffe
                    [3] => The Sweet Taste of Liberty
                    [4] => Return of the Shirt
                    [5] => Okay Awesome
                    [6] => The Slutty Pumpkin
                    [7] => Matchmaker
                    [8] => The Duel
                    [9] => Belly Full of Turkey
                    [10] => The Pineapple Incident
                    [11] => The Limo
                    [12] => The Wedding
                    [13] => Drumroll, Please
                    [14] => Zip, Zip, Zip
                    [15] => Game Night
                    [16] => Cupcake
                    [17] => Life Among the Gorillas
                    [18] => Nothing Good Happens After 2 AM
                    [19] => Mary the Paralegal
                    [20] => Best Prom Ever
                    [21] => Milk
                    [22] => Come On
                )

            [2] => Array
                (
                    [1] => Where Were We?
                    [2] => The Scorpion and the Toad
                    [3] => Brunch
                    [4] => Ted Mosby, Architect
                    [5] => World's Greatest Couple
                    [6] => Aldrin Justice
                    [7] => Swarley
                    [8] => Atlantic City
                    [9] => Slap Bet
                    [10] => Single Stamina
                    [11] => How Lily Stole Christmas
                    [12] => First Time in New York
                    [13] => Columns
                    [14] => Monday Night Football
                    [15] => Lucky Penny
                    [16] => Stuff
                    [17] => Arrivederci, Fiero
                    [18] => Moving Day
                    [19] => Bachelor Party
                    [20] => Showdown
                    [21] => Something Borrowed
                    [22] => Something Blue
                )
			.....
		}
}

Print out seasons and episodes with hide/show feature

Method nameprint_episodes($arr, $hide = true, $level = 0)
Description

This method recursively prints out episodes from restructured arrays in ul and li elements and provides simple hide/show abiltiy for seasons using javascript if parameter $hide is passed as true

Input parameters

array $arr - restructured array from transform method or method

boolean $hide - provide simple hide/show feature using javascript

int $level - to determine level of recursion, function should always be called with default 0 parameter

Example inputprint_episodes(get_episodes("How I met your mother"))
Example output
  • How I Met Your Mother (2005)
    • Season 1
    • Season 2
    • Season 3
    • Season 4
    • Season 5
    • Season 6

Check if episode exists

Back to method list

Method namecheck_episode($episode, $tv_series, $year = "")
Description

Checks if episode with similar name exists in provided TV series. Method returns array with exact episode name, season and episode number if found, else returns false. This method takes mixed type for TV series name parameter. It could be string with exact TV series name. Array with list of episodes from TV series using get_exact_names and get_similar_names methods. Or restructured array from transform or get_episodes method

Input parameters

string $episode - Episode name

mixed $tv_series - TV series name in string or structured or restructured array

int $year - year of first release of TV show(optional)

Example inputcheck_episode("purple", get_episodes("How I met your mother"))
Example output
Array
(
    [0] => Array
        (
            [name] => Purple Giraffe
            [season] => 1
            [episode] => 2
        )

)

Possible error messages

List of all errors and meanings

Error textMeaningSolution
No TV series name provided for searchTV series name is emptyProvide TV series name
No similar matches foundNo TV series foundCheck TV series name or try another one
No exact matches foundNo TV series foundCheck TV series name or try another one
API server error! Provided TV series name, that doesn't have episodesTV series exists, but it has no episodesAlthough this situation is possible, still it might be an API error
Incorrect array structure. Use array with episode listYou provided incorrect array structureUse array from get_exact_names and get_similar_names methods
Parameter is not an arrayParameter you provided is not an arrayProvide array
Parameter is not an arrayParameter you provided is not an arrayProvide array

Latest changes

27.08.2010 - added support for non cURL users


You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus