From d2d9080d4c9fdae5f22d81a064a08fe0084b1208 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 20 Feb 2021 15:35:36 -0600 Subject: [PATCH] Fix YouTube embeds by rewriting http to https --- lib/pleroma/web/rich_media/helpers.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/pleroma/web/rich_media/helpers.ex b/lib/pleroma/web/rich_media/helpers.ex index 566fc8c8a..4d1c2dc9a 100644 --- a/lib/pleroma/web/rich_media/helpers.ex +++ b/lib/pleroma/web/rich_media/helpers.ex @@ -78,6 +78,13 @@ defmodule Pleroma.Web.RichMedia.Helpers do 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"}]