diff --git a/bridges/DailymotionBridge.php b/bridges/DailymotionBridge.php index ff8d4828..dc4f5d3f 100644 --- a/bridges/DailymotionBridge.php +++ b/bridges/DailymotionBridge.php @@ -4,7 +4,7 @@ class DailymotionBridge extends BridgeAbstract { const MAINTAINER = 'mitsukarenai'; const NAME = 'Dailymotion Bridge'; const URI = 'https://www.dailymotion.com/'; - const CACHE_TIMEOUT = 10800; // 3h + const CACHE_TIMEOUT = 3600; // 1h const DESCRIPTION = 'Returns the 5 newest videos by username/playlist or search'; const PARAMETERS = array ( @@ -27,74 +27,99 @@ class DailymotionBridge extends BridgeAbstract { ), 'pa' => array( 'name' => 'Page', - 'type' => 'number' + 'type' => 'number', + 'defaultValue' => 1, ) ) ); - protected function getMetadata($id){ - $metadata = array(); - $html2 = getSimpleHTMLDOM(self::URI . 'video/' . $id); - if(!$html2) { - return $metadata; - } + private $feedName = ''; - $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'); - $metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content'); - return $metadata; - } + private $apiUrl = 'https://api.dailymotion.com'; + private $apiFields = 'created_time,description,id,owner.screenname,tags,thumbnail_url,title,url'; public function getIcon() { return 'https://static1-ssl.dmcdn.net/images/neon/favicons/android-icon-36x36.png.vf806ca4ed0deed812'; } - public function collectData(){ - $html = ''; - $limit = 5; - $count = 0; + public function collectData() { - $html = getSimpleHTMLDOM($this->getURI()) - or returnServerError('Could not request Dailymotion.'); + if ($this->queriedContext === 'By username' || $this->queriedContext === 'By playlist id') { - foreach($html->find('div.media a.preview_link') as $element) { - if($count < $limit) { + $apiJson = getContents($this->getApiUrl()) + or returnServerError('Could not request: ' . $this->getApiUrl()); + + $apiData = json_decode($apiJson, true); + + $this->feedName = $this->getPlaylistTitle($this->getInput('p')); + + foreach ($apiData['list'] as $apiItem) { $item = array(); + + $item['uri'] = $apiItem['url']; + $item['uid'] = $apiItem['id']; + $item['title'] = $apiItem['title']; + $item['timestamp'] = $apiItem['created_time']; + $item['author'] = $apiItem['owner.screenname']; + $item['content'] = '
' . $apiItem['description'] . '
'; + $item['categories'] = $apiItem['tags']; + $item['enclosures'][] = $apiItem['thumbnail_url']; + + $this->items[] = $item; + } + } + + if ($this->queriedContext === 'From search results') { + + $html = getSimpleHTMLDOM($this->getURI()) + or returnServerError('Could not request Dailymotion.'); + + foreach($html->find('div.media a.preview_link') as $element) { + $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']; $item['content'] = '