Skip to content
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

Added "Se coucher moins bête" bridge #11

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Supported sites/pages
* `Identi.ca` : Identica user timeline (Should be compatible with other Pump.io instances).
* `YouTube` : YouTube user channel feed.
* `Cryptome` : Returns the most recent documents from Cryptome.org.
* `Se coucher moins bête` : Returns the most recent anecdotes from Secouchermoinsbete.fr with their embedded content


Output format
Expand Down Expand Up @@ -52,6 +53,7 @@ Patch/contributors :
* [Mitsukarenai](https://github.com/Mitsukarenai) : Initial inspiration, TwitterBridge, IdenticaBridge, YoutubeBridge.
* [ArthurHoaro](https://github.com/ArthurHoaro)
* [BoboTiG](https://github.com/BoboTiG)
* [supitalp](https://github.com/supitalp) : Se coucher moins bête Bridge

Licence
===
Expand Down
72 changes: 72 additions & 0 deletions bridges/ScmbBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* RssBridgeSeCoucherMoinsBete
* Returns the newest anecdotes
*
* @name Se Coucher Moins Bête Bridge
* @description Returns the newest anecdotes with their embedded content if any (additional details, picture, video)
*/
class ScmbBridge extends BridgeAbstract{

public function collectData(array $param){
$html = '';
$html = file_get_html('http://secouchermoinsbete.fr/') or $this->returnError('Could not request Se Coucher Moins Bete.', 404);

foreach($html->find('article') as $article) {
$item = new \Item();
$item->uri = 'http://secouchermoinsbete.fr'.$article->find('p.summary a',0)->href;
$item->title = $article->find('header h1 a',0)->innertext;

$article->find('span.read-more',0)->outertext=''; // remove text "En savoir plus" from anecdote content
$content = $article->find('p.summary a',0)->innertext;
$content =substr($content,0,strlen($content)-17); // remove superfluous spaces at the end

// get publication date
$str_date = $article->find('time',0)->datetime;
list($date, $time) = explode(' ', $str_date);
list($y, $m, $d) = explode('-', $date);
list($h, $i) = explode(':', $time);
$timestamp = mktime($h,$i,0,$m,$d,$y);
$item->timestamp = $timestamp;

// TODO: this should be optional since it is highly time and broadband consuming
// check if the anecdote has more content to offer (text details, picture, video) and follow link to retrieve it if that is the case
$optcontent = $article->find('div.metadata-list a');
$hasPic = (preg_match("#pas#", $optcontent[0]->innertext)) ? false : true;
$hasVid = (preg_match("#pas#", $optcontent[1]->innertext)) ? false : true;
$hasDetails = (preg_match("#pas#", $optcontent[2]->innertext)) ? false : true;

if($hasDetails || $hasPic || $hasVid) $opt_html = file_get_html($item->uri);
if($hasDetails){
$details = $opt_html->find('p.details',0)->innertext;
$content = $content . '<br />' . $details;
}
if($hasPic){
$picUri = $opt_html->find('div#sources-image-wrapper a',0)->href;
$item->pictureUri = $picUri;
$content = $content . '<br /><img src="' . $item->pictureUri . '" />';
}
if($hasVid){
$vidUri = $opt_html->find('div#sources-video-wrapper iframe',0)->src;
$vidUri = explode('?', $vidUri)[0]; // remove "?autoplay=0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A éviter. A priori, ne fonctionne pas avec PHP 5.3.

$item->vidUri = $vidUri;
$content = $content . ' <a href="' . $vidUri . '">Vidéo</a>';
}

$item->content = $content;
$this->items[] = $item;
}
}

public function getName(){
return 'Se Coucher Moins Bête Bridge';
}

public function getURI(){
return 'http://secouchermoinsbete.fr/';
}

public function getCacheDuration(){
return 21600; // 6 hours
}
}