[Enhancement] Download image when using playlists with media center apps (#313)
* [WIP] started adding calls for downloading posters for playlists * Updated source image parser to work with playlists
This commit is contained in:
@@ -75,4 +75,51 @@ defmodule Pinchflat.Metadata.SourceImageParserTest do
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == %{}
|
||||
end
|
||||
end
|
||||
|
||||
describe "store_source_images/2 when testing fallbacks" do
|
||||
test "uses the entries list for a fallback poster if needed" do
|
||||
metadata = %{
|
||||
"thumbnails" => [],
|
||||
"entries" => [
|
||||
%{
|
||||
"thumbnails" => [%{"filepath" => "/app/test/support/files/channel_photos/a.0.jpg"}]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expected = %{
|
||||
poster_filepath: "#{@base_dir}/poster.jpg"
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == expected
|
||||
end
|
||||
|
||||
test "doesn't blow up if the entries list doesn't have any suitable thumbnails" do
|
||||
metadata = %{
|
||||
"thumbnails" => [],
|
||||
"entries" => [
|
||||
%{"thumbnails" => [%{"id" => "1"}]}
|
||||
]
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == %{}
|
||||
end
|
||||
|
||||
test "doesn't use the entries list if it's empty" do
|
||||
metadata = %{
|
||||
"thumbnails" => [],
|
||||
"entries" => []
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == %{}
|
||||
end
|
||||
|
||||
test "doesn't use the entries list if it's not present" do
|
||||
metadata = %{
|
||||
"thumbnails" => []
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == %{}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -143,7 +143,9 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
_url, opts, ot when ot == @metadata_ot ->
|
||||
assert {:convert_thumbnails, "jpg"} in opts
|
||||
|
||||
{:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
@@ -164,6 +166,42 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
Sources.delete_source(source, delete_files: true)
|
||||
end
|
||||
|
||||
test "calls one set of yt-dlp metadata opts for channels" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
{:ok, source_details_return_fixture()}
|
||||
|
||||
_url, opts, ot when ot == @metadata_ot ->
|
||||
assert {:playlist_items, 0} in opts
|
||||
assert :write_all_thumbnails in opts
|
||||
|
||||
{:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_source_images: true})
|
||||
source = source_fixture(media_profile_id: profile.id, collection_type: :channel)
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
end
|
||||
|
||||
test "calls another set of yt-dlp metadata opts for playlists" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
{:ok, source_details_return_fixture()}
|
||||
|
||||
_url, opts, ot when ot == @metadata_ot ->
|
||||
assert {:playlist_items, 1} in opts
|
||||
assert :write_thumbnail in opts
|
||||
|
||||
{:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_source_images: true})
|
||||
source = source_fixture(media_profile_id: profile.id, collection_type: :playlist)
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
end
|
||||
|
||||
test "does not store source images if the profile is not set to" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
|
||||
@@ -129,7 +129,7 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||
|
||||
test "it passes the expected args to the backend runner" do
|
||||
expect(YtDlpRunnerMock, :run, fn @channel_url, opts, ot ->
|
||||
assert opts == [playlist_items: 0]
|
||||
assert opts == [:skip_download, playlist_items: 0]
|
||||
assert ot == "playlist:%()j"
|
||||
|
||||
{:ok, "{}"}
|
||||
@@ -152,12 +152,18 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||
|
||||
test "allows you to pass additional opts" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, opts, _ot ->
|
||||
assert opts == [playlist_items: 0, real_opt: :yup]
|
||||
assert opts == [:skip_download, playlist_items: 1, real_opt: :yup]
|
||||
|
||||
{:ok, "{}"}
|
||||
end)
|
||||
|
||||
assert {:ok, _} = MediaCollection.get_source_metadata(@channel_url, real_opt: :yup)
|
||||
assert {:ok, _} = MediaCollection.get_source_metadata(@channel_url, playlist_items: 1, real_opt: :yup)
|
||||
end
|
||||
|
||||
test "blows up if you pass addl opts but don't pass playlist items" do
|
||||
assert_raise KeyError, fn ->
|
||||
MediaCollection.get_source_metadata(@channel_url, real_opt: :yup)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user