PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/stream/stream.php

https://github.com/jamusj/iphone
PHP | 85 lines | 43 code | 12 blank | 30 comment | 8 complexity | 4b8f730cc182b5f41a0531a0b5301371 MD5 | raw file
  1. <?php
  2. /*
  3. Copyright (c) 2009, Jamus Jegier
  4. All rights reserved.
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions are met:
  7. - Redistributions of source code must retain the above copyright notice, this
  8. list of conditions and the following disclaimer.
  9. - Redistributions in binary form must reproduce the above copyright notice,
  10. this list of conditions and the following disclaimer in the documentation
  11. and/or other materials provided with the distribution.
  12. - Neither the name of the Jamus Jegier nor the names of its contributors
  13. may be used to endorse or promote products derived from this software
  14. without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. require_once 'streamlib.php';
  28. $url=resolveMp3Stream($_GET["url"]);
  29. $parsed_url=parseMp3Stream($url);
  30. header('Content-Type: audio/mpeg');
  31. if (strcmp($_SERVER["HTTP_RANGE"],"bytes=0-1")==0)
  32. {
  33. header("HTTP/1.1 206 Partial Content");
  34. header('Accept-Ranges: bytes');
  35. header('Content-Range: bytes 0-1/4000000000');
  36. echo chr(255);
  37. echo chr(0xFB);
  38. exit;
  39. } else if (isset($_SERVER["HTTP_RANGE"])) {
  40. header("HTTP/1.1 206 Partial Content");
  41. header('Content-Length: 4000000000');
  42. header('Content-Range: bytes 0-3999999999/4000000000');
  43. header('Accept-Ranges: bytes');
  44. } else {
  45. header("HTTP/1.1 200 OK");
  46. header('Content-Length: 4000000000');
  47. header('Accept-Ranges: bytes');
  48. }
  49. $file=fsockopen($parsed_url["site"],$parsed_url["port"]);
  50. fputs($file,"GET ".$parsed_url["loc"]." HTTP/1.0\n\n");
  51. while (1)
  52. {
  53. $data=fread($file,1);
  54. if ($data==chr(255))
  55. {
  56. $data=fread($file,1);
  57. if ($data==chr(0xFB))
  58. break;
  59. }
  60. }
  61. echo chr(255);
  62. echo chr(0xFB);
  63. while (1)
  64. {
  65. $data=fread($file,1024);
  66. echo $data;
  67. }
  68. ?>