Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: API do odczytywania tytułu piosenki
Forum PHP.pl > Forum > PHP
Parrot
Witam, uruchomiłem musicbota na moim serwerze ts3.
Chciałbym aby na stronie WWW była infromacja jaka piosenka w gra w tej chwili.
Pobieram muzykę z http://gr-relay-16.gaduradio.pl/95
Czy jest jakieś api do tego?
Beniooo
  1. function getMp3StreamTitle($streamingUrl, $interval, $offset = 0, $headers = true)
  2. {
  3. $needle = 'StreamTitle=';
  4. $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36';
  5.  
  6. $opts = [
  7. 'http' => [
  8. 'method' => 'GET',
  9. 'header' => 'Icy-MetaData: 1',
  10. 'user_agent' => $ua
  11. ]
  12. ];
  13.  
  14. if (($headers = get_headers($streamingUrl)))
  15. foreach ($headers as $h)
  16. if (strpos(strtolower($h), 'icy-metaint') !== false && ($interval = explode(':', $h)[1]))
  17. break;
  18.  
  19. $context = stream_context_create($opts);
  20.  
  21. if ($stream = fopen($streamingUrl, 'r', false, $context))
  22. {
  23. $buffer = stream_get_contents($stream, $interval, $offset);
  24. fclose($stream);
  25.  
  26. if (strpos($buffer, $needle) !== false)
  27. {
  28. $title = explode($needle, $buffer)[1];
  29. return substr($title, 1, strpos($title, ';') - 2);
  30. }
  31. else
  32. return getMp3StreamTitle($streamingUrl, $interval, $offset + $interval, false);
  33. }
  34. else
  35. throw new Exception("Unable to open stream [{$streamingUrl}]");
  36. }
  37.  
  38. var_dump(getMp3StreamTitle('http://gr-relay-16.gaduradio.pl/95', 19200));

Minimum PHP 5.4
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.