[DailymotionBridge] fix + code simplification

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-28 13:38:01 +02:00
parent f1a3ed297e
commit 2238e8998a

View file

@ -35,8 +35,11 @@ class DailymotionBridge extends BridgeAbstract{
function getMetadata($id) { function getMetadata($id) {
$metadata=array(); $metadata=array();
$html2 = $this->getSimpleHTMLDOM('http://www.dailymotion.com/video/'.$id) $html2 = $this->getSimpleHTMLDOM($this->uri.'video/'.$id);
or $this->returnServerError('Could not request Dailymotion.'); if(!$html2){
return $metadata;
}
$metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content'); $metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
$metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') ); $metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') );
$metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content'); $metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
@ -57,6 +60,9 @@ class DailymotionBridge extends BridgeAbstract{
$item = array(); $item = array();
$item['id'] = str_replace('/video/', '', strtok($element->href, '_')); $item['id'] = str_replace('/video/', '', strtok($element->href, '_'));
$metadata = $this->getMetadata($item['id']); $metadata = $this->getMetadata($item['id']);
if(empty($metadata)){
continue;
}
$item['uri'] = $metadata['uri']; $item['uri'] = $metadata['uri'];
$item['title'] = $metadata['title']; $item['title'] = $metadata['title'];
$item['timestamp'] = $metadata['timestamp']; $item['timestamp'] = $metadata['timestamp'];
@ -84,19 +90,20 @@ class DailymotionBridge extends BridgeAbstract{
} }
public function getURI(){ public function getURI(){
$uri=$this->uri;
switch($this->queriedContext){ switch($this->queriedContext){
case 'By username': case 'By username':
$uri='http://www.dailymotion.com/user/' $uri.='user/'
.urlencode($this->getInput('u')).'/1'; .urlencode($this->getInput('u')).'/1';
break; break;
case 'By playlist id': case 'By playlist id':
$uri='http://www.dailymotion.com/playlist/' $uri.='playlist/'
.urlencode(strtok($this->getInput('p'), '_')); .urlencode(strtok($this->getInput('p'), '_'));
break; break;
case 'From search results': case 'From search results':
$uri='http://www.dailymotion.com/search/' $uri.='search/'
.urlencode($this->getInput('s')); .urlencode($this->getInput('s'));
if(isset($this->getInput('pa'))){ if($this->getInput('pa')){
$uri.='/'.$this->getInput('pa'); $uri.='/'.$this->getInput('pa');
} }
break; break;