Zachary Kotlarek před 13 roky
rodič
revize
a3fddb4ca3
3 změnil soubory, kde provedl 51 přidání a 15 odebrání
  1. 1 0
      web/includes/config.php
  2. 48 8
      web/includes/tvdb.php
  3. 2 7
      web/includes/webloc.php

+ 1 - 0
web/includes/config.php

@@ -5,5 +5,6 @@ $TV_PATH       = $MEDIA_PATH . '/TV';
 $EXISTS_FILES  = array('no_quality_checks', 'more_number_formats', 'skip');
 $CONTENT_FILES = array('must_match', 'search_name');
 $TVDB_URL      = 'http://thetvdb.com/?tab=series';
+$TVDB_LANG_ID  = 7;
 
 ?>

+ 48 - 8
web/includes/tvdb.php

@@ -2,21 +2,61 @@
 
 require 'config.php';
 
-# Get the title of a TVDB entity
-function getTVDBTitle($id) {
-	$retval = false;
-	return $retval;
+# Build a series URL from the ID and optional LID
+function TVDBURL($id, $lid) {
+	global $TVDB_URL;
+	$url = false;
+
+	if (!$lid) {
+		$lid = $TVDB_LANG_ID;
+	}
+	if ($id) {
+		$url = $TVDB_URL . '&id=' . $id . '&lid=' . $lid;
+	}
+
+	return $url;
 }
 
-# Get the seasons of a TVDB entity
-function getTVDBSeasons($id) {
+function getTVDBPage($id, $lid) {
+	$url = TVDBURL($id, $lid);
+	$ctx = stream_context_create(array(
+		'http' => array( 'timeout' => 15 )
+	)); 
+	return @file_get_contents($url, 0, $ctx);
+}
+
+# Plain-text title of a TVDB entity (or FALSE on failure)
+function getTVDBTitle($id, $lid) {
 	$retval = false;
+
+	$page = getTVDBPage($id, $lid);
+	if ($page) {
+		if (preg_match('/\<h1\>([^\>]+)\<\/h1\>/i', $page, $matches)) {
+			$retval = $matches[1];
+		}
+	}
+
 	return $retval;
 }
 
-# Search TVDB for the named series and return all likely results
-function findTVDBSeries($series) {
+# Get the seasons of a TVDB entity
+function getTVDBSeasons($id, $lid) {
 	$retval = false;
+
+	$page = getTVDBPage($id, $lid);
+	if ($page) {
+		if (preg_match_all('/class=\"seasonlink\"[^\>]*\>([^\<]+)\<\/a\>/i', $page, $matches)) {
+			$retval = array();
+			foreach ($matches[1] as $val) {
+				if (preg_match('/^\d+$/', $val)) {
+					$retval[ $val ] = true;
+				} else if ($val == 'Specials') {
+					$retval[0] = true;
+				}
+			}
+		}
+	}
+
 	return $retval;
 }
 

+ 2 - 7
web/includes/webloc.php

@@ -68,13 +68,8 @@ function readWebloc($file) {
 		$retval['tvdb-lid'] = $matches[1];
 	}
 
-	# Construct a URL
-	if ($retval['tvdb-id'] !== false) {
-		$retval['url'] = $TVDB_URL . '&id=' . $retval['tvdb-id'];
-		if ($retval['tvdb-lid'] !== false) {
-			$retval['url'] .= '&lid=' . $retval['tvdb-lid'];
-		}
-	}
+	# Grab the URL, if available
+	$retval['url'] = TVDBURL($retval['tvdb-id'], $retval['tvdb-lid']);
 
 	return $retval;
 }