Video: Handle peertube videos only stashing attachments in x-mpegURL
[akkoma] / lib / pleroma / web / activity_pub / object_validators / audio_video_validator.ex
index b3e738d8d84eafa461f1124e543085b393553814..4a96fef529899be4e80ac8c606df1b2dcbe15488 100644 (file)
@@ -70,19 +70,33 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioVideoValidator do
     |> changeset(data)
   end
 
-  defp fix_url(%{"url" => url} = data) when is_list(url) do
-    attachment =
-      Enum.find(url, fn x ->
-        mime_type = x["mimeType"] || x["mediaType"] || ""
-
-        is_map(x) and String.starts_with?(mime_type, ["video/", "audio/"])
+  defp find_attachment(url) do
+    mpeg_url =
+      Enum.find(url, fn
+        %{"mediaType" => mime_type, "tag" => tags} when is_list(tags) ->
+          mime_type == "application/x-mpegURL"
+
+        _ ->
+          false
       end)
 
-    link_element =
-      Enum.find(url, fn x ->
-        mime_type = x["mimeType"] || x["mediaType"] || ""
+    url
+    |> Enum.concat(mpeg_url["tag"] || [])
+    |> Enum.find(fn
+      %{"mediaType" => mime_type} -> String.starts_with?(mime_type, ["video/", "audio/"])
+      %{"mimeType" => mime_type} -> String.starts_with?(mime_type, ["video/", "audio/"])
+      _ -> false
+    end)
+  end
 
-        is_map(x) and mime_type == "text/html"
+  defp fix_url(%{"url" => url} = data) when is_list(url) do
+    attachment = find_attachment(url)
+
+    link_element =
+      Enum.find(url, fn
+        %{"mediaType" => "text/html"} -> true
+        %{"mimeType" => "text/html"} -> true
+        _ -> false
       end)
 
     data