------------------------------
My current project:
Currently I'm writing a PHP interface to the DAAP protocol, which is the protocol that Apple's iTunes uses to share and stream playlists
I'm not a Mac person at all, but it seemed like an interesting challenge. The DAAP protocol is built atop HTTP, so interfacing with the server is pretty simple, but making sense of the data that iTunes returns is quite a challenge. Fortunately, a number of people have already done most of the footwork for me (1, 2).
The big challenge has been learning how to deal with binary data in PHP. When you query iTunes, the response is in a binary format (no human-readable XML or anything, here). I just started working on this tonight, about six hours ago, and with the help of the protocol documentation, I've been able to write a function (recursive, no less) that takes the binary data returned by iTunes and turn it into an array in PHP. My eventual goal is to make an OOP interface to the DAAP server., and then use that to build some sort of web-based DAAP-browsing app. We'll see how far I get.
If anybody's really interested in how this project is going, send me a PM (or post below) and I'd be happy to discuss it and show you what I've got, though at this point I don't want to turn it into a team project -- I'm just tinkering now. But I have come up with a couple of functions that might be helpful for other projects.
The first should be easy, but it took me a long time to figure out. It's a function to take a binary string (not a string of 1s and 0s, but an actual string of binary data -- for the former, just use bindec()) and return its integer value:
Code: Select all
<?php
// convert a binary string to an int
function bin2int($bin) {
return hexdec(bin2hex($bin));
}
?>
Code: Select all
<?php
function bin_dump($string, $width = 16, $break = 4, $return_text = 0) {
$line_count = 0;
$section_count = 0;
$hex = '';
$text = '';
for($i = 0; $i < strlen($string); $i++) {
$line_count++;
$section_count++;
$hex .= str_pad(strtoupper(dechex(ord($string{$i}))), 2, '0', STR_PAD_LEFT);
$text .= $string{$i};
if($line_count == $width) {
$hex .= "\n";
$text .= "\n";
$line_count = 0;
$section_count = 0;
} elseif($section_count == $break) {
$hex .= ' ';
$text .= ' ';
$section_count = 0;
} else {
$hex .= ' ';
}
}
if($return_text > 0) {
return $text;
} else {
return $hex;
}
}
?>
Code: Select all
6D 73 72 76 00 00 00 A7 6D 73 74 74 00 00 00 04
00 00 00 C8 6D 70 72 6F 00 00 00 04 00 02 00 00
61 70 72 6F 00 00 00 04 00 02 00 00 6D 69 6E 6D
00 00 00 12 41 67 69 74 61 74 65 64 20 4C 75 6E
63 68 6C 61 64 79 6D 73 6C 72 00 00 00 01 00 6D
73 74 6D 00 00 00 04 00 00 07 08 6D 73 61 6C 00
00 00 01 00 6D 73 75 70 00 00 00 01 00 6D 73 70
69 00 00 00 01 00 6D 73 65 78 00 00 00 01 00 6D
73 62 72 00 00 00 01 00 6D 73 71 79 00 00 00 01
00 6D 73 69 78 00 00 00 01 00 6D 73 72 73 00 00
00 01 00 6D 73 64 63 00 00 00 04 00 00 00 01