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

[RadioMelodieBridge] Bridge fixed after website update #1145

Merged
merged 3 commits into from
Jun 1, 2019
Merged
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
47 changes: 23 additions & 24 deletions bridges/RadioMelodieBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,63 @@ public function getIcon() {
public function collectData(){
$html = getSimpleHTMLDOM(self::URI . '/actu/')
or returnServerError('Could not request Radio Melodie.');
$list = $html->find('div[class=actu_col1]', 0)->children();;
$list = $html->find('div[class=displayList]', 0)->children();
foreach($list as $element) {
if($element->tag == 'a') {
$articleURL = self::URI . $element->href;
$article = getSimpleHTMLDOM($articleURL);
$textDOM = $article->find('article', 0);

// Initialise arrays
$item = array();
$audio = array();
$picture = array();

// Get the Main picture URL
$picture[] = $this->rewriteImage($article->find('img[id=picturearticle]', 0)->src);
$audioHTML = $article->find('div[class=sm2-playlist-wrapper]');
$picture[] = $this->rewriteImage($article->find('div[id=pictureTitleSupport]', 0)->find('img', 0)->src);
$audioHTML = $article->find('audio');

// Remove the audio placeholder under the Audio player with an <audio>
// element and add the audio element to the enclosure
// Add the audio element to the enclosure
foreach($audioHTML as $audioElement) {
$audioURL = $audioElement->find('a', 0)->href;
$audioURL = $audioElement->src;
$audio[] = $audioURL;
$audioElement->outertext = '<audio controls src="' . $audioURL . '"></audio>';
$article->save();
}

// Rewrite pictures URL
$imgs = $article->find('img[src^="https://www.radiomelodie.com/image.php]');
$imgs = $textDOM->find('img[src^="http://www.radiomelodie.com/image.php]');
foreach($imgs as $img) {
$img->src = $this->rewriteImage($img->src);
$article->save();
}

// Remove inline audio player HTML
$inlinePlayers = $article->find('div[class*=sm2-main-controls]');
foreach($inlinePlayers as $inlinePlayer) {
$inlinePlayer->outertext = '';
$article->save();
}

// Remove Google Ads
$ads = $article->find('div[style^=margin:25px 0; position:relative; height:auto;]');
$ads = $article->find('div[class=adInline]');
foreach($ads as $ad) {
$ad->outertext = '';
$article->save();
}

$author = $article->find('div[id=author]', 0)->find('span', 0)->plaintext;
// Remove Radio Melodie Logo
$logoHTML = $article->find('div[id=logoArticleRM]', 0);
$logoHTML->outertext = '';
$article->save();

$author = $article->find('p[class=AuthorName]', 0)->plaintext;

$item['enclosures'] = array_merge($picture, $audio);
$item['author'] = $author;
$item['uri'] = $articleURL;
$item['title'] = $article->find('meta[property=og:title]', 0)->content;
$date_category = $article->find('div[class*=date]', 0)->plaintext;
$header = $article->find('a[class=fancybox]', 0)->innertext;
$textDOM = $article->find('div[class=text_content]', 0);
$textDOM->find('div[id=author]', 0)->outertext = '';
$date = $article->find('p[class*=date]', 0)->plaintext;

// Header Image
$header = '<img src="' . $picture[0] . '"/>';

// Remove the Date and Author part
$textDOM->find('div[class=AuthorDate]', 0)->outertext = '';
$article->save();
$text = $textDOM->innertext;
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $date_category . $header . $text;
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $date . '<br/>' . $header . $text;
$this->items[] = $item;
}
}
Expand All @@ -81,7 +80,7 @@ public function collectData(){
private function rewriteImage($url)
{
$parts = explode('?', $url);
parse_str($parts[1], $params);
parse_str(html_entity_decode($parts[1]), $params);
return self::URI . '/' . $params['image'];

}
Expand Down