1
0
Fork 0
forked from blallo/rss-bridge

[DailymotionBridge] fix

This commit is contained in:
Mitsukarenai 2016-08-02 14:24:54 +02:00
parent cb84635e2d
commit c75622135e
2 changed files with 82 additions and 82 deletions

View file

@ -1,79 +1,79 @@
<?php <?php
#ini_set('display_errors', 'On'); #ini_set('display_errors', 'On');
#error_reporting(E_ALL); #error_reporting(E_ALL);
class ArstechnicaBridge extends BridgeAbstract { class ArstechnicaBridge extends BridgeAbstract {
public function loadMetadatas() { public function loadMetadatas() {
$this->maintainer = "prysme"; $this->maintainer = "prysme";
$this->name = "ArstechnicaBridge"; $this->name = "ArstechnicaBridge";
$this->uri = "http://arstechnica.com"; $this->uri = "http://arstechnica.com";
$this->description = "The PC enthusiast's resource. Power users and the tools they love, without computing religion"; $this->description = "The PC enthusiast's resource. Power users and the tools they love, without computing religion";
$this->update = "01/08/2016"; $this->update = "01/08/2016";
} }
public function collectData(array $param) { public function collectData(array $param) {
function StripWithDelimiters($string, $start, $end) { function StripWithDelimiters($string, $start, $end) {
while (strpos($string, $start) !== false) { while (strpos($string, $start) !== false) {
$section_to_remove = substr($string, strpos($string, $start)); $section_to_remove = substr($string, strpos($string, $start));
$section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end)); $section_to_remove = substr($section_to_remove, 0, strpos($section_to_remove, $end) + strlen($end));
$string = str_replace($section_to_remove, '', $string); $string = str_replace($section_to_remove, '', $string);
} return $string; } return $string;
} }
function StripCDATA($string) { function StripCDATA($string) {
$string = str_replace('<![CDATA[', '', $string); $string = str_replace('<![CDATA[', '', $string);
$string = str_replace(']]>', '', $string); $string = str_replace(']]>', '', $string);
return $string; return $string;
} }
function ExtractContent($url) { function ExtractContent($url) {
#echo $url; #echo $url;
$html2 = file_get_html($url); $html2 = file_get_html($url);
$text = $html2->find("section[id='article-guts']", 0); $text = $html2->find("section[id='article-guts']", 0);
/*foreach ($text->find('<aside id="social-left">') as $node) /*foreach ($text->find('<aside id="social-left">') as $node)
{ $node = NULL; }*/ { $node = NULL; }*/
$text = StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>'); $text = StripWithDelimiters($text->innertext,'<aside id="social-left">','</aside>');
$text = StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>'); $text = StripWithDelimiters($text,'<figcaption class="caption">','</figcaption>');
$text = StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>'); $text = StripWithDelimiters($text,'<div class="gallery shortcode-gallery">','</div>');
//error_log("ICI", 0); //error_log("ICI", 0);
//error_log($text, 0); //error_log($text, 0);
return $text; return $text;
} }
$html = $this->file_get_html('http://feeds.arstechnica.com/arstechnica/index') or $this->returnError('Could not request NextInpact.', 404); $html = $this->file_get_html('http://feeds.arstechnica.com/arstechnica/index') or $this->returnError('Could not request NextInpact.', 404);
$limit = 0; $limit = 0;
foreach($html->find('item') as $element) { foreach($html->find('item') as $element) {
if($limit < 5) { if($limit < 5) {
$item = new \Item(); $item = new \Item();
$item->title = StripCDATA($element->find('title', 0)->innertext); $item->title = StripCDATA($element->find('title', 0)->innertext);
$item->uri = StripCDATA($element->find('guid', 0)->plaintext); $item->uri = StripCDATA($element->find('guid', 0)->plaintext);
$item->thumbnailUri = StripCDATA($element->find('enclosure', 0)->url); $item->thumbnailUri = StripCDATA($element->find('enclosure', 0)->url);
$item->author = StripCDATA($element->find('author', 0)->innertext); $item->author = StripCDATA($element->find('author', 0)->innertext);
$item->timestamp = strtotime($element->find('pubDate', 0)->plaintext); $item->timestamp = strtotime($element->find('pubDate', 0)->plaintext);
$item->content = ExtractContent($item->uri); $item->content = ExtractContent($item->uri);
//$item->content = $item->uri; //$item->content = $item->uri;
$this->items[] = $item; $this->items[] = $item;
$limit++; $limit++;
} }
} }
} }
public function getName() { public function getName() {
return 'ArsTechnica'; return 'ArsTechnica';
} }
public function getCacheDuration() { public function getCacheDuration() {
return 7200; // 2h return 7200; // 2h
} }
public function getURI() { public function getURI() {
return "http://arstechnica.com"; return "http://arstechnica.com";
} }
} }

View file

@ -9,7 +9,7 @@ class DailymotionBridge extends BridgeAbstract{
$this->name = "Dailymotion Bridge"; $this->name = "Dailymotion Bridge";
$this->uri = "https://www.dailymotion.com/"; $this->uri = "https://www.dailymotion.com/";
$this->description = "Returns the 5 newest videos by username/playlist or search"; $this->description = "Returns the 5 newest videos by username/playlist or search";
$this->update = "2014-11-18"; $this->update = "2016-08-02";
$this->parameters["By username"] = $this->parameters["By username"] =
'[ '[
@ -24,7 +24,7 @@ class DailymotionBridge extends BridgeAbstract{
{ {
"name" : "playlist id", "name" : "playlist id",
"identifier" : "p", "identifier" : "p",
"type" : "number" "type" : "text"
} }
]'; ]';
@ -47,7 +47,7 @@ class DailymotionBridge extends BridgeAbstract{
function getMetadata($id) { function getMetadata($id) {
$metadata=array(); $metadata=array();
$html2 = $this->file_get_html('http://www.dailymotion.com/video/'.$id) or $this->returnError('Could not request Dailymotion.', 404); $html2 = file_get_html('http://www.dailymotion.com/video/'.$id) or $this->returnError('Could not request Dailymotion.', 404);
$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');