Advertisement
DjSxX

fallback.php

Oct 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.01 KB | None | 0 0
  1. <?php
  2. /////////////////////////////////////////////////////
  3. // FALLBACK FOR META DATA
  4. // https://www.flashradio.info
  5. //
  6. // Copyright (C) SODAH | JOERG KRUEGER
  7. // https://www.sodah.de
  8. /////////////////////////////////////////////////////
  9. error_reporting(0);
  10. header('Content-type: text/plain');
  11. header('Pragma: public');
  12. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');                  
  13. header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
  14. header('Cache-Control: no-store, no-cache, must-revalidate');
  15. header('Cache-Control: pre-check=0, post-check=0, max-age=0');
  16. header('Pragma: no-cache');
  17. header('Expires: 0');
  18.  
  19. if (isset($_POST['url']) && isset($_POST['mode'])) {
  20.     if ($_POST['url'] != "") {
  21.         switch ($_POST['mode']) {
  22.             case "fallback":
  23.                 $options = array(
  24.                     'http'=>array(
  25.                     'method'=>"GET",
  26.                     'header'=>"Accept-language: en\r\n" .
  27.                                 "Cookie: foo=bar\r\n" .
  28.                                 "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
  29.                     )
  30.                 );
  31.  
  32.                 $contents = file_get_contents($_POST['url'], false, stream_context_create($options));
  33.                 //$contents = utf8_encode($contents);
  34.                 echo $contents;
  35.                 break;
  36.             case "radioname":
  37.                 echo utf8_encode(htmlentities(html_entity_decode(readRadioName($_POST['url']), ENT_QUOTES | ENT_HTML5,"ISO-8859-1")));
  38.                 break;
  39.             case "songname":
  40.                 echo utf8_encode(htmlentities(html_entity_decode(readSongName($_POST['url']), ENT_QUOTES | ENT_HTML5,"ISO-8859-1")));
  41.                 break;
  42.         }
  43.     }
  44. }
  45.  
  46. function readSongName($sURL){
  47.     $aPathInfo = parse_url($sURL);
  48.     $sHost = $aPathInfo['host'];
  49.     $sPort = empty($aPathInfo['port']) ? 80 : $sPort = $aPathInfo['port'];
  50.     $sPath = empty($aPathInfo['path']) ? '/' : $sPath = $aPathInfo['path'];
  51.     $fp = fsockopen($sHost, $sPort, $errno, $errstr);
  52.     if (!$fp){
  53.         return "";
  54.     } else {
  55.         fputs($fp, "GET $sPath HTTP/1.0\r\n");
  56.         fputs($fp, "Host: $sHost\r\n");
  57.         fputs($fp, "Accept: */*\r\n");
  58.         fputs($fp, "Icy-MetaData:1\r\n");
  59.         fputs($fp, "Connection: close\r\n\r\n");
  60.         $char = "";
  61.         $info = "";
  62.         while ($char != Chr(255)){  //END OF MPEG-HEADER
  63.             if (@feof($fp) || @ftell($fp)>14096){
  64.                 exit;
  65.             }
  66.             $char = @fread($fp,1);
  67.             $info .= $char;
  68.         }
  69.         fclose($fp);
  70.         $info = str_replace("\n", "",$info);
  71.         $info = str_replace("\r", "",$info);
  72.         $info = str_replace("\n\r", "",$info);
  73.         $info = str_replace("<BR>", "",$info);
  74.         $info = str_replace(":", "=",$info);
  75.         $info = str_replace("icy", "&icy",$info);
  76.         $info = strtolower($info);
  77.         parse_str($info, $output);
  78.         if ($output['icy-br']!=""){
  79.             $streambitrate = intval($output['icy-br']);
  80.         }
  81.         if ($output['icy-name']==""){
  82.             return ""; 
  83.         } else {
  84.             return utf8_encode($output['icy-name']);
  85.         }
  86.     }
  87. }
  88.  
  89. function readRadioName($sURL) {
  90.     $aPathInfo = parse_url($sURL);
  91.     $sHost = $aPathInfo['host'];
  92.     $sPort = empty($aPathInfo['port']) ? 80 : $sPort = $aPathInfo['port'];
  93.     $sPath = empty($aPathInfo['path']) ? '/' : $sPath = $aPathInfo['path'];
  94.     $fp = fsockopen($sHost, $sPort, $errno, $errstr);
  95.     if (!$fp):
  96.         return "";
  97.     else:
  98.         fputs($fp, "GET $sPath HTTP/1.0\r\n");
  99.         fputs($fp, "Host: $sHost\r\n");
  100.         fputs($fp, "Accept: */*\r\n");
  101.         fputs($fp, "Icy-MetaData:1\r\n");
  102.         fputs($fp, "Connection: close\r\n\r\n");
  103.         $char = "";
  104.         $info = "";
  105.         while ($char != Chr(255)){
  106.             if (@feof($fp) || @ftell($fp)>14096){
  107.                 exit;
  108.             }
  109.             $char = @fread($fp,1);
  110.             $info .= $char;
  111.         }
  112.         fclose($fp);
  113.         $info = str_replace("\n", "",$info);
  114.         $info = str_replace("\r", "",$info);
  115.         $info = str_replace("\n\r", "",$info);
  116.         $info = str_replace("<BR>", "",$info);
  117.         $info = str_replace(":", "=",$info);
  118.         $info = str_replace("icy", "&icy",$info);
  119.         $info = strtolower($info);
  120.         parse_str($info, $output);
  121.         if ($output['icy-br']!=""){
  122.             $streambitrate = intval($output['icy-br']);
  123.         }
  124.         if ($output['icy-name']==""){
  125.             return ""; 
  126.         } else {
  127.             return $output['icy-name'];
  128.         }
  129.     endif;
  130. }
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement