Skip to content

Commit

Permalink
Use a better check for missing posters
Browse files Browse the repository at this point in the history
The status header will always be the first in the array (no need to check the others). Also, not all servers will respond with HTTP/1.1. Also, servers will not always use the string Not Found. Only the response code is guaranteed by the protocol.

404 is also not the only problematic response.
  • Loading branch information
mfairchild365 committed Nov 12, 2013
1 parent 4d975e8 commit bd1eade
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions scripts/find404Posters.php
Expand Up @@ -29,17 +29,17 @@
continue;
}

if (false === $http_response_header) {
if (!isset($http_response_header) ||
false === $http_response_header) {
echo 'DNS failure, did the server move?'.PHP_EOL;
}

foreach ($http_response_header as $header) {
if (strpos($header, 'HTTP/1.1 404 Not Found') !== false) {
// This file is GONE! Better remove it
echo 'REMOVING POSTER-'.PHP_EOL.'ID: '.$media->id.PHP_EOL.'Title: '.$media->title.PHP_EOL.'POSTER URL: '.$media->poster.PHP_EOL.PHP_EOL;
$media->poster = '';
$media->save();
}
if (!isset($http_response_header[0])
|| strpos($http_response_header[0], '200') === false) {
// This file is GONE! Better remove it
echo 'REMOVING POSTER-'.PHP_EOL.'ID: '.$media->id.PHP_EOL.'Title: '.$media->title.PHP_EOL.'POSTER URL: '.$media->poster.PHP_EOL.PHP_EOL;
$media->poster = '';
$media->save();
}
}
}
Expand Down

0 comments on commit bd1eade

Please sign in to comment.