Skip to content

Instantly share code, notes, and snippets.

@tayfunerbilen
Created April 14, 2016 13:30
Show Gist options
  • Save tayfunerbilen/53e29f221335576985b70c58b0c8dee6 to your computer and use it in GitHub Desktop.
Save tayfunerbilen/53e29f221335576985b70c58b0c8dee6 to your computer and use it in GitHub Desktop.
IMDB için ilgili diziye ait bölümlerin listesini array olarak geriye döndürür
<?php
/**
* @param $imdbID
* @param $season
* @return array
*/
function imdbEpisode($imdbID, $season)
{
$url = 'http://www.imdb.com/title/' . $imdbID . '/episodes/_ajax?season=' . $season;
$open = file_get_contents($url);
$open = str_replace(["\n", "\r", "\t"], null, $open);
preg_match_all('@<div class="airdate">(.*?)</div>@', $open, $dates);
$dates = array_map(function ($item) {
return date('Y-m-d', strtotime(str_replace('.', '', trim($item))));
}, $dates[1]);
preg_match_all('@<a href="/title/(.*?)"title="(.*?)" itemprop="name">(.*?)</a>@', $open, $names);
$names = $names[3];
preg_match_all('@<div>S([0-9]+), Ep([0-9]+)</div>@', $open, $episodeNumber);
$episodes = [];
foreach ($episodeNumber[1] as $i => $val) {
$episodes[] = [
'episode_season' => $val,
'episode_number' => $seasonAndEpisode[2][$i],
'episode_name' => $names[$i],
'episode_date' => $dates[$i]
];
}
return $episodes;
}
// usage
print_r( imdbEpisode('tt0903747', 2) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment