2018-03-11 17:38:07 +03:00
|
|
|
<?php
|
|
|
|
class RadioMelodieBridge extends BridgeAbstract {
|
|
|
|
const NAME = 'Radio Melodie Actu';
|
2019-04-20 23:19:22 +03:00
|
|
|
const URI = 'https://www.radiomelodie.com';
|
2018-03-11 17:38:07 +03:00
|
|
|
const DESCRIPTION = 'Retourne les actualités publiées par Radio Melodie';
|
|
|
|
const MAINTAINER = 'sysadminstory';
|
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon() {
|
2019-04-20 23:19:22 +03:00
|
|
|
return self::URI . '/img/favicon.png';
|
2018-10-26 19:07:34 +03:00
|
|
|
}
|
|
|
|
|
2018-03-11 17:38:07 +03:00
|
|
|
public function collectData(){
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM(self::URI . '/actu/');
|
2021-12-18 13:19:58 +03:00
|
|
|
$list = $html->find('div[class=listArticles]', 0)->children();
|
2021-06-25 23:12:33 +03:00
|
|
|
|
2018-03-11 17:38:07 +03:00
|
|
|
foreach($list as $element) {
|
2019-04-20 23:19:22 +03:00
|
|
|
if($element->tag == 'a') {
|
|
|
|
$articleURL = self::URI . $element->href;
|
|
|
|
$article = getSimpleHTMLDOM($articleURL);
|
2021-08-04 07:04:45 +03:00
|
|
|
$this->rewriteAudioPlayers($article);
|
|
|
|
// Reload the modified content
|
|
|
|
$article = str_get_html($article->save());
|
2019-06-01 13:12:17 +03:00
|
|
|
$textDOM = $article->find('article', 0);
|
2019-04-20 23:19:22 +03:00
|
|
|
|
|
|
|
// Initialise arrays
|
|
|
|
$item = array();
|
|
|
|
$audio = array();
|
|
|
|
$picture = array();
|
|
|
|
|
|
|
|
// Get the Main picture URL
|
2021-12-18 13:19:58 +03:00
|
|
|
$picture[] = self::URI . $article->find('figure[class=photoviewer]', 0)->find('img', 0)->src;
|
2019-06-01 13:12:17 +03:00
|
|
|
$audioHTML = $article->find('audio');
|
2019-04-20 23:19:22 +03:00
|
|
|
|
2019-06-01 13:12:17 +03:00
|
|
|
// Add the audio element to the enclosure
|
2019-04-20 23:19:22 +03:00
|
|
|
foreach($audioHTML as $audioElement) {
|
2019-06-01 13:12:17 +03:00
|
|
|
$audioURL = $audioElement->src;
|
2019-04-20 23:19:22 +03:00
|
|
|
$audio[] = $audioURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rewrite pictures URL
|
2019-06-01 13:12:17 +03:00
|
|
|
$imgs = $textDOM->find('img[src^="http://www.radiomelodie.com/image.php]');
|
2019-04-20 23:19:22 +03:00
|
|
|
foreach($imgs as $img) {
|
|
|
|
$img->src = $this->rewriteImage($img->src);
|
2019-06-02 14:03:26 +03:00
|
|
|
$article->save();
|
2019-04-20 23:19:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove Google Ads
|
2019-06-01 13:12:17 +03:00
|
|
|
$ads = $article->find('div[class=adInline]');
|
2019-04-20 23:19:22 +03:00
|
|
|
foreach($ads as $ad) {
|
2019-06-02 14:03:26 +03:00
|
|
|
$ad->outertext = '';
|
|
|
|
$article->save();
|
2019-04-20 23:19:22 +03:00
|
|
|
}
|
|
|
|
|
2021-12-18 13:19:58 +03:00
|
|
|
// Extract the author
|
|
|
|
$author = $article->find('div[class=author]', 0)->children(1)->children(0)->plaintext;
|
2019-04-20 23:19:22 +03:00
|
|
|
|
2021-06-25 23:12:33 +03:00
|
|
|
// Handle date to timestamp
|
2021-12-18 13:19:58 +03:00
|
|
|
$dateHTML = $article->find('div[class=author]', 0)->children(1)->plaintext;
|
2022-05-08 05:19:06 +03:00
|
|
|
|
|
|
|
preg_match('/([a-z]{4,10}[ ]{1,2}[0-9]{1,2} [\p{L}]{3,10} [0-9]{4} à [0-9]{2}:[0-9]{2})/mus', $dateHTML, $matches);
|
2021-06-25 23:12:33 +03:00
|
|
|
$dateText = $matches[1];
|
2022-05-08 05:19:06 +03:00
|
|
|
|
2021-12-18 13:19:58 +03:00
|
|
|
$timestamp = $this->parseDate($dateText);
|
2021-06-25 23:12:33 +03:00
|
|
|
|
2019-04-20 23:19:22 +03:00
|
|
|
$item['enclosures'] = array_merge($picture, $audio);
|
|
|
|
$item['author'] = $author;
|
|
|
|
$item['uri'] = $articleURL;
|
|
|
|
$item['title'] = $article->find('meta[property=og:title]', 0)->content;
|
2021-06-25 23:12:33 +03:00
|
|
|
if($timestamp !== false) {
|
|
|
|
$item['timestamp'] = $timestamp;
|
|
|
|
}
|
2019-06-01 13:12:17 +03:00
|
|
|
|
2021-12-18 13:19:58 +03:00
|
|
|
// Remove the share article part
|
|
|
|
$textDOM->find('div[class=share]', 0)->outertext = '';
|
2021-06-25 23:12:33 +03:00
|
|
|
|
|
|
|
// Rewrite relative Links
|
|
|
|
$textDOM = defaultLinkTo($textDOM, self::URI . '/');
|
|
|
|
|
2019-06-02 14:03:26 +03:00
|
|
|
$article->save();
|
2019-04-20 23:19:22 +03:00
|
|
|
$text = $textDOM->innertext;
|
2021-12-18 13:19:58 +03:00
|
|
|
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $dateText . '<br/>' . $text;
|
2019-04-20 23:19:22 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
2018-03-11 17:38:07 +03:00
|
|
|
}
|
|
|
|
}
|
2019-04-20 23:19:22 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to rewrite image URL to use the real Image URL and not the resized one (which is very slow)
|
|
|
|
*/
|
|
|
|
private function rewriteImage($url)
|
|
|
|
{
|
|
|
|
$parts = explode('?', $url);
|
2019-06-01 13:12:17 +03:00
|
|
|
parse_str(html_entity_decode($parts[1]), $params);
|
2019-04-20 23:19:22 +03:00
|
|
|
return self::URI . '/' . $params['image'];
|
|
|
|
|
|
|
|
}
|
2021-08-04 07:04:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to rewrite Audio Players to use the <audio> tag and not the javascript audio player
|
|
|
|
*/
|
|
|
|
private function rewriteAudioPlayers($html)
|
|
|
|
{
|
|
|
|
// Find all audio Players
|
|
|
|
$audioPlayers = $html->find('div[class=audioPlayer]');
|
|
|
|
|
|
|
|
foreach($audioPlayers as $audioPlayer) {
|
|
|
|
// Get the javascript content below the player
|
|
|
|
$js = $audioPlayer->next_sibling();
|
|
|
|
|
|
|
|
// Extract the audio file URL
|
|
|
|
preg_match('/wavesurfer[0-9]+.load\(\'(.*)\'\)/m', $js->innertext, $urls);
|
|
|
|
|
|
|
|
// Create the plain HTML <audio> content to play this audio file
|
|
|
|
$content = '<audio style="width: 100%" src="' . $urls[1] . '" controls ></audio>';
|
|
|
|
|
|
|
|
// Replace the <script> tag by the <audio> tag
|
|
|
|
$js->outertext = $content;
|
|
|
|
// Remove the initial Audio Player
|
|
|
|
$audioPlayer->outertext = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-12-18 13:19:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
}
|
2018-03-11 17:38:07 +03:00
|
|
|
}
|