From 2238e8998a6a2bef95f683fd49490921d4f99dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Sun, 28 Aug 2016 13:38:01 +0200 Subject: [PATCH] [DailymotionBridge] fix + code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/DailymotionBridge.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/bridges/DailymotionBridge.php b/bridges/DailymotionBridge.php index 58dfe8f..7849ba6 100644 --- a/bridges/DailymotionBridge.php +++ b/bridges/DailymotionBridge.php @@ -35,8 +35,11 @@ class DailymotionBridge extends BridgeAbstract{ function getMetadata($id) { $metadata=array(); - $html2 = $this->getSimpleHTMLDOM('http://www.dailymotion.com/video/'.$id) - or $this->returnServerError('Could not request Dailymotion.'); + $html2 = $this->getSimpleHTMLDOM($this->uri.'video/'.$id); + if(!$html2){ + return $metadata; + } + $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['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content'); @@ -57,6 +60,9 @@ class DailymotionBridge extends BridgeAbstract{ $item = array(); $item['id'] = str_replace('/video/', '', strtok($element->href, '_')); $metadata = $this->getMetadata($item['id']); + if(empty($metadata)){ + continue; + } $item['uri'] = $metadata['uri']; $item['title'] = $metadata['title']; $item['timestamp'] = $metadata['timestamp']; @@ -84,19 +90,20 @@ class DailymotionBridge extends BridgeAbstract{ } public function getURI(){ + $uri=$this->uri; switch($this->queriedContext){ case 'By username': - $uri='http://www.dailymotion.com/user/' + $uri.='user/' .urlencode($this->getInput('u')).'/1'; break; case 'By playlist id': - $uri='http://www.dailymotion.com/playlist/' + $uri.='playlist/' .urlencode(strtok($this->getInput('p'), '_')); break; case 'From search results': - $uri='http://www.dailymotion.com/search/' + $uri.='search/' .urlencode($this->getInput('s')); - if(isset($this->getInput('pa'))){ + if($this->getInput('pa')){ $uri.='/'.$this->getInput('pa'); } break;