GithubHelp home page GithubHelp logo

azuracast / nowplaying Goto Github PK

View Code? Open in Web Editor NEW
28.0 8.0 9.0 178 KB

A lightweight PHP adapter for viewing the current now playing data in Icecast and SHOUTcast 1/2. A part of the AzuraCast software suite.

License: Apache License 2.0

PHP 98.93% Dockerfile 1.07%
azuracast php library webcasting icecast shoutcast web-radio

nowplaying's Introduction

NowPlaying

NowPlaying is a lightweight, modern, object-oriented PHP library that abstracts out the currently playing metadata from popular radio broadcast software into a single common return format.

Installing

NowPlaying is a Composer package that you can include in your project by running:

composer require azuracast/nowplaying

Compatibility

Now Playing data Detailed client information
Icecast (2.4+)
SHOUTcast 2
SHOUTcast 1

Usage Example

<?php
// Example PSR-17 and PSR-18 implementation from Guzzle 7
// Install those with:
//   composer require guzzlehttp/guzzle

$httpFactory = new GuzzleHttp\Psr7\HttpFactory();
$adapterFactory = new NowPlaying\AdapterFactory(
    $httpFactory,
    $httpFactory,
    new GuzzleHttp\Client
);

$adapter = $adapterFactory->getAdapter(
    NowPlaying\Enums\AdapterType::Shoutcast2,
    'http://my-station-url.example.com:8000'
);

// You can also call:
// $adapterFactory->getShoutcast2Adapter('http://url');

// Optionally set administrator password
$adapter->setAdminUsername('admin'); // "admin" is the default
$adapter->setAdminPassword('AdminPassword!');

// The first argument to the functions is the mount point or
// stream ID (SID), to pull one specific stream's information.
$now_playing = $adapter->getNowPlaying('1');

$clients = $adapter->getClients('1');

Example "now playing" response (PHP objects represented in JSON):

{
  "currentSong": {
    "text": "Joe Bagale - Until We Meet Again",
    "title": "Until We Meet Again",
    "artist": "Joe Bagale"
  },
  "listeners": {
    "total": 0,
    "unique": 0
  },
  "meta": {
    "online": true,
    "bitrate": 128,
    "format": "audio/mpeg"
  },
  "clients": []
}

Example "clients" response:

[
  {
    "uid": 1,
    "ip": "127.0.0.1",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
    "connectedSeconds": 123
  }
]

nowplaying's People

Contributors

busterneece avatar markwasley avatar vaalyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nowplaying's Issues

SimpleXMLElement::simplexml_load_string fails on illegal char

As mentioned in this issue for AzuraCast it is possible that the XML response from IceCast contains an illegal character which leads to a failure to decode the response via the simplexml_load_string function.

In the issue mentioned above this illegal character gets send by a faulty streaming software to IceCast but regardless of what is sending this illegal char to IceCast since IceCast itself has no problem with the char and happily returns an XML containing it this library should be able to deal with cases like this. It could make sense to switch from using simplexml to something like sabre/xml which uses the DOM API which is much more robust than simplexml.

Artist and Title split in the wrong place when there is more than one hyphen

For a long time the track artist and track title have been split in the wrong place. Because the hyphen is being used as a delimiter to split the two, this has been causing a problem when there is more that one hyphen in $text.

For example, if I have a track named The Beatles - Yesterday - Live from The ABC Theatre, Blackpool, UK 1965, the artist will be set as The Beatles - Yesterday and the title will be set as Live from The ABC Theatre, Blackpool, UK 1965.

Icecast remote sources, including other AzuraCast stations, do not pass title and artist metadata to AzuraCast even if they are set on the original source, requiring the title that it does provide, to be split.

I will submit a pull request shortly to fix this.

Now Playing Update /admin/stats API call fails due to URL-encoded basic authentication parameters

This issue seems to particularly affect AzuraMirror.

We patched status.xsl, xspf.xsl, status-json.xsl and status2.xsl to hide listener statistics from curious members of the public. Consequently, the Now Playing Update command won't run owing to listeners being NULL on the JSON now playing data.

But as the Icecast adapter has HTTP basic authentication available, it should be first trying /admin/stats. This appears to be failing due to source:password being in an urlencoded format before being parsed in this file., resulting in an empty password being supplied and a 401 error.

I fixed this by wrapping $uriUserInfo in urldecode before it is exploded.

Cant install

Wich folder do i need to enter to install this? And are there requirements?

Use admin passwort in Shoutcast2 adapter if set

This issue is prompted by this AzuraCast issue.

The Shoutcast2 adapter is currently not using the admin password if it is set. The IceCast adapter uses it if it is set. In order to still access the API when the puplic access to it is blocked the pass query parameter should be set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.