https://github.com/dakdevs/php-stream-api
PHP API Wrapper for Stream Services such as Twitch.tv and Hitbox.tv. YouTube Gaming coming soon...
https://github.com/dakdevs/php-stream-api
Last synced: about 1 month ago
JSON representation
PHP API Wrapper for Stream Services such as Twitch.tv and Hitbox.tv. YouTube Gaming coming soon...
- Host: GitHub
- URL: https://github.com/dakdevs/php-stream-api
- Owner: dakdevs
- Created: 2016-05-30T03:05:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-26T00:36:17.000Z (over 9 years ago)
- Last Synced: 2025-02-15T05:25:05.632Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 49.8 KB
- Stars: 3
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP API Wrapper for multiple streaming services.
**Note:** Update coming, as Twitch has updated their API making this currently obsolete.
#### Supported Service Providers
* [Twitch.tv](http://www.twitch.tv)
* [Hitbox.tv](http://www.hitbox.tv)
## Install via Composer
```shell
$ composer require vinlock/stream-api
```
## Usage
### Merging games.
```php
$twitch = \Vinlock\StreamAPI\Services\Twitch::game("Dota 2");
$hitbox = \Vinlock\StreamAPI\Services\Hitbox::game("Dota 2");
$merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $hitbox);
echo $merge->getJSON(); // Displays all streams from highest to lowest viewers for Dota 2 on Twitch and Hitbox.
```
Merge as many games as you want...
```php
$bladeandsoul_twitch = \Vinlock\StreamAPI\Services\Twitch::game("Blade and Soul");
$bladeandsoul_hitbox = \Vinlock\StreamAPI\Services\Hitbox::game("Blade and Soul");
$overwatch_twitch = \Vinlock\StreamAPI\Services\Twitch::game("Overwatch");
$overwatch_hitbox = \Vinlock\StreamAPI\Services\Hitbox::game("Overwatch");
$merge = \Vinlock\StreamAPI\Services\Service::merge(
$bladeandsoul_twitch,
$bladeandsoul_hitbox,
$overwatch_twitch,
$overwatch_hitbox
);
```
Or you may pass in the games as an array.
```php
$games = [
"Blade and Soul",
"Overwatch",
"Aion Online"
];
$twitch = \Vinlock\StreamAPI\Services\Twitch::game($games);
$hitbox = \Vinlock\StreamAPI\Services\Hitbox::game($games);
$merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $hitbox);
// or pass the Service Objects as an array to be merged.
$merge = \Vinlock\StreamAPI\Services\Service::merge( [ $twitch, $hitbox ] );
echo $merge->getJSON();
```
### From Usernames
Results will only show for online users.
```php
$twitch = new \Vinlock\StreamAPI\Services\Twitch("vinlockz");
$hitbox = new \Vinlock\StreamAPI\Services\Hitbox("vinlock");
```
Or pass many usernames as an array.
```php
$twitch_streams = [ "trick2g", "vinlockz", ... ];
$hitbox_streams = [ "hitboxstream1", "hitboxstream2", ... ];
$twitch = new \Vinlock\StreamAPI\Services\Twitch($twitch_streams);
$hitbox = new \Vinlock\StreamAPI\Services\Twitch($hitbox_streams);
```
Then merge these as well.
```php
$merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $hitbox);
// or
$merge = \Vinlock\StreamAPI\Services\Service::merge( [ $twitch, $hitbox ] );
echo $merge->getJSON(); // Displays the information for all streams merged as JSON.
```
### Universal Merging
You may merge instances initialized by usernames with ones initialized by Games.
```php
$bladeandsoul_twitch = \Vinlock\StreamAPI\Services\Twitch::game("Blade and Soul");
$twitch = new \Vinlock\StreamAPI\Services\Twitch("vinlockz");
$merge = \Vinlock\StreamAPI\Services\Service::merge($twitch, $bladeandsoul_twitch);
$merge->getJSON();
```
### Data Retrieval
You can get an array, JSON, or object from the Service Object.
```php
echo $merge->getJSON(); // Displays the information for all streams merged as JSON.
echo $merge->getArray(); // Array
echo $merge->getObject(); // Object
```
## Example JSON
This will be universal for every stream provider.
```json
[
{
"username": "trick2g",
"display_name": "Trick2g",
"game": "League of Legends",
"preview": {
"small": "https://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-80x45.jpg",
"medium": "https://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-320x180.jpg",
"large": "https://static-cdn.jtvnw.net/previews-ttv/live_user_trick2g-640x360.jpg"
},
"status": "100% Advan | Silver Clown Fiesta 101 How to TDM #Na Throws @Trick2g Day 35 No Sodabull",
"bio": "Opening the Gates",
"url": "https://www.twitch.tv/trick2g",
"viewers": 4040,
"id": 28036688,
"avatar": "https://static-cdn.jtvnw.net/jtv_user_pictures/trick2g-profile_image-291046f75304f006-300x300.jpeg",
"service": "twitch",
"followers": 996140,
"created_at": "05-31-2016 01:15:12",
"updated_at": "05-31-2016 03:36:19"
}
]
```