1
0
mirror of https://github.com/algora-io/tv.git synced 2025-01-05 01:20:24 +02:00

remove thumbnails_ready from video

This commit is contained in:
zafer 2024-03-06 20:01:29 +03:00
parent 1b2c7d6f5a
commit 0abb697a1f
6 changed files with 19 additions and 14 deletions

View File

@ -259,13 +259,6 @@ defmodule Algora.Library do
end
end
def thumbnail_url(%Video{} = video) do
case youtube_id(video) do
:not_found -> video.url_root <> "/index.jpeg"
id -> "https://i.ytimg.com/vi/#{id}/hqdefault.jpg"
end
end
def player_type(%Video{type: :livestream}), do: "application/x-mpegURL"
def player_type(%Video{} = video) do

View File

@ -12,7 +12,6 @@ defmodule Algora.Library.Video do
field :title, :string
field :type, Ecto.Enum, values: [vod: 1, livestream: 2]
field :is_live, :boolean, default: false
field :thumbnails_ready, :boolean, default: false
field :thumbnail_url, :string
field :url, :string
field :url_root, :string

View File

@ -65,10 +65,14 @@ defmodule Algora.Storage do
contents,
_metadata,
%{type: :segment, mode: :binary},
%{video: %{thumbnails_ready: false} = video, video_header: video_header} = state
%{video: %{thumbnail_url: nil} = video, video_header: video_header} = state
) do
with :ok <- Library.store_thumbnail(video, video_header <> contents),
{:ok, video} = video |> change() |> put_change(:thumbnails_ready, true) |> Repo.update(),
{:ok, video} =
video
|> change()
|> put_change(:thumbnail_url, "#{video.url_root}/index.jpeg")
|> Repo.update(),
:ok <- broadcast_thumbnails_generated(video) do
{:ok, %{state | video: video}}
end

View File

@ -87,10 +87,10 @@ defmodule AlgoraWeb.CoreComponents do
}
>
<div class="relative flex items-center justify-center overflow-hidden rounded-2xl aspect-[16/9] bg-gray-800">
<Heroicons.play :if={!@video.thumbnails_ready} solid class="h-12 w-12 text-gray-500" />
<Heroicons.play :if={!@video.thumbnail_url} solid class="h-12 w-12 text-gray-500" />
<img
:if={@video.thumbnails_ready}
src={Library.thumbnail_url(@video)}
:if={@video.thumbnail_url}
src={@video.thumbnail_url}
alt={@video.title}
class="absolute w-full h-full object-cover transition-transform duration-200 scale-105 hover:scale-110 z-10"
/>

View File

@ -13,7 +13,7 @@ defmodule Algora.Repo.Migrations.AddThumbnailUrlToVideo do
def down do
alter table("videos") do
remove :thumbnail_url, :string
remove :thumbnail_url
end
end
end

View File

@ -0,0 +1,9 @@
defmodule Algora.Repo.Migrations.RemoveThumbnailsReadyFromVideo do
use Ecto.Migration
def change do
alter table("videos") do
remove :thumbnails_ready
end
end
end