This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoDetails.php
185 lines (175 loc) · 5.86 KB
/
VideoDetails.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* Active video and oEmbed details along with it's relevant metadata.
*
*/
class Rendition {
var $type;
var $statusId;
var $status;
}
class VideoDetails
{
var $type;
var $version;
var $title;
var $description;
var $playCount;
var $authorName;
var $authorUrl;
var $authorAccount;
var $providerName;
var $providerUrl;
var $thumbnailUrl;
var $thumbnailWidth;
var $thumbnailHeight;
var $framegrabUrl;
var $framegrabWidth;
var $framegrabHeight;
var $html;
var $height;
var $width;
var $borderless;
var $duration;
var $videoStatus;
var $videoStatusDescription;
var $renditions;
var $totalSize;
/**
* Package protected constructor.
*
* @param type the oEmbed resource type
* @param version the vzaar API version number
* @param title the video title. It may be null
* @param description the video description. It may be null
* @param authorName the vzaar user name (i.e. their login)
* @param authorUrl the link to the vzaar user summary page
* @param authorAccount the number representing the users vzaar account
* @param providerName this will always be vzaar
* @param providerUrl this will always be http://vzaar.com
* @param thumbnailUrl the URL link that points to the video thumbnail
* @param thumbnailWidth the width of the thumbnail in pixels
* @param thumbnailHeight the height of the thumbnail in pixels
* @param framegrabUrl the URL that points to a framegrab of the video
* @param framegrabWidth the width of the frame grab in pixels
* @param framegrabHeight the height of the frame grab in pixels
* @param html the exact HTML you need to use to embed the video into a webpage
* @param height the height of the video
* @param width the width of the video
* @param borderless does the video player has no border
* @param duration the duration of the video
*/
function __construct()
{
}
function __construct1($type, $version, $title, $description, $authorName, $authorUrl, $authorAccount, $providerName, $providerUrl, $thumbnailUrl, $thumbnailWidth, $thumbnailHeight, $framegrabUrl, $framegrabWidth, $framegrabHeight, $html, $height, $width, $borderless, $duration, $videoStatus, $renditions, $totalSize)
{
$this->type = $type;
$this->version = $version;
$this->title = $title;
$this->description = $description;
$this->user->authorName = $authorName;
$this->user->authorUrl = $authorUrl;
$this->user->authorAccount = $authorAccount;
$this->providerName = $providerName;
$this->providerUrl = $providerUrl;
$this->thumbnailUrl = $thumbnailUrl;
$this->thumbnailWidth = $thumbnailWidth;
$this->thumbnailHeight = $thumbnailHeight;
$this->framegrabUrl = $framegrabUrl;
$this->framegrabWidth = $framegrabWidth;
$this->framegrabHeight = $framegrabHeight;
$this->html = $html;
$this->height = $height;
$this->width = $width;
$this->borderless = $borderless;
$this->duration = $duration;
$this->videoStatus = $videoStatus;
$this->renditions = $renditions;
$this->totalSize = $totalSize;
}
/**
* Contructs Video Details object from JSON
* @param <type> $data
* @return VideoDetails
*/
static function fromJson($data)
{
$jo = json_decode($data); //error messages comes in format like this: "{"error":"In progress"}"
if ($jo == NULL)
{
return NULL;
}
else
{
$vid = new VideoDetails();
if (array_key_exists('error', $jo))
{
if (strpos($jo->error, 'progress'))
{
$vid->type = 'video';
$vid->videoStatus = VideoStatus::PROCESSING;
$vid->videoStatusDescription = VideoStatusDescriptions::PROCESSING;
}
}
else
{
if (array_key_exists('vzaar-api', $jo))
{
$vars = get_object_vars($jo);
if (array_key_exists('error', $vars['vzaar-api']))
{
throw new VzaarException($vars['vzaar-api']->error->type);
}
else
{
$vid->videoStatus = $vars['vzaar-api']->video->video_status_id;
$vid->videoStatusDescription = $vars['vzaar-api']->video->state;
}
}
else
{
$vid->authorAccount = $jo->author_account;
$vid->authorName = $jo->author_name;
$vid->authorUrl = $jo->author_url;
$vid->borderless = (array_key_exists('borderless', $jo) ? $jo->borderless : NULL);
$vid->description = (array_key_exists('description', $jo) ? $jo->description : NULL);
$vid->duration = (array_key_exists('duration', $jo) ? $jo->duration : NULL);
$vid->framegrabHeight = (array_key_exists('framegreb_height', $jo) ? $jo->framegreb_height : NULL);
$vid->framegrabUrl = (array_key_exists('framegrab_url', $jo) ? $jo->framegrab_url : NULL);
$vid->framegrabWidth = (array_key_exists('framegrab_width', $jo) ? $jo->framegrab_width : NULL);
$vid->height = $jo->height;
$vid->html = $jo->html;
$vid->providerName = $jo->provider_name;
$vid->providerUrl = $jo->provider_url;
$vid->thumbnailHeight = (array_key_exists('thumbnail_height', $jo) ? $jo->thumbnail_height : NULL);
$vid->thumbnailUrl = (array_key_exists('thumbnail_url', $jo) ? $jo->thumbnail_url : NULL);
$vid->thumbnailWidth = (array_key_exists('thumbnail_width', $jo) ? $jo->thumbnail_width : NULL);
$vid->title = $jo->title;
$vid->playCount = $jo->play_count;
$vid->type = $jo->type;
$vid->version = $jo->version;
$vid->width = $jo->width;
$vid->videoStatus = (array_key_exists('video_status_id', $jo) ? $jo->video_status_id : 0);
$vid->videoStatusDescription = (array_key_exists('video_status_description', $jo) ? $jo->video_status_description : '');
$vid->renditions = VideoDetails::parseRenditions($jo->renditions);
$vid->totalSize = $jo->total_size;
}
}
return $vid;
}
}
private static function parseRenditions($renditions)
{
$col = array();
foreach ((array)$renditions as $el) {
$ren = new Rendition();
$ren->type = $el->type;
$ren->statusId = $el->status_id;
$ren->status = $el->status;
array_push($col, $ren);
}
return $col;
}
}
?>