| @@ -100,8 +100,12 @@ | ||
| 100 | 100 | |
| 101 | 101 | // Get playlist id from the channel |
| 102 | 102 | $playlist_id = $this->get_playlist_id( $params ); |
| 103 | 103 | |
| 104 | + if ( is_object( $playlist_id ) && isset( $playlist_id->error ) ) { | |
| 105 | + return $playlist_id; | |
| 106 | + } | |
| 107 | + | |
| 104 | 108 | if ( empty( $playlist_id ) ) { |
| 105 | 109 | return $this->get_error( __( 'No videos found matching your query.', 'automatic-youtube-gallery' ) ); |
| 106 | 110 | } |
| 107 | 111 | |
| @@ -118,8 +122,12 @@ | ||
| 118 | 122 | // Get playlist id from the channel |
| 119 | 123 | $params['forUsername'] = $this->parse_youtube_id_from_url( $params['src'], 'username' ); |
| 120 | 124 | $playlist_id = $this->get_playlist_id( $params ); |
| 121 | 125 | |
| 126 | + if ( is_object( $playlist_id ) && isset( $playlist_id->error ) ) { | |
| 127 | + return $playlist_id; | |
| 128 | + } | |
| 129 | + | |
| 122 | 130 | if ( empty( $playlist_id ) ) { |
| 123 | 131 | return $this->get_error( __( 'No videos found matching your query.', 'automatic-youtube-gallery' ) ); |
| 124 | 132 | } |
| 125 | 133 | |
| @@ -148,14 +156,16 @@ | ||
| 148 | 156 | if ( empty( $params['src'] ) ) { |
| 149 | 157 | return $this->get_error( __( 'YouTube Channel ID (or) or a YouTube Video URL from the Channel is required.', 'automatic-youtube-gallery' ) ); |
| 150 | 158 | } |
| 151 | 159 | |
| 152 | - $response = new stdClass(); | |
| 153 | - $response->id = $this->get_channel_id( $params ); | |
| 160 | + $params['channelId'] = $this->get_channel_id( $params ); | |
| 154 | 161 | |
| 155 | - if ( empty( $response->id ) ) { | |
| 162 | + if ( empty( $params['channelId'] ) ) { | |
| 156 | 163 | return $this->get_error( __( 'Invalid YouTube Channel ID.', 'automatic-youtube-gallery' ) ); |
| 157 | 164 | } |
| 165 | + | |
| 166 | + // Get live video using the channel id | |
| 167 | + $response = $this->request_api_live_video( $params ); | |
| 158 | 168 | break; |
| 159 | 169 | |
| 160 | 170 | default: // video |
| 161 | 171 | if ( empty( $params['src'] ) ) { |
| @@ -461,8 +471,50 @@ | ||
| 461 | 471 | $response->videos = $videos; |
| 462 | 472 | |
| 463 | 473 | return $response; |
| 464 | 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 | + } | |
| 465 | 517 | |
| 466 | 518 | /** |
| 467 | 519 | * Get details of the given video ID. |
| 468 | 520 | * |