Sigh gives up going to HTTPs cant understand this code it only seems to step through 8192 chunk not even reading headers. This said if its dumping this all why does it not play ? Is it missing the headers on each 8192 bytes?
$url = "http://".$server.":".$port."/".$mount;
class MetadataBlock {
private $expected_length, $content;
public $ID3 = array(
"ID3" => array(BinaryFileReader::FIXED, 3),
"Version" => array(BinaryFileReader::FIXED, 2),
"Flag" => array(BinaryFileReader::FIXED, 1),
"SizeTag" => array(BinaryFileReader::FIXED, 4, BinaryFileReader::INT)
);
public $ARTMAP = array(
"TextEncoding" => array(BinaryFileReader::FIXED, 1),
"MimeType" => array(BinaryFileReader::NULL_TERMINATED),
"FileName" => array(BinaryFileReader::NULL_TERMINATED),
"ContentDesc" => array(BinaryFileReader::NULL_TERMINATED),
"BinaryData" => array(BinaryFileReader::EOF_TERMINATED)
);
public $ALLTAGS = array(
"FrameID" => array(BinaryFileReader::FIXED, 4),
"Size" => array(BinaryFileReader::FIXED, 4, BinaryFileReader::INT),
"Flag" => array(BinaryFileReader::FIXED, 2),
"Body" => array(BinaryFileReader::SIZE_OF, "Size"),
);
private $id3v23 = array("TIT2","TALB","TPE1","TRCK","TDRC","TLEN","USLT");
private $id3v22 = array("TT2","TAL","TP1","TRK","TYE","TLE","ULT");
/**
* Creates a new empty MetadataBlock with the given $expected_length.
* The actual content can be added using the write() method.
*/
public function __construct($expected_length) {
$this->content = '';
$this->expected_length = $expected_length;
}
public function expected_length() {
return $this->expected_length;
}
public function write($buffer) {
$this->content .= $buffer;
}
public function content() {
return $this->content;
}
public function length() {
return strlen($this->content);
}
/**
* Determines if the metadata block is complete. A metadata block is completed
* when its content has at least $expected_length bytes of data.
* https://learn.microsoft.com/en-us/windows/win32/wmformat/id3-tag-support
*/
public function is_complete() {
return $this->remaining_length() == 0;
}
public function remaining_length() {
return $this->expected_length - $this->length();
}
public function stream_title() {
if (!$this->is_complete())
throw new \Exception("The Title is not complete yet");
$start = strlen("TIT1"); // title
$end = strpos($this->content, "TIT1", $start);
return substr($this->content, $start, $end-$start);
}public function stream_author() {
if (!$this->is_complete())
throw new \Exception("The Authur is not complete yet");
$start = strlen("TPE2"); //Author
$end = strpos($this->content, "TPE2", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_album() {
if (!$this->is_complete())
throw new \Exception("The Album is not complete yet");
$start = strlen("TALB"); // The structure of the TALB (Album) text frame
$end = strpos($this->content, "TALB", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_genre() {
if (!$this->is_complete())
throw new \Exception("The Genre is not complete yet");
$start = strlen("TCON"); // Genre
$end = strpos($this->content, "TCON", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_comment() {
if (!$this->is_complete())
throw new \Exception("The comment is not complete yet");
$start = strlen("TCOM"); // Comment
$end = strpos($this->content, "TCOM", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_year() {
if (!$this->is_complete())
throw new \Exception("The comment is not complete yet");
$start = strlen("TYER"); // Year
$end = strpos($this->content, "TYER", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_duration() {
if (!$this->is_complete())
throw new \Exception("The duration is not complete yet");
$start = strlen("TLEN"); // Duration
$end = strpos($this->content, "TLEN", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_bpm() {
if (!$this->is_complete())
throw new \Exception("The bpm is not complete yet");
$start = strlen("TBPM"); // Beats per Minute.
$end = strpos($this->content, "TBPM", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_listeners() {
if (!$this->is_complete())
throw new \Exception("The listeners is not complete yet");
$start = strlen("LISTENERS=");
$end = strpos($this->content, ";", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_song_cover() {
$start = strlen("APIC");
$end = strpos($this->content, "APIC", $start);
return substr($this->content, $start, $end-$start);
}
public function stream_lyrics() {
$start = strlen("USLT");
$end = strpos($this->content, ";", $start);
return substr($this->content, $start, $end-$start);
}
}
// Begin SHOUTcast Principle control
class stream {
private $metadata, $next_metadata_position, $icy_metaint, $mp3, $stream_bytes_count = 0;
private $length,$duration,$tag;
private $expected_length, $content;
private $options, $default_options = array(
'path' => '.',
'split_tracks' => false,
'max_track_duration' => 3600, #sec (1 h)
'max_track_length' => 102400000 #bytes (100 mb)
);
public $title;
public function __construct($options=array()) {
$this->options = array_merge($this->default_options, $options);
}
public function start($url) {
$http_streaming = new HttpStreaming($url);
$http_streaming->open();
$response_message = $http_streaming->response_message();
var_dump($response_message);
$this->icy_metaint = $response_message->icy_metaint();
$this->next_metadata_position = $this->icy_metaint; //8192 value lenghth of frames
while ($buffer = $http_streaming->read_stream()) {
$this->length += strlen($buffer);
if (!$this->process_received_buffer($buffer) || $this->are_limits_reached()) break;
}
}
private function are_limits_reached(){
//return false;
return $this->length >= $this->options['max_track_duration'];
}
private function process_received_buffer($buffer) {
$buffer_len = strlen($buffer);
$this->stream_bytes_count += $buffer_len;
var_dump( $buffer);
return TRUE;
}
}
?>