Move YouTube oembed hack to oembed parser

This commit is contained in:
Alex Gleason 2021-02-23 09:48:04 -06:00
parent d2d9080d4c
commit 36a5ff7803
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 7 additions and 7 deletions

View file

@ -78,13 +78,6 @@ 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"}]

View file

@ -21,6 +21,13 @@ defmodule Pleroma.Web.RichMedia.Parsers.OEmbed 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)