PageRenderTime 31ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/umsp/plugins/grooveshark/grooveshark-proxy.php

http://umspx.googlecode.com/
PHP | 101 lines | 43 code | 14 blank | 44 comment | 10 complexity | f616e87d934320b52498f435bba97568 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?PHP
  2. /*
  3. (C) 2010 sombragris.
  4. http://forum.wdlxtv.com/viewtopic.php?f=53&t=2802
  5. This Grooveshark plugin is designed for Zoster's USMP server which runs (amongst others)
  6. inside the EM7075 and DTS variant.
  7. This code is GPL licensed. Please read it here: http://www.gnu.org/licenses/gpl.html
  8. In addtion to section 7 of the GPL terms, there is one additional term :
  9. G) You must keep this header intact when you intend to release modified copies of the program.
  10. Thank you, and enjoy this plugin.
  11. */
  12. include_once('grooveshark-helper.php');
  13. // There is no MP3 cache or it failed... So let's get on
  14. // OpenCache
  15. if( file_exists('/var/cache/grooveshark') ) {
  16. $cache = new SimpleXMLElement( file_get_contents('/var/cache/grooveshark') );
  17. } else {
  18. header("HTTP/1.0 404 Not Found");
  19. trigger_error('Unable to load grooveshark cache file ', E_USER_ERROR);
  20. exit();
  21. }
  22. $songToken = grooveshark_getTokenForSong($_GET['SongID']);
  23. // ToDo: Necesito el pu?etero ArtistID!!!
  24. $stream = grooveshark_getStreamFromSongIDEx($_GET['SongID']);
  25. // Tell grooveshark we are downloading this file
  26. $result = grooveshark_markSongDownloadedEx($_GET['SongID'], $stream['streamServerID'], $stream['streamKey']);
  27. // Ignore!
  28. //if( $result['return'] !== '1' ) {
  29. // header("HTTP/1.0 404 Not Found");
  30. // trigger_error('Method <b>markSongDownloadedEx</b> returned <b>' . $result['return'] . '</b>', E_USER_ERROR);
  31. // exit();
  32. //}
  33. // ToDo: Start downloading
  34. $fp = fsockopen($stream['ip'], 80, $errno, $errstr, 30);
  35. if (!$fp) {
  36. header("HTTP/1.0 404 Not Found");
  37. trigger_error('Unable to open the stream server <b>' . $stream['ip']. '</b>', E_USER_ERROR);
  38. exit();
  39. } else {
  40. $content = 'streamKey=' . urlencode($stream['streamKey']);
  41. $out = "POST /stream.php HTTP/1.1\r\n" .
  42. "Host: " . $stream['ip'] . "\r\n" .
  43. "Cookie: PHPSESSID=" . (string)$cache->herader->session . "\r\n" .
  44. "Referer: http://listen.grooveshark.com/JSQueue.swf?20101203.19\r\n" .
  45. "Content-type: application/x-www-form-urlencoded\r\n" .
  46. "Content-length: " . strlen($content) . "\r\n\r\n" .
  47. $content;
  48. fwrite($fp, $out);
  49. set_time_limit(0);
  50. $headerpassed = false;
  51. while ($headerpassed == false) {
  52. $line = fgets( $fp);
  53. if((stristr($line, 'Content-Type')) || (stristr($line, 'Content-Length'))) {
  54. header($line);
  55. }
  56. if( $line == "\r\n" ) {
  57. header('Content-Disposition: attachment; filename="' . urldecode($_GET['SongID']) . '.mp3"');
  58. $headerpassed = true;
  59. }
  60. }
  61. fpassthru($fp);
  62. fclose($fp);
  63. }
  64. //$result = _groovesharkMarkSongComplete();
  65. //
  66. // ToDo: Tell Grooveshark we are done
  67. //$parameters = array(
  68. // 'streamServerID'=> $stream['streamServerID'],
  69. // 'streamKey' => $stream['streamKey'],
  70. // 'songID' => $_GET['songID'],
  71. // 'song' => array(
  72. // 'artistName' => null,
  73. // 'albumID' => null,
  74. // 'songID' => null,
  75. // 'songName' => $_GET['songID'],
  76. // 'token' => $stream['FileToken'], /* short token */
  77. // 'artFilename' => null,
  78. // 'albumName' => null,
  79. // 'artistID' => null
  80. // )
  81. // );
  82. //_groovesharkSend('markSongQueueSongPlayed');
  83. ?>