diff --git a/src/services/Embed.php b/src/services/Embed.php index be90c2b..adfe1a4 100644 --- a/src/services/Embed.php +++ b/src/services/Embed.php @@ -32,6 +32,7 @@ class Embed extends Component public const YOUTUBE_STREAM_URL = 'https://www.youtube.com/embed/live_stream'; public const YOUTUBE_CHAT_URL = 'https://www.youtube.com/live_chat'; + public const YOUTUBE_CHANNEL_URL='https://www.youtube.com/channel'; // Public Methods // ========================================================================= @@ -138,6 +139,16 @@ public function isLive(): bool // Protected Methods // ========================================================================= + /** + * Returns the URL to the channel's live page (used to extract video ID) + * + * @return string + */ + protected function getYoutubeChannelLiveUrl(): string + { + return self::YOUTUBE_CHANNEL_URL . '/' . YoutubeLiveEmbed::$youtubeChannelId . '/live'; + } + /** * Returns the URL to the live video YouTube page * @@ -192,13 +203,13 @@ protected function getSiteDomain(): string protected function getVideoIdFromLiveStream(): ?string { $videoId = null; - $liveUrl = $this->getYoutubeStreamUrl(); + $liveUrl = $this->getYoutubeChannelLiveUrl(); // Fetch the livestream page // Find the video ID in there - if (($data = @file_get_contents($liveUrl)) && preg_match('/\"VIDEO_ID\":\"(.*?)\"/', $data, $matches)) { + if (($data = @file_get_contents($liveUrl)) && preg_match('/\"videoId\":\"(.*?)\"/', $data, $matches)) { $videoId = $matches[1]; } return $videoId; } -} +} \ No newline at end of file diff --git a/src/templates/embeds/youtube-live-chat.twig b/src/templates/embeds/youtube-live-chat.twig index c90c376..21477a2 100644 --- a/src/templates/embeds/youtube-live-chat.twig +++ b/src/templates/embeds/youtube-live-chat.twig @@ -29,6 +29,6 @@ }
-