tvdb.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?
  2. require 'config.php';
  3. # Build a series URL from the ID and optional LID
  4. function TVDBURL($id, $lid) {
  5. global $TVDB_URL;
  6. $url = false;
  7. if (!$lid) {
  8. $lid = $TVDB_LANG_ID;
  9. }
  10. if ($id) {
  11. $url = $TVDB_URL . '&id=' . $id . '&lid=' . $lid;
  12. }
  13. return $url;
  14. }
  15. function getTVDBPage($id, $lid) {
  16. $url = TVDBURL($id, $lid);
  17. $ctx = stream_context_create(array(
  18. 'http' => array( 'timeout' => 15 )
  19. ));
  20. return @file_get_contents($url, 0, $ctx);
  21. }
  22. # Plain-text title of a TVDB entity (or FALSE on failure)
  23. function getTVDBTitle($id, $lid) {
  24. $retval = false;
  25. $page = getTVDBPage($id, $lid);
  26. if ($page) {
  27. if (preg_match('/\<h1\>([^\>]+)\<\/h1\>/i', $page, $matches)) {
  28. $retval = $matches[1];
  29. }
  30. }
  31. return $retval;
  32. }
  33. # Get the seasons of a TVDB entity
  34. function getTVDBSeasons($id, $lid) {
  35. $retval = false;
  36. $page = getTVDBPage($id, $lid);
  37. if ($page) {
  38. if (preg_match_all('/class=\"seasonlink\"[^\>]*\>([^\<]+)\<\/a\>/i', $page, $matches)) {
  39. $retval = array();
  40. foreach ($matches[1] as $val) {
  41. if (preg_match('/^\d+$/', $val)) {
  42. $retval[ $val ] = true;
  43. } else if ($val == 'Specials') {
  44. $retval[0] = true;
  45. }
  46. }
  47. }
  48. }
  49. return $retval;
  50. }
  51. ?>