New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow custom poster images #103
Changes from 15 commits
033611f
a134748
d547636
5a8f0f8
f793d37
c6cc002
eeec257
c55e46c
fb0a532
ab46482
645fd18
b1cee1c
af53555
526fd9a
23ccadc
4d975e8
bd1eade
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE `media` ADD `poster` VARCHAR(255) NULL AFTER `url`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
require_once dirname(__FILE__).'/../config.inc.php'; | ||
|
||
$mediahub = new UNL_MediaHub($dsn); | ||
|
||
$list = new UNL_MediaHub_MediaList(array( | ||
'filter' => new UNL_MediaHub_MediaList_Filter_WithPoster() | ||
)); | ||
|
||
$list->options['limit'] = 3000; | ||
$list->run(); | ||
|
||
if (count($list->items)) { | ||
foreach ($list->items as $media) { | ||
if (empty($media->poster)) { | ||
continue; | ||
} | ||
|
||
// Try and get the poster | ||
if (substr($media->poster, 0, 5) == 'http:' | ||
|| substr($media->poster, 0, 6) == 'https:') { | ||
$context = stream_context_create(array('http'=>array( | ||
'method' => 'GET', | ||
'user_agent' => 'UNL MediaHub/mediahub.unl.edu' | ||
))); | ||
|
||
if ($result = @file_get_contents($media->poster, null, $context, -1, 8)) { | ||
// Assume OK, $result would === false if there was a 404 | ||
continue; | ||
} | ||
|
||
if (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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The status header will always be the first in the array (no need to check the others). Also, not all servers will respond with 404 is also not the only problematic response. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very true. I was just copy/pasting the find404Media script. Both could use an update. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it would be better to look for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. That would be better and can be easily parse by exploding the first header on whitespace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed in mfairchild365@bd1eade |
||
// 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(); | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
class UNL_MediaHub_MediaList_Filter_WithPoster implements UNL_MediaHub_Filter | ||
{ | ||
function __construct() | ||
{ | ||
|
||
} | ||
|
||
function apply(Doctrine_Query &$query) | ||
{ | ||
$query->where('m.poster IS NOT NULL AND m.poster != ""'); | ||
} | ||
|
||
function getLabel() | ||
{ | ||
return 'Media with posters'; | ||
} | ||
|
||
function getType() | ||
{ | ||
return ''; | ||
} | ||
|
||
function getValue() | ||
{ | ||
return ''; | ||
} | ||
|
||
function __toString() | ||
{ | ||
return ''; | ||
} | ||
|
||
public static function getDescription() | ||
{ | ||
return 'Find media with custom poster images defined'; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a
HEAD
request?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in mfairchild365@4d975e8