Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- set_time_limit(0);
- //error_reporting(0);
- function get_title($soundcloud_link, $data) {
- $doc=new DOMDocument();
- $doc->loadHTML($data);
- $xml=simplexml_import_dom($doc);
- $title=$xml->xpath('//em');
- return $title[0];
- }
- function get_id($soundcloud_link, $data) {
- $doc=new DOMDocument();
- $doc->loadHTML($data);
- $xml=simplexml_import_dom($doc);
- $images=$xml->xpath('//img');
- foreach ($images as $img) {
- if ($img['class'] == "waveform") {
- $final_id = $img['src'];
- break;
- }
- }
- $final_id = end(explode('/', $final_id));
- $final_id = current(explode('_', $final_id));
- return "http://media.soundcloud.com/stream/" . $final_id;
- }
- function savefile($id, $title) {
- $dir = "files";
- $file = file_get_contents($id);
- $thetitle = "";
- $titlelen = strlen($title) - 2;
- $thetitle = substr($title, 1, $titlelen);
- $thetitle = str_replace(" ", "_", $thetitle);
- $filename = $dir . "/" . $thetitle . ".mp3";
- file_put_contents("$filename", $file);
- header('Pragma: public');
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Cache-Control: public');
- header('Content-type: application/force-download');
- header('Content-Disposition: attachment; filename='.basename($filename).";" );
- header("Content-Transfer-Encoding: binary");
- header('Content-Length: '.filesize("$filename"));
- readfile("$filename");
- }
- if ( $_POST ) {
- $soundcloud_link = $_POST['l'];
- $data = file_get_contents($soundcloud_link);
- $id = get_id($soundcloud_link,$data);
- $title = get_title($soundcloud_link,$data);
- savefile($id, $title);
- } else {
- print <<<SOUND_FORM
- <form method="post" ">
- <label for="name">Soundcloud Link: </label><br />
- <input name="l" id="l" type="text" maxlength="150" /><br>
- <input type="submit" value="Submit" />
- </form>
- SOUND_FORM;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment