scrobble-proxy.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('config.php');
  16. if ($_GET['method'] == 'scrobble') {
  17. $url = $submissions_server . '/submissions/1.2/';
  18. } else if ($_GET['method'] == 'nowplaying') {
  19. $url = $submissions_server . '/nowplaying/1.2/';
  20. } else {
  21. die("Invalid proxy method\n");
  22. }
  23. $session = curl_init($url);
  24. $post_vars = '';
  25. foreach ($_POST as $key => $element) {
  26. if (is_array($element)) {
  27. $i = 0;
  28. foreach ($element as $e) {
  29. $post_vars .= $key . '[' . $i . ']=' . rawurlencode($e) . '&';
  30. $i++;
  31. }
  32. } else {
  33. $post_vars .= $key . '=' . rawurlencode($element) . '&';
  34. }
  35. }
  36. curl_setopt($session, CURLOPT_POST, true);
  37. curl_setopt($session, CURLOPT_POSTFIELDS, $post_vars);
  38. $response = curl_exec($session);
  39. echo $response;
  40. curl_close($session);