Volkova

PHP Soundcloud Downloader V0.1

Jun 29th, 2011
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(0);
  4.  
  5. function get_id($soundcloud_link) {
  6.     $data = file_get_contents($soundcloud_link);
  7.  
  8.     $doc=new DOMDocument();
  9.     $doc->loadHTML($data);
  10.     $xml=simplexml_import_dom($doc);
  11.     $images=$xml->xpath('//img');
  12.  
  13.     foreach ($images as $img) {
  14.         if ($img['class'] == "waveform") {
  15.             $final_id = $img['src'];
  16.             break;
  17.         }
  18.     }
  19.  
  20.     $final_id = end(explode('/', $final_id));
  21.     $final_id = current(explode('_', $final_id));
  22.  
  23.     return "http://media.soundcloud.com/stream/" . $final_id;
  24. }
  25.  
  26. if ( $_POST ) {
  27.     $file = get_id($_POST['l']);
  28.     print "<a href=\"$file\"> Right-Click & Save Link as...</a>";
  29. } else {
  30.     print <<<SOUND_FORM
  31. <form action="soundcloud.php" method="post" onsubmit="return valid2ate()">
  32.  
  33.     <label for="name">Soundcloud Link: </label><br />
  34.     <input name="l" id="l" type="text" maxlength="150" value=""/>
  35.  
  36.     <input type="submit" value="Submit" />
  37. </form>
  38. SOUND_FORM;
  39. }
  40.  
  41. ?>
Add Comment
Please, Sign In to add comment