| @@ -156,14 +156,16 @@ | ||
| 156 | 156 | if ( empty( $params['src'] ) ) { |
| 157 | 157 | return $this->get_error( __( 'YouTube Channel ID (or) or a YouTube Video URL from the Channel is required.', 'automatic-youtube-gallery' ) ); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - $response = new stdClass(); | |
| 161 | - $response->id = $this->get_channel_id( $params ); | |
| 160 | + $params['channelId'] = $this->get_channel_id( $params ); | |
| 162 | 161 | |
| 163 | - if ( empty( $response->id ) ) { | |
| 162 | + if ( empty( $params['channelId'] ) ) { | |
| 164 | 163 | return $this->get_error( __( 'Invalid YouTube Channel ID.', 'automatic-youtube-gallery' ) ); |
| 165 | 164 | } |
| 165 | + | |
| 166 | + // Get live video using the channel id | |
| 167 | + $response = $this->request_api_live_video( $params ); | |
| 166 | 168 | break; |
| 167 | 169 | |
| 168 | 170 | default: // video |
| 169 | 171 | if ( empty( $params['src'] ) ) { |
| @@ -469,8 +471,50 @@ | ||
| 469 | 471 | $response->videos = $videos; |
| 470 | 472 | |
| 471 | 473 | return $response; |
| 472 | 474 | } |
| 475 | + | |
| 476 | + /** | |
| 477 | + * Get live video using search API. | |
| 478 | + * | |
| 479 | + * @since 2.3.7 | |
| 480 | + * @access private | |
| 481 | + * @param array $params Array of query params. | |
| 482 | + * @return mixed | |
| 483 | + */ | |
| 484 | + private function request_api_live_video( $params = array() ) { | |
| 485 | + $api_url = $this->get_api_url( 'search.list' ); | |
| 486 | + | |
| 487 | + $params['type'] = 'video'; // Overrides user defined type value 'livestream' | |
| 488 | + | |
| 489 | + $api_params = $this->safe_merge_params( | |
| 490 | + array( | |
| 491 | + 'type' => 'video', | |
| 492 | + 'eventType' => 'live', | |
| 493 | + 'part' => 'snippet', | |
| 494 | + 'channelId' => '', | |
| 495 | + 'cache' => 0 | |
| 496 | + ), | |
| 497 | + $params | |
| 498 | + ); | |
| 499 | + | |
| 500 | + $api_response = $this->request_api( $api_url, $api_params ); | |
| 501 | + if ( isset( $api_response->error ) ) { | |
| 502 | + return $api_response; | |
| 503 | + } | |
| 504 | + | |
| 505 | + $videos = $this->parse_videos( $api_response ); | |
| 506 | + if ( isset( $videos->error ) ) { | |
| 507 | + $livestream_settings = get_option( 'ayg_livestream_settings' ); | |
| 508 | + return $this->get_error( '<div class="ayg-livestream-fallback-message">' . $livestream_settings['fallback_message'] . '</div>' ); | |
| 509 | + } | |
| 510 | + | |
| 511 | + // Process output | |
| 512 | + $response = new stdClass(); | |
| 513 | + $response->videos = $videos; | |
| 514 | + | |
| 515 | + return $response; | |
| 516 | + } | |
| 473 | 517 | |
| 474 | 518 | /** |
| 475 | 519 | * Get details of the given video ID. |
| 476 | 520 | * |