PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/subtitles/addic7ed.php

http://mytvondemand.googlecode.com/
PHP | 50 lines | 46 code | 2 blank | 2 comment | 3 complexity | 3c5629d25b87ad1b5bd2c2d396351f0f MD5 | raw file
  1. <?php
  2. function fetchSubtitles($showtitle, $season, $episode, $language) {
  3. $englang = array( it => 'Italian',
  4. en => 'English',
  5. es => 'Spanish',
  6. ro => 'Romanian',
  7. pt => 'Portuguese',
  8. fr => 'French',
  9. hu => 'Hungarian',
  10. ru => 'Russian',
  11. de => 'German',
  12. sw => 'Swedish',
  13. dk => 'Dutch');
  14. /* Gathering TV Series Names */
  15. $data = file_get_contents("http://www.addic7ed.com/shows.php");
  16. preg_match_all("/\"Letter1\">(.*)/", $data, $matches);
  17. $series = $matches[1][0];
  18. preg_match_all('/href="([0-z\/]*)">(.*?)<\/a>/', $series, $matches);
  19. $links = $matches[1];
  20. $names = $matches[2];
  21. unset($matches); unset($data); unset($series);
  22. for($i=0; $i<=count($links); $i++)
  23. $series[strtolower($names[$i])] = $links[$i];
  24. unset($names); unset($links);
  25. /* Gathering Episodes */
  26. if ($series[strtolower($showtitle)] == Null)
  27. return Null;
  28. preg_match_all("/\/show\/(.*)/", $series[strtolower($showtitle)], $matches);
  29. $link = $matches[1][0];
  30. $data = str_replace("\n","",file_get_contents("http://www.addic7ed.com/ajax_loadShow.php?show=$link&season=$season"));
  31. preg_match_all("/ - [0-9]*x[0]*$episode.*?".$englang[$language].".*?>([0-9\.\% ]*)?Completed.*?(\/updated.*?)\".*?<\/table>/", $data, $matches);
  32. $sublink = $matches[2][0];
  33. $completed = $matches[1][0];
  34. unset($link); unset($matches); unset($data);
  35. /* Subtitle download */
  36. if (($sublink == Null) || ($completed != ''))
  37. return Null;
  38. $subtitle = file_get_contents("http://www.addic7ed.com".$sublink);
  39. if (strrpos($subtitle, "Daily Download count exceeded") === false) {
  40. if ($subtitle != Null)
  41. return $subtitle;
  42. else
  43. return Null;
  44. } else
  45. return null;
  46. }
  47. ?>