Explorar el Código

Allow a few TVDB hits in rapid succession, then start throttling

Zachary Kotlarek hace 13 años
padre
commit
bd7400a562
Se han modificado 2 ficheros con 13 adiciones y 9 borrados
  1. 6 5
      web/includes/config.php
  2. 7 4
      web/includes/tvdb.php

+ 6 - 5
web/includes/config.php

@@ -5,11 +5,12 @@ $TV_PATH       = '/mnt/media/TV';	# Root path for all TV series
 $MAX_AGE       = 86400 * 90;		# Consider a series "old" if it has not been updated for this many seconds
 
 ### TVDB
-$ENABLE_TVDB   = true;		# Master enable/disable flag
-$TVDB_DELAY    = 20;		# Minimum delay between TVDB downloads
-$TVDB_TIMEOUT  = 15;		# Maximum load time for TVDB pages
-$TVDB_LANG_ID  = 7;		# Default language ID for TVDB URLs
-$TVDB_URL      = 'http://thetvdb.com/?tab=series';
+$ENABLE_TVDB      = true;	# Master enable/disable flag
+$TVDB_DELAY       = 20;		# Minimum delay between TVDB downloads
+$TVDB_DELAY_COUNT = 3;		# Number of TVDB requests allowed without throttling
+$TVDB_TIMEOUT     = 15;		# Maximum load time for TVDB pages
+$TVDB_LANG_ID     = 7;		# Default language ID for TVDB URLs
+$TVDB_URL         = 'http://thetvdb.com/?tab=series';
 
 ### App Config
 $EXISTS_FILES  = array('no_quality_checks', 'more_number_formats', 'skip');

+ 7 - 4
web/includes/tvdb.php

@@ -1,7 +1,8 @@
 <?
 
 require 'config.php';
-$LAST_TVDB_DOWNLOAD = 0;
+$TVDB_DOWNLOAD_TIME  = 0;
+$TVDB_DOWNLOAD_COUNT = 0;
 
 # Parse and input URL for TVDB ID and LID
 function parseTVDBURL($url) {
@@ -46,11 +47,13 @@ function getTVDBPage($id, $lid) {
 
 	# Sleep between downloads to avoid TVDB bans
 	global $TVDB_DELAY;
-	global $LAST_TVDB_DOWNLOAD;
-	if (time() - $LAST_TVDB_DOWNLOAD < $TVDB_DELAY) {
+	global $TVDB_DOWNLOAD_TIME;
+	global $TVDB_DOWNLOAD_COUNT;
+	if ($TVDB_DOWNLOAD_COUNT >= $TVDB_DELAY_COUNT && time() - $TVDB_DOWNLOAD_TIME < $TVDB_DELAY) {
 		sleep(rand($TVDB_DELAY, 2 * $TVDB_DELAY));
 	}
-	$LAST_TVDB_DOWNLOAD = time();
+	$TVDB_DOWNLOAD_COUNT++;
+	$TVDB_DOWNLOAD_TIME = time();
 
 	# Download with a timeout
 	global $TVDB_TIMEOUT;