Created
September 18, 2019 19:20
-
-
Save BlackScorp/db78a43c968ddbbd73864c63861c675c to your computer and use it in GitHub Desktop.
Code for the Youtube Tutorial https://youtu.be/1kRy0JgPC04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(-1); | |
ini_set('display_errors', 'On'); | |
$url = 'https://www.green-secure.de/podcast/'; | |
$domDocument = new DOMDocument(); | |
@$domDocument->loadHTMLFile($url); | |
$xpath = new DOMXPath($domDocument); | |
$elements = $xpath->query('//div[@class="elementor-shortcode"]/script'); | |
if($elements->length === 0){ | |
echo "Keine Elemente zum Selector gefunden"; | |
return; | |
} | |
$context = stream_context_create([ | |
'http'=>[ | |
'header'=>['Accept: application/json'] | |
] | |
]); | |
foreach($elements as $element){ | |
$source = $element->getAttribute('data-configuration'); | |
if(!$source){ | |
echo "Attribut data-configuration wurde nicht gefunden"; | |
continue; | |
} | |
$json = file_get_contents($source,false,$context); | |
$data = json_decode($json); | |
$fileName = str_replace(['?', '"', '/', '*', '|', ':', '<', '>'], '-', $data->episode->title).'.mp3'; | |
$mp3Source = $data->episode->media->mp3; | |
file_put_contents($fileName, fopen($mp3Source,'r')); | |
echo sprintf("Neueste Podcast Episode mit dem Titel '%s' wurde heruntergeladen", $fileName); | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment