[Bugfix]: Misc. bugfixes 2024-04-16 (#189)

* Manually installed mutagen

* Stopped upgrade form from submitting on enter

* Gracefully handle duplicate enqueued downloads

* Update metadata thumbnail fetcher to use the best jpg available
This commit is contained in:
Kieran
2024-04-16 17:37:39 -07:00
committed by GitHub
parent 4721957875
commit 618711691b
9 changed files with 60 additions and 20 deletions
+3 -9
View File
@@ -731,9 +731,7 @@ defmodule Pinchflat.MediaTest do
metadata: %{
metadata_filepath: MetadataFileHelpers.compress_and_store_metadata_for(media_item, %{}),
thumbnail_filepath:
MetadataFileHelpers.download_and_store_thumbnail_for(media_item, %{
"thumbnail" => "https://example.com/thumbnail.jpg"
})
MetadataFileHelpers.download_and_store_thumbnail_for(media_item, render_parsed_metadata(:media_metadata))
}
}
@@ -760,9 +758,7 @@ defmodule Pinchflat.MediaTest do
metadata: %{
metadata_filepath: MetadataFileHelpers.compress_and_store_metadata_for(media_item, %{}),
thumbnail_filepath:
MetadataFileHelpers.download_and_store_thumbnail_for(media_item, %{
"thumbnail" => "https://example.com/thumbnail.jpg"
})
MetadataFileHelpers.download_and_store_thumbnail_for(media_item, render_parsed_metadata(:media_metadata))
}
}
@@ -831,9 +827,7 @@ defmodule Pinchflat.MediaTest do
metadata: %{
metadata_filepath: MetadataFileHelpers.compress_and_store_metadata_for(media_item, %{}),
thumbnail_filepath:
MetadataFileHelpers.download_and_store_thumbnail_for(media_item, %{
"thumbnail" => "https://example.com/thumbnail.jpg"
})
MetadataFileHelpers.download_and_store_thumbnail_for(media_item, render_parsed_metadata(:media_metadata))
}
}
@@ -54,13 +54,11 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
describe "download_and_store_thumbnail_for/2" do
setup do
# This tests that the HTTP endpoint is being called with every test
expect(HTTPClientMock, :get, fn url, _headers, _opts ->
assert url =~ "example.com"
expect(HTTPClientMock, :get, fn _url, _headers, _opts ->
{:ok, "thumbnail data"}
end)
metadata = %{"thumbnail" => "example.com/thumbnail.jpg"}
metadata = render_parsed_metadata(:media_metadata)
{:ok, %{metadata: metadata}}
end
@@ -68,7 +66,7 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
test "returns the filepath", %{media_item: media_item, metadata: metadata} do
filepath = Helpers.download_and_store_thumbnail_for(media_item, metadata)
assert filepath =~ ~r{/media_items/#{media_item.id}/thumbnail.jpg}
assert filepath =~ ~r{/media_items/#{media_item.id}/maxresdefault.jpg}
end
test "creates folder structure based on passed record", %{media_item: media_item, metadata: metadata} do
@@ -77,11 +75,19 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
assert File.exists?(Path.dirname(filepath))
end
test "the filename and extension is based on the URL", %{media_item: media_item} do
metadata = %{"thumbnail" => "example.com/maxres.webp"}
test "chooses the highest preference jpg thumbnail available", %{media_item: media_item} do
metadata = %{
"thumbnails" => [
%{"url" => "https://i.ytimg.com/vi/ABC123/img_1.jpg", "preference" => -1},
%{"url" => "https://i.ytimg.com/vi/ABC123/img_2.jpg", "preference" => 1},
%{"url" => "https://i.ytimg.com/vi/ABC123/img_3.jpg", "preference" => -10},
%{"url" => "https://i.ytimg.com/vi/ABC123/img_4.webp", "preference" => 10}
]
}
filepath = Helpers.download_and_store_thumbnail_for(media_item, metadata)
assert Path.basename(filepath) == "maxres.webp"
assert filepath =~ ~r{/media_items/#{media_item.id}/img_2.jpg}
end
end
@@ -97,6 +97,15 @@ defmodule PinchflatWeb.MediaItemControllerTest do
assert [_] = all_enqueued(worker: MediaDownloadWorker)
end
test "doesn't freak out if the task is a duplicate", %{conn: conn} do
media_item = media_item_fixture()
MediaDownloadWorker.kickoff_with_task(media_item, %{force: true})
post(conn, ~p"/sources/#{media_item.source_id}/media/#{media_item.id}/force_download")
assert [_] = all_enqueued(worker: MediaDownloadWorker)
end
test "forces a download even if one wouldn't normally run", %{conn: conn} do
media_item = media_item_fixture(%{media_filepath: nil})