Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> API do odczytywania tytułu piosenki
Parrot
post
Post #1





Grupa: Zarejestrowani
Postów: 5
Pomógł: 0
Dołączył: 30.08.2014

Ostrzeżenie: (0%)
-----


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?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
Beniooo
post
Post #2





Grupa: Zarejestrowani
Postów: 260
Pomógł: 26
Dołączył: 26.01.2012
Skąd: Ci to przyszło do głowy?

Ostrzeżenie: (0%)
-----


  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


--------------------
Mój post rozwiązał Twój problem? Naciśnij co Ci szkodzi? ;-)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 17:22