2010-12-21, 09:51
vinc Wrote:http://www.youtube.com/watch?v=2oBfC8Lqumo
Looks SWEET!!!
iapiap Wrote:@Blieb, I would also like to take a look at your code if possible, please Thanks!
<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$sendok = "HTTP/1.1 200 OK\nContent-Length: 0\n\n";
$address = '192.168.0.60';
$port = 22555;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
if (socket_listen($sock, 5) === false) {
echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
do {
if (($msgsock = socket_accept($sock)) === false) {
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
break;
}
/* Send instructions. */
do {
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
break;
}
if (!$buf = trim($buf)) {
continue;
}
echo "'$buf'\n";
$expl = explode(" ", $buf);
if ($expl[0] == "POST") { $cmd = $expl[1]; $method = $expl[0]; }
if ($expl[0] == "PUT") { $cmd = $expl[1]; $method = $expl[0]; }
if ($expl[0] == "GET") { $cmd = $expl[1]; $method = $expl[0]; }
if ($expl[0] == "Content-Location:") { $url = $expl[1]; }
if ($expl[0] == "Content-Length:") { $contentlength = $expl[1]; }
if ($expl[0] == "Start-Position:") {
$postition = $expl[1];
echo "- Ik moet $url spelen!";
startvideo($url);
socket_write($msgsock, $sendok);
}
if ($expl[0] =="User-Agent:") {
echo substr($cmd, 0,6);
if ($cmd == "/photo") {
$photo = "";
while (strlen($photo) < $contentlength) {
$photo .= socket_read($msgsock, $contentlength);
echo " -foto ontvangen" . strlen($photo) . " of " . $contentlength . "\n";
}
$File = "/var/www/test.jpg";
$Handle = fopen($File, 'w');
fwrite($Handle, trim($photo));
fclose($Handle);
$cmd = "";
startpic("http://192.168.0.60/test.jpg");
socket_write($msgsock, $sendok);
}
if (substr($cmd, 0,6) == "/scrub") {
socket_write($msgsock, $sendok);
echo "- send scrub reply\n";
}
if (substr($cmd, 0,5) == "/rate") {
$body = "duration: 2:23\nposition: 31:11\n";
$length = strlen($reply);
$reply = "HTTP/1.1 200 OK\nContent-Length: $length\n\n";
socket_write($msgsock, $reply . "\n\n" . $body . "\n\n");
echo "- send rate reply\n";
}
if ($cmd == "/reverse") {
{
$reply = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: PTTH/1.0\r\nConnection: Upgrade\r\n\r\n\r\n";
socket_write($msgsock, $reply);
echo "- Sending switchting protocols\n";
$cmd = "";
}
break;
}
}
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
function startvideo($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" . $url . "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
function startpic($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" . $url . "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
?>
<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_airplay._tcp</type>
<port>22555</port>
</service>
</service-group>
Blieb Wrote:Sure, but is it very buggy, I think this is not a good language voor making airplay in it.
avahi service file:PHP Code:<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$sendok = "HTTP/1.1 200 OK\nContent-Length: 0\n\n";
$address = '192.168.0.60';
$port = 22555;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
}
if (socket_bind($sock, $address, $port) === false) {
echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
if (socket_listen($sock, 5) === false) {
echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
}
do {
if (($msgsock = socket_accept($sock)) === false) {
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";
break;
}
/* Send instructions. */
do {
if (false === ($buf = socket_read($msgsock, 2048, PHP_NORMAL_READ))) {
echo "socket_read() failed: reason: " . socket_strerror(socket_last_error($msgsock)) . "\n";
break;
}
if (!$buf = trim($buf)) {
continue;
}
echo "'$buf'\n";
$expl = explode(" ", $buf);
if ($expl[0] == "POST") { $cmd = $expl[1]; $method = $expl[0]; }
if ($expl[0] == "PUT") { $cmd = $expl[1]; $method = $expl[0]; }
if ($expl[0] == "GET") { $cmd = $expl[1]; $method = $expl[0]; }
if ($expl[0] == "Content-Location:") { $url = $expl[1]; }
if ($expl[0] == "Content-Length:") { $contentlength = $expl[1]; }
if ($expl[0] == "Start-Position:") {
$postition = $expl[1];
echo "- Ik moet $url spelen!";
startvideo($url);
socket_write($msgsock, $sendok);
}
if ($expl[0] =="User-Agent:") {
echo substr($cmd, 0,6);
if ($cmd == "/photo") {
$photo = "";
while (strlen($photo) < $contentlength) {
$photo .= socket_read($msgsock, $contentlength);
echo " -foto ontvangen" . strlen($photo) . " of " . $contentlength . "\n";
}
$File = "/var/www/test.jpg";
$Handle = fopen($File, 'w');
fwrite($Handle, trim($photo));
fclose($Handle);
$cmd = "";
startpic("http://192.168.0.60/test.jpg");
socket_write($msgsock, $sendok);
}
if (substr($cmd, 0,6) == "/scrub") {
socket_write($msgsock, $sendok);
echo "- send scrub reply\n";
}
if (substr($cmd, 0,5) == "/rate") {
$body = "duration: 2:23\nposition: 31:11\n";
$length = strlen($reply);
$reply = "HTTP/1.1 200 OK\nContent-Length: $length\n\n";
socket_write($msgsock, $reply . "\n\n" . $body . "\n\n");
echo "- send rate reply\n";
}
if ($cmd == "/reverse") {
{
$reply = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: PTTH/1.0\r\nConnection: Upgrade\r\n\r\n\r\n";
socket_write($msgsock, $reply);
echo "- Sending switchting protocols\n";
$cmd = "";
}
break;
}
}
} while (true);
socket_close($msgsock);
} while (true);
socket_close($sock);
function startvideo($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" . $url . "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
function startpic($url) {
system("curl -i -X POST -d '{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\":{ \"file\" : \"" . $url . "\" }, \"id\": 1}' http://192.168.0.63:8080/jsonrpc");
}
?>
Code:<service-group>
<name replace-wildcards="yes">%h</name>
<service>
<type>_airplay._tcp</type>
<port>22555</port>
</service>
</service-group>
I was running the script on a other computer than xbmc is running. when used for photo's it saves photo to /var/www/test.jpg but I dit not know how to show it in xbmc.
I know it is crapy code. but it was just for testing. It should be written in a real language
logictester Wrote:could you please share some instructions? thanks a lot
Quote:Installation
This hack was developed on Ubuntu (but should also work on other linux systems). Therefore installation istruction will be for linux only (Ubuntu). It should be possible to port the code to other platform since it's only python. However I have no ideas about the dependencies (avahi for example).
apt-get install avahi-daemon
apt-get install python-twisted
apt-get install xbmc-eventclients-xbmc-send
copy the play2wifi.service script to /etc/avahi/services/.
restart avahi: "sudo service avahi-daemon restart"
pico play2wifi.cfg and edit the port number (default is 8080)
launch the script python play2wifi.py somewhere.
launch a video/podcast on the iThing and switch it over to xbmc.
joeblack2k Wrote:Yeah got the .py code running
edited the readme, how i got it to work..
Blieb is jou code php ? hoe start ik dat ?