@@ -9,8 +9,8 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Video_Storage_Factory { |
| 11 | 11 | |
| 12 | - public static function get_storage() { |
|
| 13 | - return new Meta_Storage(); |
|
| 14 | - } |
|
| 12 | + public static function get_storage() { |
|
| 13 | + return new Meta_Storage(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | 16 | } |
| 17 | 17 | \ No newline at end of file |
@@ -10,41 +10,41 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | interface Storage { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param $post_id int Post id to add video. |
|
| 15 | - * @param $video Video The video object which needs to be saved. |
|
| 16 | - * |
|
| 17 | - * @return bool true if video is added, false otherwise. |
|
| 18 | - */ |
|
| 19 | - public function add_video( $post_id, $video ); |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Return all video objects for the post |
|
| 23 | - * |
|
| 24 | - * @param $post_id int Post id to get all videos. |
|
| 25 | - * |
|
| 26 | - * @return array<Video> |
|
| 27 | - */ |
|
| 28 | - public function get_all_videos( $post_id ); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Remove the Video Object. |
|
| 32 | - * |
|
| 33 | - * @param $videos_to_be_removed array<Video> |
|
| 34 | - * |
|
| 35 | - * @param $post_id int |
|
| 36 | - * |
|
| 37 | - * @return bool return true if removed or false |
|
| 38 | - */ |
|
| 39 | - public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Remove all videos present for post id |
|
| 43 | - * |
|
| 44 | - * @param $post_id |
|
| 45 | - * |
|
| 46 | - * @return true if removed else false. |
|
| 47 | - */ |
|
| 48 | - public function remove_all_videos( $post_id ); |
|
| 13 | + /** |
|
| 14 | + * @param $post_id int Post id to add video. |
|
| 15 | + * @param $video Video The video object which needs to be saved. |
|
| 16 | + * |
|
| 17 | + * @return bool true if video is added, false otherwise. |
|
| 18 | + */ |
|
| 19 | + public function add_video( $post_id, $video ); |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Return all video objects for the post |
|
| 23 | + * |
|
| 24 | + * @param $post_id int Post id to get all videos. |
|
| 25 | + * |
|
| 26 | + * @return array<Video> |
|
| 27 | + */ |
|
| 28 | + public function get_all_videos( $post_id ); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Remove the Video Object. |
|
| 32 | + * |
|
| 33 | + * @param $videos_to_be_removed array<Video> |
|
| 34 | + * |
|
| 35 | + * @param $post_id int |
|
| 36 | + * |
|
| 37 | + * @return bool return true if removed or false |
|
| 38 | + */ |
|
| 39 | + public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Remove all videos present for post id |
|
| 43 | + * |
|
| 44 | + * @param $post_id |
|
| 45 | + * |
|
| 46 | + * @return true if removed else false. |
|
| 47 | + */ |
|
| 48 | + public function remove_all_videos( $post_id ); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @return bool true if video is added, false otherwise. |
| 18 | 18 | */ |
| 19 | - public function add_video( $post_id, $video ); |
|
| 19 | + public function add_video($post_id, $video); |
|
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | 22 | * Return all video objects for the post |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * |
| 26 | 26 | * @return array<Video> |
| 27 | 27 | */ |
| 28 | - public function get_all_videos( $post_id ); |
|
| 28 | + public function get_all_videos($post_id); |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Remove the Video Object. |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return bool return true if removed or false |
| 38 | 38 | */ |
| 39 | - public function remove_videos( $videos_to_be_removed, $post_id ); |
|
| 39 | + public function remove_videos($videos_to_be_removed, $post_id); |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * Remove all videos present for post id |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | * |
| 46 | 46 | * @return true if removed else false. |
| 47 | 47 | */ |
| 48 | - public function remove_all_videos( $post_id ); |
|
| 48 | + public function remove_all_videos($post_id); |
|
| 49 | 49 | |
| 50 | 50 | } |
| 51 | 51 | \ No newline at end of file |
@@ -11,8 +11,8 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | interface Embedded_Video { |
| 13 | 13 | |
| 14 | - public function get_api_provider(); |
|
| 14 | + public function get_api_provider(); |
|
| 15 | 15 | |
| 16 | - public function get_url(); |
|
| 16 | + public function get_url(); |
|
| 17 | 17 | |
| 18 | 18 | } |
| 19 | 19 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Embedded_Video_Factory { |
| 9 | 9 | |
| 10 | - public static function get_embedded_video( $video_url ) { |
|
| 11 | - return new Default_Embedded_Video( $video_url ); |
|
| 12 | - } |
|
| 10 | + public static function get_embedded_video( $video_url ) { |
|
| 11 | + return new Default_Embedded_Video( $video_url ); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -7,8 +7,8 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Embedded_Video_Factory { |
| 9 | 9 | |
| 10 | - public static function get_embedded_video( $video_url ) { |
|
| 11 | - return new Default_Embedded_Video( $video_url ); |
|
| 10 | + public static function get_embedded_video($video_url) { |
|
| 11 | + return new Default_Embedded_Video($video_url); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | } |
| 15 | 15 | \ No newline at end of file |
@@ -7,20 +7,20 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Default_Embedded_Video implements Embedded_Video { |
| 9 | 9 | |
| 10 | - /** |
|
| 11 | - * @var string The url of the video which got embedded. |
|
| 12 | - */ |
|
| 13 | - private $video_url; |
|
| 10 | + /** |
|
| 11 | + * @var string The url of the video which got embedded. |
|
| 12 | + */ |
|
| 13 | + private $video_url; |
|
| 14 | 14 | |
| 15 | - public function __construct( $video_url ) { |
|
| 16 | - $this->video_url = $video_url; |
|
| 17 | - } |
|
| 15 | + public function __construct( $video_url ) { |
|
| 16 | + $this->video_url = $video_url; |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - public function get_api_provider() { |
|
| 20 | - // TODO: Implement get_api_provider() method. |
|
| 21 | - } |
|
| 19 | + public function get_api_provider() { |
|
| 20 | + // TODO: Implement get_api_provider() method. |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function get_url() { |
|
| 24 | - return $this->video_url; |
|
| 25 | - } |
|
| 23 | + public function get_url() { |
|
| 24 | + return $this->video_url; |
|
| 25 | + } |
|
| 26 | 26 | } |
| 27 | 27 | \ No newline at end of file |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | private $video_url; |
| 14 | 14 | |
| 15 | - public function __construct( $video_url ) { |
|
| 15 | + public function __construct($video_url) { |
|
| 16 | 16 | $this->video_url = $video_url; |
| 17 | 17 | } |
| 18 | 18 | |
@@ -7,91 +7,91 @@ |
||
| 7 | 7 | namespace Wordlift\Videoobject\Data\Video; |
| 8 | 8 | |
| 9 | 9 | class Video { |
| 10 | - /** |
|
| 11 | - * @var string The title of the video. |
|
| 12 | - */ |
|
| 13 | - public $name; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * @var string The video description. |
|
| 17 | - */ |
|
| 18 | - public $description; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * @var array Thumbnail urls. |
|
| 22 | - */ |
|
| 23 | - public $thumbnail_urls; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string Published date. |
|
| 27 | - */ |
|
| 28 | - public $upload_date; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string Video url. |
|
| 32 | - */ |
|
| 33 | - public $content_url; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string Video duration in IS08601 format. |
|
| 37 | - */ |
|
| 38 | - public $duration; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - public $embed_url; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string An unique identifier, usually the video url. |
|
| 47 | - */ |
|
| 48 | - public $id; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var int The number of views for the video. |
|
| 52 | - */ |
|
| 53 | - public $views; |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * All the live video properties. |
|
| 58 | - */ |
|
| 59 | - /** |
|
| 60 | - * @var bool |
|
| 61 | - */ |
|
| 62 | - public $is_live_video; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string Live video start date |
|
| 66 | - */ |
|
| 67 | - public $live_video_start_date; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var string Live video end date |
|
| 71 | - */ |
|
| 72 | - public $live_video_end_date; |
|
| 73 | - |
|
| 74 | - public function from( $data ) { |
|
| 75 | - $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 76 | - // Loop through the keys and set the value from array |
|
| 77 | - foreach ( $keys as $key ) { |
|
| 78 | - $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - public function get_data() { |
|
| 83 | - |
|
| 84 | - return array( |
|
| 85 | - '@type' => 'VideoObject', |
|
| 86 | - 'name' => $this->name, |
|
| 87 | - 'description' => $this->description, |
|
| 88 | - 'contentUrl' => $this->content_url, |
|
| 89 | - 'embedUrl' => $this->embed_url, |
|
| 90 | - 'uploadDate' => $this->upload_date, |
|
| 91 | - 'thumbnailUrl' => $this->thumbnail_urls, |
|
| 92 | - 'duration' => $this->duration |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - } |
|
| 10 | + /** |
|
| 11 | + * @var string The title of the video. |
|
| 12 | + */ |
|
| 13 | + public $name; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * @var string The video description. |
|
| 17 | + */ |
|
| 18 | + public $description; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * @var array Thumbnail urls. |
|
| 22 | + */ |
|
| 23 | + public $thumbnail_urls; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string Published date. |
|
| 27 | + */ |
|
| 28 | + public $upload_date; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string Video url. |
|
| 32 | + */ |
|
| 33 | + public $content_url; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string Video duration in IS08601 format. |
|
| 37 | + */ |
|
| 38 | + public $duration; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + public $embed_url; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var string An unique identifier, usually the video url. |
|
| 47 | + */ |
|
| 48 | + public $id; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @var int The number of views for the video. |
|
| 52 | + */ |
|
| 53 | + public $views; |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * All the live video properties. |
|
| 58 | + */ |
|
| 59 | + /** |
|
| 60 | + * @var bool |
|
| 61 | + */ |
|
| 62 | + public $is_live_video; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string Live video start date |
|
| 66 | + */ |
|
| 67 | + public $live_video_start_date; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @var string Live video end date |
|
| 71 | + */ |
|
| 72 | + public $live_video_end_date; |
|
| 73 | + |
|
| 74 | + public function from( $data ) { |
|
| 75 | + $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 76 | + // Loop through the keys and set the value from array |
|
| 77 | + foreach ( $keys as $key ) { |
|
| 78 | + $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + public function get_data() { |
|
| 83 | + |
|
| 84 | + return array( |
|
| 85 | + '@type' => 'VideoObject', |
|
| 86 | + 'name' => $this->name, |
|
| 87 | + 'description' => $this->description, |
|
| 88 | + 'contentUrl' => $this->content_url, |
|
| 89 | + 'embedUrl' => $this->embed_url, |
|
| 90 | + 'uploadDate' => $this->upload_date, |
|
| 91 | + 'thumbnailUrl' => $this->thumbnail_urls, |
|
| 92 | + 'duration' => $this->duration |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | 97 | } |
| 98 | 98 | \ No newline at end of file |
@@ -71,11 +71,11 @@ |
||
| 71 | 71 | */ |
| 72 | 72 | public $live_video_end_date; |
| 73 | 73 | |
| 74 | - public function from( $data ) { |
|
| 75 | - $keys = array_keys( get_class_vars( get_class( $this ) ) ); |
|
| 74 | + public function from($data) { |
|
| 75 | + $keys = array_keys(get_class_vars(get_class($this))); |
|
| 76 | 76 | // Loop through the keys and set the value from array |
| 77 | - foreach ( $keys as $key ) { |
|
| 78 | - $this->$key = array_key_exists( $key, $data ) ? $data[ $key ] : null; |
|
| 77 | + foreach ($keys as $key) { |
|
| 78 | + $this->$key = array_key_exists($key, $data) ? $data[$key] : null; |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | |
@@ -14,94 +14,94 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Vimeo extends Api_Provider { |
| 16 | 16 | |
| 17 | - const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key'; |
|
| 17 | + const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key'; |
|
| 18 | 18 | |
| 19 | - public static function get_api_key() { |
|
| 20 | - return get_option( self::API_FIELD_NAME, false ); |
|
| 21 | - } |
|
| 19 | + public static function get_api_key() { |
|
| 20 | + return get_option( self::API_FIELD_NAME, false ); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - public function get_videos_data( $videos ) { |
|
| 23 | + public function get_videos_data( $videos ) { |
|
| 24 | 24 | |
| 25 | - $key = $this->get_api_key(); |
|
| 25 | + $key = $this->get_api_key(); |
|
| 26 | 26 | |
| 27 | - if ( ! $key ) { |
|
| 28 | - return array(); |
|
| 29 | - } |
|
| 27 | + if ( ! $key ) { |
|
| 28 | + return array(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $urls = array_map( function ( $video ) { |
|
| 32 | - return $video->get_url(); |
|
| 33 | - }, $videos ); |
|
| 31 | + $urls = array_map( function ( $video ) { |
|
| 32 | + return $video->get_url(); |
|
| 33 | + }, $videos ); |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - $response_body = $this->api_client->get_data( $urls ); |
|
| 36 | + $response_body = $this->api_client->get_data( $urls ); |
|
| 37 | 37 | |
| 38 | - if ( ! is_string( $response_body ) || ! $response_body ) { |
|
| 39 | - return array(); |
|
| 40 | - } |
|
| 38 | + if ( ! is_string( $response_body ) || ! $response_body ) { |
|
| 39 | + return array(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $response = json_decode( $response_body, true ); |
|
| 42 | + $response = json_decode( $response_body, true ); |
|
| 43 | 43 | |
| 44 | - $video_list = $response['data']; |
|
| 44 | + $video_list = $response['data']; |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - if ( ! is_array( $video_list ) ) { |
|
| 48 | - // Return if we cant parse the response. |
|
| 49 | - return array(); |
|
| 50 | - } |
|
| 47 | + if ( ! is_array( $video_list ) ) { |
|
| 48 | + // Return if we cant parse the response. |
|
| 49 | + return array(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) ); |
|
| 53 | + return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) ); |
|
| 54 | 54 | |
| 55 | - } |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - public function get_video_from_video_data( $vimeo_video_data ) { |
|
| 57 | + public function get_video_from_video_data( $vimeo_video_data ) { |
|
| 58 | 58 | |
| 59 | - if ( ! $vimeo_video_data ) { |
|
| 60 | - // If valid data not supplied dont init the object. |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - $video = new Video(); |
|
| 64 | - $video->name = $vimeo_video_data['name']; |
|
| 65 | - $video->description = $vimeo_video_data['description']; |
|
| 59 | + if ( ! $vimeo_video_data ) { |
|
| 60 | + // If valid data not supplied dont init the object. |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + $video = new Video(); |
|
| 64 | + $video->name = $vimeo_video_data['name']; |
|
| 65 | + $video->description = $vimeo_video_data['description']; |
|
| 66 | 66 | |
| 67 | - $video->content_url = $vimeo_video_data['link']; |
|
| 68 | - $video->embed_url = "https://player.vimeo.com/video/" . $this->get_id( $vimeo_video_data ); |
|
| 69 | - if ( is_numeric( $vimeo_video_data['duration'] ) ) { |
|
| 70 | - $video->duration = "PT" . $vimeo_video_data['duration'] . "S"; |
|
| 71 | - } |
|
| 72 | - $video->upload_date = $vimeo_video_data['release_time']; |
|
| 73 | - $video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data ); |
|
| 74 | - $video->id = $video->content_url; |
|
| 67 | + $video->content_url = $vimeo_video_data['link']; |
|
| 68 | + $video->embed_url = "https://player.vimeo.com/video/" . $this->get_id( $vimeo_video_data ); |
|
| 69 | + if ( is_numeric( $vimeo_video_data['duration'] ) ) { |
|
| 70 | + $video->duration = "PT" . $vimeo_video_data['duration'] . "S"; |
|
| 71 | + } |
|
| 72 | + $video->upload_date = $vimeo_video_data['release_time']; |
|
| 73 | + $video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data ); |
|
| 74 | + $video->id = $video->content_url; |
|
| 75 | 75 | |
| 76 | - if ( array_key_exists( 'stats', $vimeo_video_data ) |
|
| 77 | - && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) { |
|
| 78 | - $video->views = (int) $vimeo_video_data['stats']['plays']; |
|
| 79 | - } |
|
| 76 | + if ( array_key_exists( 'stats', $vimeo_video_data ) |
|
| 77 | + && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) { |
|
| 78 | + $video->views = (int) $vimeo_video_data['stats']['plays']; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - return $video; |
|
| 82 | - } |
|
| 81 | + return $video; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - private function get_id( $api_response_data ) { |
|
| 85 | - return str_replace( "/videos/", "", $api_response_data['uri'] ); |
|
| 86 | - } |
|
| 84 | + private function get_id( $api_response_data ) { |
|
| 85 | + return str_replace( "/videos/", "", $api_response_data['uri'] ); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | 88 | |
| 89 | - private function set_thumbnail_urls( $api_response_data ) { |
|
| 89 | + private function set_thumbnail_urls( $api_response_data ) { |
|
| 90 | 90 | |
| 91 | - if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists( 'sizes', |
|
| 92 | - $api_response_data['pictures'] ) ) { |
|
| 93 | - return array(); |
|
| 94 | - } |
|
| 95 | - if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) { |
|
| 96 | - return array(); |
|
| 97 | - } |
|
| 98 | - $pictures = $api_response_data['pictures']['sizes']; |
|
| 91 | + if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists( 'sizes', |
|
| 92 | + $api_response_data['pictures'] ) ) { |
|
| 93 | + return array(); |
|
| 94 | + } |
|
| 95 | + if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) { |
|
| 96 | + return array(); |
|
| 97 | + } |
|
| 98 | + $pictures = $api_response_data['pictures']['sizes']; |
|
| 99 | 99 | |
| 100 | - return array_map( function ( $picture_data ) { |
|
| 101 | - return $picture_data['link']; |
|
| 102 | - }, $pictures ); |
|
| 100 | + return array_map( function ( $picture_data ) { |
|
| 101 | + return $picture_data['link']; |
|
| 102 | + }, $pictures ); |
|
| 103 | 103 | |
| 104 | - } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | 107 | } |
| 108 | 108 | \ No newline at end of file |
@@ -17,46 +17,46 @@ discard block |
||
| 17 | 17 | const API_FIELD_NAME = '_wl_videoobject_vimeo_api_key'; |
| 18 | 18 | |
| 19 | 19 | public static function get_api_key() { |
| 20 | - return get_option( self::API_FIELD_NAME, false ); |
|
| 20 | + return get_option(self::API_FIELD_NAME, false); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function get_videos_data( $videos ) { |
|
| 23 | + public function get_videos_data($videos) { |
|
| 24 | 24 | |
| 25 | 25 | $key = $this->get_api_key(); |
| 26 | 26 | |
| 27 | - if ( ! $key ) { |
|
| 27 | + if ( ! $key) { |
|
| 28 | 28 | return array(); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | - $urls = array_map( function ( $video ) { |
|
| 31 | + $urls = array_map(function($video) { |
|
| 32 | 32 | return $video->get_url(); |
| 33 | - }, $videos ); |
|
| 33 | + }, $videos); |
|
| 34 | 34 | |
| 35 | 35 | |
| 36 | - $response_body = $this->api_client->get_data( $urls ); |
|
| 36 | + $response_body = $this->api_client->get_data($urls); |
|
| 37 | 37 | |
| 38 | - if ( ! is_string( $response_body ) || ! $response_body ) { |
|
| 38 | + if ( ! is_string($response_body) || ! $response_body) { |
|
| 39 | 39 | return array(); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - $response = json_decode( $response_body, true ); |
|
| 42 | + $response = json_decode($response_body, true); |
|
| 43 | 43 | |
| 44 | 44 | $video_list = $response['data']; |
| 45 | 45 | |
| 46 | 46 | |
| 47 | - if ( ! is_array( $video_list ) ) { |
|
| 47 | + if ( ! is_array($video_list)) { |
|
| 48 | 48 | // Return if we cant parse the response. |
| 49 | 49 | return array(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
| 53 | - return array_filter( array_map( array( $this, 'get_video_from_video_data' ), $video_list ) ); |
|
| 53 | + return array_filter(array_map(array($this, 'get_video_from_video_data'), $video_list)); |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - public function get_video_from_video_data( $vimeo_video_data ) { |
|
| 57 | + public function get_video_from_video_data($vimeo_video_data) { |
|
| 58 | 58 | |
| 59 | - if ( ! $vimeo_video_data ) { |
|
| 59 | + if ( ! $vimeo_video_data) { |
|
| 60 | 60 | // If valid data not supplied dont init the object. |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -65,41 +65,41 @@ discard block |
||
| 65 | 65 | $video->description = $vimeo_video_data['description']; |
| 66 | 66 | |
| 67 | 67 | $video->content_url = $vimeo_video_data['link']; |
| 68 | - $video->embed_url = "https://player.vimeo.com/video/" . $this->get_id( $vimeo_video_data ); |
|
| 69 | - if ( is_numeric( $vimeo_video_data['duration'] ) ) { |
|
| 70 | - $video->duration = "PT" . $vimeo_video_data['duration'] . "S"; |
|
| 68 | + $video->embed_url = "https://player.vimeo.com/video/".$this->get_id($vimeo_video_data); |
|
| 69 | + if (is_numeric($vimeo_video_data['duration'])) { |
|
| 70 | + $video->duration = "PT".$vimeo_video_data['duration']."S"; |
|
| 71 | 71 | } |
| 72 | 72 | $video->upload_date = $vimeo_video_data['release_time']; |
| 73 | - $video->thumbnail_urls = $this->set_thumbnail_urls( $vimeo_video_data ); |
|
| 73 | + $video->thumbnail_urls = $this->set_thumbnail_urls($vimeo_video_data); |
|
| 74 | 74 | $video->id = $video->content_url; |
| 75 | 75 | |
| 76 | - if ( array_key_exists( 'stats', $vimeo_video_data ) |
|
| 77 | - && array_key_exists( 'plays', $vimeo_video_data['stats'] ) ) { |
|
| 76 | + if (array_key_exists('stats', $vimeo_video_data) |
|
| 77 | + && array_key_exists('plays', $vimeo_video_data['stats'])) { |
|
| 78 | 78 | $video->views = (int) $vimeo_video_data['stats']['plays']; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | return $video; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - private function get_id( $api_response_data ) { |
|
| 85 | - return str_replace( "/videos/", "", $api_response_data['uri'] ); |
|
| 84 | + private function get_id($api_response_data) { |
|
| 85 | + return str_replace("/videos/", "", $api_response_data['uri']); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
| 89 | - private function set_thumbnail_urls( $api_response_data ) { |
|
| 89 | + private function set_thumbnail_urls($api_response_data) { |
|
| 90 | 90 | |
| 91 | - if ( ! array_key_exists( 'pictures', $api_response_data ) || ! array_key_exists( 'sizes', |
|
| 92 | - $api_response_data['pictures'] ) ) { |
|
| 91 | + if ( ! array_key_exists('pictures', $api_response_data) || ! array_key_exists('sizes', |
|
| 92 | + $api_response_data['pictures'])) { |
|
| 93 | 93 | return array(); |
| 94 | 94 | } |
| 95 | - if ( ! is_array( $api_response_data['pictures']['sizes'] ) ) { |
|
| 95 | + if ( ! is_array($api_response_data['pictures']['sizes'])) { |
|
| 96 | 96 | return array(); |
| 97 | 97 | } |
| 98 | 98 | $pictures = $api_response_data['pictures']['sizes']; |
| 99 | 99 | |
| 100 | - return array_map( function ( $picture_data ) { |
|
| 100 | + return array_map(function($picture_data) { |
|
| 101 | 101 | return $picture_data['link']; |
| 102 | - }, $pictures ); |
|
| 102 | + }, $pictures); |
|
| 103 | 103 | |
| 104 | 104 | } |
| 105 | 105 | |
@@ -12,130 +12,130 @@ |
||
| 12 | 12 | class Youtube extends Api_Provider { |
| 13 | 13 | |
| 14 | 14 | |
| 15 | - const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key'; |
|
| 16 | - |
|
| 17 | - private static function get_thumbnails( $api_thumbnail_data ) { |
|
| 18 | - return array_map( function ( $item ) { |
|
| 19 | - return $item['url']; |
|
| 20 | - |
|
| 21 | - }, $api_thumbnail_data ); |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - public function get_videos_data( $videos ) { |
|
| 26 | - $urls = array_map( function ( $video ) { |
|
| 27 | - /** |
|
| 28 | - * @param $video Video |
|
| 29 | - */ |
|
| 30 | - return $video->get_url(); |
|
| 31 | - }, $videos ); |
|
| 32 | - |
|
| 33 | - return $this->get_data( $urls ); |
|
| 34 | - |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @param $video_urls |
|
| 40 | - * |
|
| 41 | - * @return bool | array<Video> |
|
| 42 | - */ |
|
| 43 | - public function get_data( $video_urls ) { |
|
| 44 | - // extract ids from the url list. |
|
| 45 | - if ( ! is_array( $video_urls ) ) { |
|
| 46 | - return array(); |
|
| 47 | - } |
|
| 48 | - $response_body = $this->api_client->get_data( $video_urls ); |
|
| 49 | - |
|
| 50 | - return $this->parse_youtube_video_data_from_response( $response_body ); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @param $response_body string |
|
| 56 | - * |
|
| 57 | - * @return array<Video> |
|
| 58 | - */ |
|
| 59 | - private function parse_youtube_video_data_from_response( $response_body ) { |
|
| 60 | - $result = json_decode( $response_body, true ); |
|
| 61 | - if ( ! is_array( $result ) ) { |
|
| 62 | - // Return empty array since the response body is invalid. |
|
| 63 | - return array(); |
|
| 64 | - } |
|
| 65 | - if ( ! array_key_exists( 'items', $result ) ) { |
|
| 66 | - return array(); |
|
| 67 | - } |
|
| 68 | - $videos_json_data = $result['items']; |
|
| 69 | - $videos = array(); |
|
| 70 | - foreach ( $videos_json_data as $single_video_json_data ) { |
|
| 71 | - $videos[] = self::create_video_from_youtube_data( $single_video_json_data ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - return $videos; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - public static function create_video_from_youtube_data( $video_data ) { |
|
| 78 | - |
|
| 79 | - $video = new Video(); |
|
| 80 | - if ( array_key_exists( 'contentDetails', $video_data ) ) { |
|
| 81 | - $video->duration = $video_data['contentDetails']['duration']; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if ( array_key_exists( 'id', $video_data ) ) { |
|
| 85 | - $video_id = $video_data['id']; |
|
| 86 | - $video->embed_url = "https://www.youtube.com/embed/${video_id}"; |
|
| 87 | - $video->content_url = "https://www.youtube.com/watch?v=${video_id}"; |
|
| 88 | - } |
|
| 89 | - if ( ! array_key_exists( 'snippet', $video_data ) ) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $video->name = $video_data['snippet']['title']; |
|
| 94 | - $video->description = $video_data['snippet']['description']; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @since 3.30.0 |
|
| 98 | - * Use title as fallback if description is not present. |
|
| 99 | - */ |
|
| 100 | - if ( ! $video->description ) { |
|
| 101 | - $video->description = $video->name; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $video->upload_date = $video_data['snippet']['publishedAt']; |
|
| 105 | - |
|
| 106 | - if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) { |
|
| 107 | - $api_thumbnail_data = array_values( $video_data['snippet']['thumbnails'] ); |
|
| 108 | - $video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if ( array_key_exists( 'statistics', $video_data ) |
|
| 112 | - && array_key_exists( 'viewCount', $video_data['statistics'] ) ) { |
|
| 113 | - $video->views = $video_data['statistics']['viewCount']; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - if ( array_key_exists( 'liveStreamingDetails', $video_data ) && |
|
| 117 | - array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) { |
|
| 118 | - $video->is_live_video = true; |
|
| 119 | - $video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime']; |
|
| 120 | - try { |
|
| 121 | - $end_date = new \DateTime( $video->live_video_start_date ); |
|
| 122 | - /** |
|
| 123 | - * the google doc says : |
|
| 124 | - * It is required to provide the endDate once the video has finished and is no longer live. |
|
| 125 | - * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate. |
|
| 126 | - */ |
|
| 127 | - // we add 1 day to start date |
|
| 128 | - $end_date->add( new DateInterval( 'P1D' ) ); |
|
| 129 | - $video->live_video_end_date = $end_date->format( 'c' ); |
|
| 130 | - } catch ( \Exception $e ) { |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $video->id = $video->content_url; |
|
| 135 | - |
|
| 136 | - return $video; |
|
| 137 | - |
|
| 138 | - } |
|
| 15 | + const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key'; |
|
| 16 | + |
|
| 17 | + private static function get_thumbnails( $api_thumbnail_data ) { |
|
| 18 | + return array_map( function ( $item ) { |
|
| 19 | + return $item['url']; |
|
| 20 | + |
|
| 21 | + }, $api_thumbnail_data ); |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + public function get_videos_data( $videos ) { |
|
| 26 | + $urls = array_map( function ( $video ) { |
|
| 27 | + /** |
|
| 28 | + * @param $video Video |
|
| 29 | + */ |
|
| 30 | + return $video->get_url(); |
|
| 31 | + }, $videos ); |
|
| 32 | + |
|
| 33 | + return $this->get_data( $urls ); |
|
| 34 | + |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @param $video_urls |
|
| 40 | + * |
|
| 41 | + * @return bool | array<Video> |
|
| 42 | + */ |
|
| 43 | + public function get_data( $video_urls ) { |
|
| 44 | + // extract ids from the url list. |
|
| 45 | + if ( ! is_array( $video_urls ) ) { |
|
| 46 | + return array(); |
|
| 47 | + } |
|
| 48 | + $response_body = $this->api_client->get_data( $video_urls ); |
|
| 49 | + |
|
| 50 | + return $this->parse_youtube_video_data_from_response( $response_body ); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * @param $response_body string |
|
| 56 | + * |
|
| 57 | + * @return array<Video> |
|
| 58 | + */ |
|
| 59 | + private function parse_youtube_video_data_from_response( $response_body ) { |
|
| 60 | + $result = json_decode( $response_body, true ); |
|
| 61 | + if ( ! is_array( $result ) ) { |
|
| 62 | + // Return empty array since the response body is invalid. |
|
| 63 | + return array(); |
|
| 64 | + } |
|
| 65 | + if ( ! array_key_exists( 'items', $result ) ) { |
|
| 66 | + return array(); |
|
| 67 | + } |
|
| 68 | + $videos_json_data = $result['items']; |
|
| 69 | + $videos = array(); |
|
| 70 | + foreach ( $videos_json_data as $single_video_json_data ) { |
|
| 71 | + $videos[] = self::create_video_from_youtube_data( $single_video_json_data ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + return $videos; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + public static function create_video_from_youtube_data( $video_data ) { |
|
| 78 | + |
|
| 79 | + $video = new Video(); |
|
| 80 | + if ( array_key_exists( 'contentDetails', $video_data ) ) { |
|
| 81 | + $video->duration = $video_data['contentDetails']['duration']; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if ( array_key_exists( 'id', $video_data ) ) { |
|
| 85 | + $video_id = $video_data['id']; |
|
| 86 | + $video->embed_url = "https://www.youtube.com/embed/${video_id}"; |
|
| 87 | + $video->content_url = "https://www.youtube.com/watch?v=${video_id}"; |
|
| 88 | + } |
|
| 89 | + if ( ! array_key_exists( 'snippet', $video_data ) ) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $video->name = $video_data['snippet']['title']; |
|
| 94 | + $video->description = $video_data['snippet']['description']; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @since 3.30.0 |
|
| 98 | + * Use title as fallback if description is not present. |
|
| 99 | + */ |
|
| 100 | + if ( ! $video->description ) { |
|
| 101 | + $video->description = $video->name; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $video->upload_date = $video_data['snippet']['publishedAt']; |
|
| 105 | + |
|
| 106 | + if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) { |
|
| 107 | + $api_thumbnail_data = array_values( $video_data['snippet']['thumbnails'] ); |
|
| 108 | + $video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if ( array_key_exists( 'statistics', $video_data ) |
|
| 112 | + && array_key_exists( 'viewCount', $video_data['statistics'] ) ) { |
|
| 113 | + $video->views = $video_data['statistics']['viewCount']; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + if ( array_key_exists( 'liveStreamingDetails', $video_data ) && |
|
| 117 | + array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) { |
|
| 118 | + $video->is_live_video = true; |
|
| 119 | + $video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime']; |
|
| 120 | + try { |
|
| 121 | + $end_date = new \DateTime( $video->live_video_start_date ); |
|
| 122 | + /** |
|
| 123 | + * the google doc says : |
|
| 124 | + * It is required to provide the endDate once the video has finished and is no longer live. |
|
| 125 | + * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate. |
|
| 126 | + */ |
|
| 127 | + // we add 1 day to start date |
|
| 128 | + $end_date->add( new DateInterval( 'P1D' ) ); |
|
| 129 | + $video->live_video_end_date = $end_date->format( 'c' ); |
|
| 130 | + } catch ( \Exception $e ) { |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $video->id = $video->content_url; |
|
| 135 | + |
|
| 136 | + return $video; |
|
| 137 | + |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | } |
| 142 | 142 | \ No newline at end of file |
@@ -14,23 +14,23 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | const YT_API_FIELD_NAME = '__wl_video_object_youtube_api_key'; |
| 16 | 16 | |
| 17 | - private static function get_thumbnails( $api_thumbnail_data ) { |
|
| 18 | - return array_map( function ( $item ) { |
|
| 17 | + private static function get_thumbnails($api_thumbnail_data) { |
|
| 18 | + return array_map(function($item) { |
|
| 19 | 19 | return $item['url']; |
| 20 | 20 | |
| 21 | - }, $api_thumbnail_data ); |
|
| 21 | + }, $api_thumbnail_data); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - public function get_videos_data( $videos ) { |
|
| 26 | - $urls = array_map( function ( $video ) { |
|
| 25 | + public function get_videos_data($videos) { |
|
| 26 | + $urls = array_map(function($video) { |
|
| 27 | 27 | /** |
| 28 | 28 | * @param $video Video |
| 29 | 29 | */ |
| 30 | 30 | return $video->get_url(); |
| 31 | - }, $videos ); |
|
| 31 | + }, $videos); |
|
| 32 | 32 | |
| 33 | - return $this->get_data( $urls ); |
|
| 33 | + return $this->get_data($urls); |
|
| 34 | 34 | |
| 35 | 35 | } |
| 36 | 36 | |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @return bool | array<Video> |
| 42 | 42 | */ |
| 43 | - public function get_data( $video_urls ) { |
|
| 43 | + public function get_data($video_urls) { |
|
| 44 | 44 | // extract ids from the url list. |
| 45 | - if ( ! is_array( $video_urls ) ) { |
|
| 45 | + if ( ! is_array($video_urls)) { |
|
| 46 | 46 | return array(); |
| 47 | 47 | } |
| 48 | - $response_body = $this->api_client->get_data( $video_urls ); |
|
| 48 | + $response_body = $this->api_client->get_data($video_urls); |
|
| 49 | 49 | |
| 50 | - return $this->parse_youtube_video_data_from_response( $response_body ); |
|
| 50 | + return $this->parse_youtube_video_data_from_response($response_body); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -56,37 +56,37 @@ discard block |
||
| 56 | 56 | * |
| 57 | 57 | * @return array<Video> |
| 58 | 58 | */ |
| 59 | - private function parse_youtube_video_data_from_response( $response_body ) { |
|
| 60 | - $result = json_decode( $response_body, true ); |
|
| 61 | - if ( ! is_array( $result ) ) { |
|
| 59 | + private function parse_youtube_video_data_from_response($response_body) { |
|
| 60 | + $result = json_decode($response_body, true); |
|
| 61 | + if ( ! is_array($result)) { |
|
| 62 | 62 | // Return empty array since the response body is invalid. |
| 63 | 63 | return array(); |
| 64 | 64 | } |
| 65 | - if ( ! array_key_exists( 'items', $result ) ) { |
|
| 65 | + if ( ! array_key_exists('items', $result)) { |
|
| 66 | 66 | return array(); |
| 67 | 67 | } |
| 68 | 68 | $videos_json_data = $result['items']; |
| 69 | 69 | $videos = array(); |
| 70 | - foreach ( $videos_json_data as $single_video_json_data ) { |
|
| 71 | - $videos[] = self::create_video_from_youtube_data( $single_video_json_data ); |
|
| 70 | + foreach ($videos_json_data as $single_video_json_data) { |
|
| 71 | + $videos[] = self::create_video_from_youtube_data($single_video_json_data); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return $videos; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public static function create_video_from_youtube_data( $video_data ) { |
|
| 77 | + public static function create_video_from_youtube_data($video_data) { |
|
| 78 | 78 | |
| 79 | 79 | $video = new Video(); |
| 80 | - if ( array_key_exists( 'contentDetails', $video_data ) ) { |
|
| 80 | + if (array_key_exists('contentDetails', $video_data)) { |
|
| 81 | 81 | $video->duration = $video_data['contentDetails']['duration']; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - if ( array_key_exists( 'id', $video_data ) ) { |
|
| 84 | + if (array_key_exists('id', $video_data)) { |
|
| 85 | 85 | $video_id = $video_data['id']; |
| 86 | 86 | $video->embed_url = "https://www.youtube.com/embed/${video_id}"; |
| 87 | 87 | $video->content_url = "https://www.youtube.com/watch?v=${video_id}"; |
| 88 | 88 | } |
| 89 | - if ( ! array_key_exists( 'snippet', $video_data ) ) { |
|
| 89 | + if ( ! array_key_exists('snippet', $video_data)) { |
|
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
@@ -97,37 +97,37 @@ discard block |
||
| 97 | 97 | * @since 3.30.0 |
| 98 | 98 | * Use title as fallback if description is not present. |
| 99 | 99 | */ |
| 100 | - if ( ! $video->description ) { |
|
| 100 | + if ( ! $video->description) { |
|
| 101 | 101 | $video->description = $video->name; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $video->upload_date = $video_data['snippet']['publishedAt']; |
| 105 | 105 | |
| 106 | - if ( array_key_exists( 'thumbnails', $video_data['snippet'] ) ) { |
|
| 107 | - $api_thumbnail_data = array_values( $video_data['snippet']['thumbnails'] ); |
|
| 108 | - $video->thumbnail_urls = self::get_thumbnails( $api_thumbnail_data ); |
|
| 106 | + if (array_key_exists('thumbnails', $video_data['snippet'])) { |
|
| 107 | + $api_thumbnail_data = array_values($video_data['snippet']['thumbnails']); |
|
| 108 | + $video->thumbnail_urls = self::get_thumbnails($api_thumbnail_data); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if ( array_key_exists( 'statistics', $video_data ) |
|
| 112 | - && array_key_exists( 'viewCount', $video_data['statistics'] ) ) { |
|
| 111 | + if (array_key_exists('statistics', $video_data) |
|
| 112 | + && array_key_exists('viewCount', $video_data['statistics'])) { |
|
| 113 | 113 | $video->views = $video_data['statistics']['viewCount']; |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - if ( array_key_exists( 'liveStreamingDetails', $video_data ) && |
|
| 117 | - array_key_exists( 'scheduledStartTime', $video_data['liveStreamingDetails'] ) ) { |
|
| 116 | + if (array_key_exists('liveStreamingDetails', $video_data) && |
|
| 117 | + array_key_exists('scheduledStartTime', $video_data['liveStreamingDetails'])) { |
|
| 118 | 118 | $video->is_live_video = true; |
| 119 | 119 | $video->live_video_start_date = $video_data['liveStreamingDetails']['scheduledStartTime']; |
| 120 | 120 | try { |
| 121 | - $end_date = new \DateTime( $video->live_video_start_date ); |
|
| 121 | + $end_date = new \DateTime($video->live_video_start_date); |
|
| 122 | 122 | /** |
| 123 | 123 | * the google doc says : |
| 124 | 124 | * It is required to provide the endDate once the video has finished and is no longer live. |
| 125 | 125 | * If the expected endDate is unknown prior to the livestream starting, we recommend providing an approximate endDate. |
| 126 | 126 | */ |
| 127 | 127 | // we add 1 day to start date |
| 128 | - $end_date->add( new DateInterval( 'P1D' ) ); |
|
| 129 | - $video->live_video_end_date = $end_date->format( 'c' ); |
|
| 130 | - } catch ( \Exception $e ) { |
|
| 128 | + $end_date->add(new DateInterval('P1D')); |
|
| 129 | + $video->live_video_end_date = $end_date->format('c'); |
|
| 130 | + } catch (\Exception $e) { |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
@@ -10,10 +10,10 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | interface Provider { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @param $videos array<Embedded_Video> |
|
| 15 | - * @return array<Video> |
|
| 16 | - */ |
|
| 17 | - public function get_videos_data( $videos ); |
|
| 13 | + /** |
|
| 14 | + * @param $videos array<Embedded_Video> |
|
| 15 | + * @return array<Video> |
|
| 16 | + */ |
|
| 17 | + public function get_videos_data( $videos ); |
|
| 18 | 18 | |
| 19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
| 14 | 14 | * @param $videos array<Embedded_Video> |
| 15 | 15 | * @return array<Video> |
| 16 | 16 | */ |
| 17 | - public function get_videos_data( $videos ); |
|
| 17 | + public function get_videos_data($videos); |
|
| 18 | 18 | |
| 19 | 19 | } |