better id fetching

This commit is contained in:
2026-06-11 20:07:27 +03:00
parent 799d8efabc
commit a7e514e135
4 changed files with 177 additions and 152 deletions
+9 -152
View File
@@ -1,155 +1,12 @@
<?php
// Shoutcast
function getIDshout($radioip,$radioport,$postfix = "GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n") {
$open = fsockopen($radioip,$radioport,$errno,$errstr,'.5');
if ($open) {
fputs($open,$postfix);
stream_set_timeout($open,'1');
$read = fread($open,255);
$exploded = explode(",",$read);
if ($exploded[6] == '' || $exploded[6] == '</body></html>') {
$text = 'streaming'; } else { $text = $exploded[6]; }
$id = str_replace("</body></html>","",$text);
$id = str_replace(" (minimalmix.com)","",$text);
} else { return false; }
fclose($open);
return $id;
$id_time = fopen("id_time.txt", "r") or die("Unable to open file");
$lasttime = fread($id_time, filesize("id_time.txt"));
fclose($id_time);
if ((time() - $lasttime) > 55)
include('id_fetch.php');
else {
$id_tags = fopen("id_tags.txt", "r") or die("Unable to open file");
echo fread($id_tags, filesize("id_tags.txt"));
fclose($id_tags);
}
// Icecast
// https://stackoverflow.com/a/17109654
function getIDice($streamingUrl, $interval, $offset = 0, $headers = true) {
$needle = 'StreamTitle=';
$ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
$opts = [
'http' => [
'method' => 'GET',
'header' => 'Icy-MetaData: 1',
'user_agent' => $ua
]
];
if (($headers = get_headers($streamingUrl)))
foreach ($headers as $h)
if (strpos(strtolower($h), 'icy-metaint') !== false && ($interval = explode(':', $h)[1]))
break;
$context = stream_context_create($opts);
if ($stream = fopen($streamingUrl, 'r', false, $context)) {
$buffer = stream_get_contents($stream, $interval, $offset);
fclose($stream);
if (strpos($buffer, $needle) !== false) {
$title = explode($needle, $buffer)[1];
return substr($title, 1, strpos($title, ';') - 2);
} else
return getMp3StreamTitle($streamingUrl, $interval, $offset + $interval, false);
} else
throw new Exception("Unable to open stream [{$streamingUrl}]");
}
// Anima Amoris
function getIDanima($amoris) {
$url = "http://amoris.sknt.ru/".$amoris."/stats.json";
$headers = array('User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
curl_close($ch);
// metadata.dubtechno({"uniquelisteners":19,"songtitle":"Gblanco - Inner Elusions * amoris.sknt.ru"});
$datajson = json_decode($data, true);
if (!empty($datajson)) $data = $data["songtitle"];
$data = strstr($data, 'songtitle":"');
$data = substr($data, 12);
if (substr($data, -11) == 'sknt.ru"});') $data = stristr($data, ' * amoris.sknt.ru"});', true);
return $data;
}
// first
echo "id:;:";
try {
echo getIDanima("dubtechno"); // Anima Amoris [DubTech]
} catch (Exception $exfirst) {
echo "unavailable";
}
// second
echo ":;:";
try {
echo getIDanima("dubtechnomix"); // Anima Amoris [DubTech Mix]
} catch (Exception $exsecond) {
echo "unavailable";
}
// third
echo ":;:";
try {
echo getIDshout("79.120.39.202","9009"); // Radio Caprice - Dub Techno
} catch (Exception $exthird) {
echo "unavailable";
}
// fourth
echo ":;:";
try {
echo getIDice("https://listen5.myradio24.com/ddtradio", 19200); // Deep Dub Tech radio
} catch (Exception $exfourth) {
echo "unavailable";
}
// fifth
echo ":;:";
try {
$fifthIDice = getIDice("http://94.130.113.214:8000/dubtechno", 19200); // Schizoid Dub Techno
if (bin2hex($fifthIDice) == "fffe66202d20fffe52" || "fffe53202d20fffe53" ) echo "online streaming";
else echo $fifthIDice;
// else echo (bin2hex($fifthIDice));
} catch (Exception $exfifth) {
echo "unavailable";
}
// sixth
echo ":;:";
try {
echo getIDice("http://78.47.31.164:8002/dub", 19200); // MABU Beatz Dub Techno
} catch (Exception $exsixth) {
echo "unavailable";
}
// seventh
echo ":;:";
try {
echo getIDice("http://195.133.48.93:8000/MixCult_96kbps", 19200); // MixCult Deep Techno Radio
} catch (Exception $exseventh) {
echo "unavailable";
}
// eighth
echo ":;:";
try {
echo getIDanima("minimal"); // Anima Amoris [MinimalDeepTech]
} catch (Exception $exeighth) {
echo "unavailable";
}
// ninth
echo ":;:";
try {
echo getIDanima("deeptech"); // Anima Amoris [Deep Tech House]
} catch (Exception $extenth) {
echo "unavailable";
}
// tenth
echo ":;:";
try {
echo getIDice("https://best-of-techno.stream.laut.fm/best-of-techno", 19200); // Best of techno
} catch (Exception $extenth) {
echo "unavailable";
}
// eleventh
echo ":;:";
try {
echo getIDshout("148.251.43.231","8750"); // Minimal Mix Radio
} catch (Exception $exseventh) {
echo "unavailable";
}
// twelfth
echo ":;:";
//try {
// echo getIDice("http://prem2.di.fm:80/dubtechno_hi?266a3dc03aaa30a0807d9062", 19200); // Digitally Imported Dub Techno
//} catch (Exception $exninth) {
echo "unavailable (commercial)";
//}
echo ":;:";
?>
+168
View File
@@ -0,0 +1,168 @@
<?php
// Shoutcast
function getIDshout($radioip,$radioport,$postfix = "GET /7.html HTTP/1.1\nUser-Agent:Mozilla\n\n") {
$open = fsockopen($radioip,$radioport,$errno,$errstr,'.5');
if ($open) {
fputs($open,$postfix);
stream_set_timeout($open,'1');
$read = fread($open,255);
$exploded = explode(",",$read);
if ($exploded[6] == '' || $exploded[6] == '</body></html>') {
$text = 'streaming'; } else { $text = $exploded[6]; }
$id = str_replace("</body></html>","",$text);
$id = str_replace(" (minimalmix.com)","",$id);
} else { return false; }
fclose($open);
return $id;
}
// Icecast
// https://stackoverflow.com/a/17109654
function getIDice($streamingUrl, $interval, $offset = 0, $headers = true) {
$needle = 'StreamTitle=';
$ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
$opts = [
'http' => [
'method' => 'GET',
'header' => 'Icy-MetaData: 1',
'user_agent' => $ua,
'timeout' => 3
]
];
if (($headers = get_headers($streamingUrl)))
foreach ($headers as $h)
if (strpos(strtolower($h), 'icy-metaint') !== false && ($interval = explode(':', $h)[1]))
break;
$context = stream_context_create($opts);
if ($stream = fopen($streamingUrl, 'r', false, $context)) {
$buffer = stream_get_contents($stream, $interval, $offset);
fclose($stream);
if (strpos($buffer, $needle) !== false) {
$title = explode($needle, $buffer)[1];
return substr($title, 1, strpos($title, ';') - 2);
} else
return getMp3StreamTitle($streamingUrl, $interval, $offset + $interval, false);
} else
throw new Exception("Unable to open stream [{$streamingUrl}]");
}
// Anima Amoris
function getIDanima($amoris) {
$url = "http://amoris.sknt.ru/".$amoris."/stats.json";
$headers = array('User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
$data = curl_exec($ch);
if (curl_errno($ch)) {
curl_close($ch);
return "unavailable";
}
curl_close($ch);
$datajson = json_decode($data, true);
if (!empty($datajson)) $data = $data["songtitle"];
$data = strstr($data, 'songtitle":"');
$data = substr($data, 12);
if (substr($data, -11) == 'sknt.ru"});') $data = stristr($data, ' * amoris.sknt.ru"});', true);
return $data;
}
// first
$tags = "id:;:";
try {
$tags .= getIDanima("dubtechno"); // Anima Amoris [DubTech]
} catch (Exception $exfirst) {
$tags .= "unavailable";
}
// second
$tags .= ":;:";
try {
$tags .= getIDanima("dubtechnomix"); // Anima Amoris [DubTech Mix]
} catch (Exception $exsecond) {
$tags .= "unavailable";
}
// third
$tags .= ":;:";
try {
$tags .= getIDshout("79.120.39.202","9009"); // Radio Caprice - Dub Techno
} catch (Exception $exthird) {
$tags .= "unavailable";
}
// fourth
$tags .= ":;:";
try {
$tags .= getIDice("https://listen5.myradio24.com/ddtradio", 19200); // Deep Dub Tech radio
} catch (Exception $exfourth) {
$tags .= "unavailable";
}
// fifth
$tags .= ":;:";
try {
$fifthIDice = getIDice("http://94.130.113.214:8000/dubtechno", 19200); // Schizoid Dub Techno
if (bin2hex($fifthIDice) == "fffe66202d20fffe52" || "fffe53202d20fffe53" ) $tags .= "online streaming";
else $tags .= $fifthIDice;
} catch (Exception $exfifth) {
$tags .= "unavailable";
}
// sixth
$tags .= ":;:";
try {
$tags .= getIDice("http://78.47.31.164:8002/dub", 19200); // MABU Beatz Dub Techno
} catch (Exception $exsixth) {
$tags .= "unavailable";
}
// seventh
$tags .= ":;:";
try {
$tags .= getIDice("http://195.133.48.93:8000/MixCult_96kbps", 19200); // MixCult Deep Techno Radio
} catch (Exception $exseventh) {
$tags .= "unavailable";
}
// eighth
$tags .= ":;:";
try {
$tags .= getIDanima("minimal"); // Anima Amoris [MinimalDeepTech]
} catch (Exception $exeighth) {
$tags .= "unavailable";
}
// ninth
$tags .= ":;:";
try {
$tags .= getIDanima("deeptech"); // Anima Amoris [Deep Tech House]
} catch (Exception $extenth) {
$tags .= "unavailable";
}
// tenth
$tags .= ":;:";
try {
$tags .= getIDice("https://best-of-techno.stream.laut.fm/best-of-techno", 19200); // Best of techno
} catch (Exception $extenth) {
$tags .= "unavailable";
}
// eleventh
$tags .= ":;:";
try {
$tags .= getIDshout("148.251.43.231","8750"); // Minimal Mix Radio
} catch (Exception $exseventh) {
$tags .= "unavailable";
}
// twelfth
$tags .= ":;:";
//try {
// $tags .= getIDice("http://prem2.di.fm:80/dubtechno_hi?266a3dc03aaa30a0807d9062", 19200); // Digitally Imported Dub Techno
//} catch (Exception $exninth) {
$tags .= "unavailable (commercial)";
//}
$tags .= ":;:";
$id_tags = fopen("id_tags.txt", "w") or die("Unable to open file");
fwrite($id_tags, $tags);
fclose($id_tags);
$curtime = time();
$id_time = fopen("id_time.txt", "w") or die("Unable to open file");
fwrite($id_time, $curtime);
fclose($id_time);
echo $tags;
?>
View File
View File