Skip to content

Commit

Permalink
feat(reddit): support video (#4380)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Jan 2, 2025
1 parent 152e96d commit 7d544f1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions bridges/RedditBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,14 @@ private function collectDataInternal(): void
} elseif ($data->is_video) {
// Video

// Higher index -> Higher resolution
end($data->preview->images[0]->resolutions);
$index = key($data->preview->images[0]->resolutions);

$item['content'] = $this->createFigureLink($data->url, $data->preview->images[0]->resolutions[$index]->url, 'Video');
if ($data->media->reddit_video) {
$item['content'] = $this->createVideoContent($data->media->reddit_video);
} else {
// Higher index -> Higher resolution
end($data->preview->images[0]->resolutions);
$index = key($data->preview->images[0]->resolutions);
$item['content'] = $this->createFigureLink($data->url, $data->preview->images[0]->resolutions[$index]->url, 'Video');
}
} elseif (isset($data->media) && $data->media->type == 'youtube.com') {
// Youtube link
$item['content'] = $this->createFigureLink($data->url, $data->media->oembed->thumbnail_url, 'YouTube');
Expand Down Expand Up @@ -318,6 +321,16 @@ private function createLink($href, $text)
return sprintf('<a href="%s">%s</a>', $href, $text);
}

private function createVideoContent(\stdClass $video): string
{
return <<<HTML
<video width="$video->width" height="$video->height" controls>
<source src="$video->fallback_url" type="video/mp4">
Your browser does not support the video tag.
</video>
HTML;
}

public function detectParameters($url)
{
try {
Expand Down

0 comments on commit 7d544f1

Please sign in to comment.