Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/services/Embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
// =========================================================================
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
}
}
}
2 changes: 1 addition & 1 deletion src/templates/embeds/youtube-live-chat.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
}
</style>
<div class="youtube-chat-resp-container">
<iframe class="youtube-chat-resp-iframe" src="{{ iframeUrl }}&embed_domain={{ embedDomain }}"
<iframe class="youtube-chat-resp-iframe" src="{{ iframeUrl }}"
allow="autoplay; fullscreen; encrypted-media"></iframe>
</div>