[Bugfix] Fix reddit bugs v2 (#82)

* Ensured thumbnail is converted to jpg before embedding

* Ensured media indexing doesn't fail if an upload date can't be parsed
This commit is contained in:
Kieran
2024-03-12 20:23:51 -07:00
committed by GitHub
parent abe99ce6f0
commit 1cc8731914
6 changed files with 61 additions and 4 deletions
@@ -141,6 +141,14 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
assert :embed_thumbnail in res
end
test "convertes thumbnail to jpg when embed_thumbnail is true", %{media_item: media_item} do
media_item = update_media_profile_attribute(media_item, %{embed_thumbnail: true})
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
assert {:convert_thumbnail, "jpg"} in res
end
test "doesn't include these options when not specified", %{media_item: media_item} do
media_item = update_media_profile_attribute(media_item, %{embed_thumbnail: false, download_thumbnail: false})
@@ -151,6 +151,30 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
assert [] = Tasks.list_tasks_for(:media_item_id, media_item.id)
end
test "it doesn't blow up if a media item cannot be coerced into a struct", %{source: source} do
stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot, _addl_opts ->
response =
Phoenix.json_library().encode!(%{
id: "video3",
title: "Video 3",
was_live: false,
description: "desc3",
# Only focusing on these because these are passed to functions that
# could fail if they're not present
webpage_url: nil,
aspect_ratio: nil,
duration: nil,
upload_date: nil
})
{:ok, response}
end)
assert [changeset] = SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
assert %Ecto.Changeset{} = changeset
end
end
describe "index_and_enqueue_download_for_media_items/1 when testing file watcher" do
+21
View File
@@ -141,6 +141,16 @@ defmodule Pinchflat.YtDlp.MediaTest do
assert %Media{short_form_content: false} = Media.response_to_struct(response)
end
test "doesn't blow up if short form content-related fields are missing" do
response = %{
"webpage_url" => nil,
"aspect_ratio" => nil,
"duration" => nil
}
assert %Media{short_form_content: nil} = Media.response_to_struct(response)
end
test "parses the upload date" do
response = %{
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
@@ -153,5 +163,16 @@ defmodule Pinchflat.YtDlp.MediaTest do
assert %Media{upload_date: ^expected_date} = Media.response_to_struct(response)
end
test "doesn't blow up if upload date is missing" do
response = %{
"webpage_url" => "https://www.youtube.com/watch?v=TiZPUDkDYbk",
"aspect_ratio" => 1.0,
"duration" => 61,
"upload_date" => nil
}
assert %Media{upload_date: nil} = Media.response_to_struct(response)
end
end
end