From 1b2c7d6f5a82e14b48d6db4a5368ca8fcc7d43ce Mon Sep 17 00:00:00 2001 From: zafer Date: Wed, 6 Mar 2024 19:51:58 +0300 Subject: [PATCH] add thumbnail_url to video --- lib/algora/library/video.ex | 1 + ...40306163651_add_thumbnail_url_to_video.exs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 priv/repo/migrations/20240306163651_add_thumbnail_url_to_video.exs diff --git a/lib/algora/library/video.ex b/lib/algora/library/video.ex index 90f143c..0a4457a 100644 --- a/lib/algora/library/video.ex +++ b/lib/algora/library/video.ex @@ -13,6 +13,7 @@ defmodule Algora.Library.Video do 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 field :uuid, :string diff --git a/priv/repo/migrations/20240306163651_add_thumbnail_url_to_video.exs b/priv/repo/migrations/20240306163651_add_thumbnail_url_to_video.exs new file mode 100644 index 0000000..1b527eb --- /dev/null +++ b/priv/repo/migrations/20240306163651_add_thumbnail_url_to_video.exs @@ -0,0 +1,19 @@ +defmodule Algora.Repo.Migrations.AddThumbnailUrlToVideo do + use Ecto.Migration + + def up do + alter table("videos") do + add :thumbnail_url, :string + end + + execute "update videos set thumbnail_url = format('%s/index.jpeg', url_root) where url_root is not null and thumbnails_ready = 't'" + + execute "update videos set thumbnail_url = format('https://i.ytimg.com/vi/%s/hqdefault.jpg', substr(url,29)) where url like 'https://youtube.com/watch?v=%'" + end + + def down do + alter table("videos") do + remove :thumbnail_url, :string + end + end +end