From 36a5ff78031a0e197206819cfcc22273fd76c351 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Feb 2021 09:48:04 -0600 Subject: Move YouTube oembed hack to oembed parser --- lib/pleroma/web/rich_media/helpers.ex | 7 ------- lib/pleroma/web/rich_media/parsers/o_embed.ex | 7 +++++++ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 4d1c2dc9a..566fc8c8a 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -78,13 +78,6 @@ def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) d def fetch_data_for_activity(_), do: %{} - # YouTube's oEmbed implementation is broken, requiring this hack. - # https://github.com/oscarotero/Embed/issues/417#issuecomment-746673027 - def rich_media_get("http://www.youtube.com/oembed?" <> params) do - # Use HTTPS explicitly, even though YouTube returns HTTP - rich_media_get("https://www.youtube.com/oembed?#{params}") - end - def rich_media_get(url) do headers = [{"user-agent", Pleroma.Application.user_agent() <> "; Bot"}] diff --git a/lib/pleroma/web/rich_media/parsers/o_embed.ex b/lib/pleroma/web/rich_media/parsers/o_embed.ex index 09eabec56..24fca56bb 100644 --- a/lib/pleroma/web/rich_media/parsers/o_embed.ex +++ b/lib/pleroma/web/rich_media/parsers/o_embed.ex @@ -21,6 +21,13 @@ defp get_oembed_url([{"link", attributes, _children} | _]) do Enum.find_value(attributes, fn {k, v} -> if k == "href", do: v end) end + # YouTube's oEmbed implementation is broken, requiring this hack. + # https://github.com/oscarotero/Embed/issues/417#issuecomment-746673027 + defp get_oembed_data("http://www.youtube.com/oembed?" <> params) do + # Use HTTPS explicitly, even though YouTube returns HTTP + get_oembed_data("https://www.youtube.com/oembed?#{params}") + end + defp get_oembed_data(url) do with {:ok, %Tesla.Env{body: json}} <- Pleroma.Web.RichMedia.Helpers.rich_media_get(url) do Jason.decode(json) -- cgit v1.2.3