mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-09 16:38:50 +00:00
[RadioMelodieBridge] Fix to use the new website layout (#2330)
This commit is contained in:
parent
2ee091665a
commit
a0bbbd6978
@ -12,12 +12,7 @@ class RadioMelodieBridge extends BridgeAbstract {
|
|||||||
public function collectData(){
|
public function collectData(){
|
||||||
$html = getSimpleHTMLDOM(self::URI . '/actu/')
|
$html = getSimpleHTMLDOM(self::URI . '/actu/')
|
||||||
or returnServerError('Could not request Radio Melodie.');
|
or returnServerError('Could not request Radio Melodie.');
|
||||||
$list = $html->find('div[class=displayList]', 0)->children();
|
$list = $html->find('div[class=listArticles]', 0)->children();
|
||||||
|
|
||||||
$dateFormat = '%A %e %B %Y à %H:%M';
|
|
||||||
// Set locale and Timezone to parse the date
|
|
||||||
setlocale (LC_TIME, 'fr_FR.utf8');
|
|
||||||
date_default_timezone_set('Europe/Paris');
|
|
||||||
|
|
||||||
foreach($list as $element) {
|
foreach($list as $element) {
|
||||||
if($element->tag == 'a') {
|
if($element->tag == 'a') {
|
||||||
@ -34,7 +29,7 @@ class RadioMelodieBridge extends BridgeAbstract {
|
|||||||
$picture = array();
|
$picture = array();
|
||||||
|
|
||||||
// Get the Main picture URL
|
// Get the Main picture URL
|
||||||
$picture[] = self::URI . $article->find('div[id=pictureTitleSupport]', 0)->find('img', 0)->src;
|
$picture[] = self::URI . $article->find('figure[class=photoviewer]', 0)->find('img', 0)->src;
|
||||||
$audioHTML = $article->find('audio');
|
$audioHTML = $article->find('audio');
|
||||||
|
|
||||||
// Add the audio element to the enclosure
|
// Add the audio element to the enclosure
|
||||||
@ -57,26 +52,14 @@ class RadioMelodieBridge extends BridgeAbstract {
|
|||||||
$article->save();
|
$article->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove Radio Melodie Logo
|
// Extract the author
|
||||||
$logoHTML = $article->find('div[id=logoArticleRM]', 0);
|
$author = $article->find('div[class=author]', 0)->children(1)->children(0)->plaintext;
|
||||||
$logoHTML->outertext = '';
|
|
||||||
$article->save();
|
|
||||||
|
|
||||||
$author = $article->find('p[class=AuthorName]', 0)->plaintext;
|
|
||||||
|
|
||||||
// Handle date to timestamp
|
// Handle date to timestamp
|
||||||
$dateHTML = $article->find('p[class=date]', 0)->plaintext;
|
$dateHTML = $article->find('div[class=author]', 0)->children(1)->plaintext;
|
||||||
preg_match('/\| ([^-]*)( - .*|)$/', $dateHTML, $matches);
|
preg_match('/([a-z]{4,10}[ ]{1,2}[0-9]{1,2} [\p{L}]{4,10} [0-9]{4} à [0-9]{2}:[0-9]{2})/mus', $dateHTML, $matches);
|
||||||
$dateText = $matches[1];
|
$dateText = $matches[1];
|
||||||
$dateArray = strptime($dateText, $dateFormat);
|
$timestamp = $this->parseDate($dateText);
|
||||||
$timestamp = mktime(
|
|
||||||
$dateArray['tm_hour'],
|
|
||||||
$dateArray['tm_min'],
|
|
||||||
$dateArray['tm_sec'],
|
|
||||||
$dateArray['tm_mon'] + 1,
|
|
||||||
$dateArray['tm_mday'],
|
|
||||||
$dateArray['tm_year'] + 1900
|
|
||||||
);
|
|
||||||
|
|
||||||
$item['enclosures'] = array_merge($picture, $audio);
|
$item['enclosures'] = array_merge($picture, $audio);
|
||||||
$item['author'] = $author;
|
$item['author'] = $author;
|
||||||
@ -86,22 +69,15 @@ class RadioMelodieBridge extends BridgeAbstract {
|
|||||||
$item['timestamp'] = $timestamp;
|
$item['timestamp'] = $timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header Image
|
// Remove the share article part
|
||||||
$header = '<img src="' . $picture[0] . '"/>';
|
$textDOM->find('div[class=share]', 0)->outertext = '';
|
||||||
|
|
||||||
// Remove the Date and Author part
|
|
||||||
$textDOM->find('div[class=AuthorDate]', 0)->outertext = '';
|
|
||||||
|
|
||||||
// Remove Facebook javascript
|
|
||||||
$textDOM->find('script[src^=https://connect.facebook.net]', 0)->outertext = '';
|
|
||||||
|
|
||||||
// Rewrite relative Links
|
// Rewrite relative Links
|
||||||
$textDOM = defaultLinkTo($textDOM, self::URI . '/');
|
$textDOM = defaultLinkTo($textDOM, self::URI . '/');
|
||||||
|
|
||||||
$article->save();
|
$article->save();
|
||||||
//$this->rewriteAudioPlayers($textDOM);
|
|
||||||
$text = $textDOM->innertext;
|
$text = $textDOM->innertext;
|
||||||
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $dateHTML . '<br/>' . $header . $text;
|
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $dateText . '<br/>' . $text;
|
||||||
$this->items[] = $item;
|
$this->items[] = $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,4 +119,77 @@ class RadioMelodieBridge extends BridgeAbstract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function to parse the article date
|
||||||
|
*/
|
||||||
|
private function parseDate($date_fr)
|
||||||
|
{
|
||||||
|
// French date texts
|
||||||
|
$search_fr = array(
|
||||||
|
'janvier',
|
||||||
|
'février',
|
||||||
|
'mars',
|
||||||
|
'avril',
|
||||||
|
'mai',
|
||||||
|
'juin',
|
||||||
|
'juillet',
|
||||||
|
'août',
|
||||||
|
'septembre',
|
||||||
|
'octobre',
|
||||||
|
'novembre',
|
||||||
|
'décembre',
|
||||||
|
'lundi',
|
||||||
|
'mardi',
|
||||||
|
'mercredi',
|
||||||
|
'jeudi',
|
||||||
|
'vendredi',
|
||||||
|
'samedi',
|
||||||
|
'dimanche'
|
||||||
|
);
|
||||||
|
|
||||||
|
// English replacement date text
|
||||||
|
$replace_en = array(
|
||||||
|
'january',
|
||||||
|
'february',
|
||||||
|
'march',
|
||||||
|
'april',
|
||||||
|
'may',
|
||||||
|
'june',
|
||||||
|
'july',
|
||||||
|
'august',
|
||||||
|
'september',
|
||||||
|
'october',
|
||||||
|
'november',
|
||||||
|
'december',
|
||||||
|
'monday',
|
||||||
|
'tuesday',
|
||||||
|
'wednesday',
|
||||||
|
'thursday',
|
||||||
|
'friday',
|
||||||
|
'saturday',
|
||||||
|
'sunday'
|
||||||
|
);
|
||||||
|
|
||||||
|
$dateFormat = 'l j F Y \à H:i';
|
||||||
|
|
||||||
|
// Convert the date from French to English
|
||||||
|
$date_en = str_replace($search_fr, $replace_en, $date_fr);
|
||||||
|
|
||||||
|
// Parse the date and convert it to an array
|
||||||
|
$date_array = date_parse_from_format($dateFormat, $date_en);
|
||||||
|
|
||||||
|
// Convert the array to a unix timestamp
|
||||||
|
$timestamp = mktime(
|
||||||
|
$date_array['hour'],
|
||||||
|
$date_array['minute'],
|
||||||
|
$date_array['second'],
|
||||||
|
$date_array['month'],
|
||||||
|
$date_array['day'],
|
||||||
|
$date_array['year']
|
||||||
|
);
|
||||||
|
|
||||||
|
return $timestamp;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user