[RadioMelodieBridge] Replace JS Audio Player (#2233)

The Javascript Audio Player is replaced by the plain <audio> HTML tag
This commit is contained in:
sysadminstory 2021-08-04 06:04:45 +02:00 committed by GitHub
parent 3637777070
commit f5f0b77805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 30 additions and 0 deletions

View File

@ -23,6 +23,9 @@ class RadioMelodieBridge extends BridgeAbstract {
if($element->tag == 'a') {
$articleURL = self::URI . $element->href;
$article = getSimpleHTMLDOM($articleURL);
$this->rewriteAudioPlayers($article);
// Reload the modified content
$article = str_get_html($article->save());
$textDOM = $article->find('article', 0);
// Initialise arrays
@ -96,6 +99,7 @@ class RadioMelodieBridge extends BridgeAbstract {
$textDOM = defaultLinkTo($textDOM, self::URI . '/');
$article->save();
//$this->rewriteAudioPlayers($textDOM);
$text = $textDOM->innertext;
$item['content'] = '<h1>' . $item['title'] . '</h1>' . $dateHTML . '<br/>' . $header . $text;
$this->items[] = $item;
@ -113,4 +117,30 @@ class RadioMelodieBridge extends BridgeAbstract {
return self::URI . '/' . $params['image'];
}
/*
* 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 = '';
}
}
}