Skip to content

Commit

Permalink
Add method to get live Video for Event
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubz committed Sep 22, 2020
1 parent 3324bb7 commit a97e28f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/LiveStream/LiveStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use LiveStream\Exceptions\LiveStreamException;
use LiveStream\Exceptions\InValidResourceException;
use LiveStream\Resources\Video;

class LiveStream
{
Expand Down Expand Up @@ -338,6 +339,48 @@ public function resetRtmpKey(int $accountId, int $eventId): ?RTMPKey
return RTMPKey::fromObject(json_decode($response));
}

/**
* Gets current live Video for an Event, if one exists.
*
* @param int $accountId
* @param int $eventId
* @param ?int $offsetPostId
* @param ?int $older
* @param ?int $newer
*
* @return \LiveStream\Resources\Video|null
*
* @see https://livestream.com/developers/docs/api/#get-videos
*
* @throws \LiveStream\Exceptions\LiveStreamException
*/
public function getLiveVideo(
int $accountId,
int $eventId,
?int $offsetPostId = null,
?int $older = null,
?int $newer = null
): ?Video {
$video = null;

$response = $this->request("accounts/$accountId/events/$eventId/videos", 'get', null, [
'offsetPostId' => $offsetPostId,
'older' => $older,
'newer' => $newer
]);

if ($response === null) return null;

$response_data = json_decode($response);

if ($response_data->live) {
/** @var \LiveStream\Resources\Video $video */
$video = Video::fromObject($response_data->live);
}

return $video;
}

/**
* CURL Request
*
Expand Down
27 changes: 27 additions & 0 deletions src/LiveStream/Resources/Video.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace LiveStream\Resources;

/**
* Video Object
*
* @property int $id The integer representation of the unique identifier for this video post.
* @property bool $draft This indicates whether or not the post is published.
* @property int $views The number of times this video post was viewed.
* @property object $likes An object containing a single property, total, which indicates the number of accounts who like this video post.
* @property object $comments An object containing a single property, total, which indicates the number of accounts who have commented on this video post.
* @property string $caption The user-defined title of the video post as a UTF-8 string.
* @property string $description The user-defined detailed description of the video post as a UTF-8 string.
* @property int $duration The duration of video in milliseconds.
* @property int $eventId The unique ID of the event where this video post has been posted.
* @property string $createdAt The creation date and time for the post as a string in ISO 8601 date time format.
* @property ?string $publishAt Videos are published instantly by default unless draft is set to true. To publish an event in the future, set the date and time using ISO8601 date time format.
* @property string $thumbnailUrl The full URL of the video thumbnail.
* @property string $thumbnailUrlSmall The full URL of the small thumbnail of the video (150px x 84px).
* @property string $m3u8 The m3u8 url of the live/VOD HLS stream (requires secure token authentication).
* @property array $tags Tags given for the video post in an array.
*/
class Video extends Resource
{

}

0 comments on commit a97e28f

Please sign in to comment.