diff --git a/lib/pinchflat/downloading/download_option_builder.ex b/lib/pinchflat/downloading/download_option_builder.ex
index b6a71df..1b927b9 100644
--- a/lib/pinchflat/downloading/download_option_builder.ex
+++ b/lib/pinchflat/downloading/download_option_builder.ex
@@ -34,7 +34,7 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
@doc """
Builds the output path for yt-dlp to download media based on the given source's
- media profile. Uses the source's override output path template if it exists.
+ or media_item's media profile. Uses the source's override output path template if it exists.
Accepts a %MediaItem{} or %Source{} struct. If a %Source{} struct is passed, it
will use a default %MediaItem{} struct with the given source.
@@ -51,7 +51,13 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
build_output_path(output_path_template, media_item_with_preloads)
end
- # TODO: test
+ @doc """
+ Builds the quality options for yt-dlp to download media based on the given source's
+ or media_item's media profile. Useful for helping predict final filepath of downloaded
+ media.
+
+ returns [Keyword.t()]
+ """
def build_quality_options_for(%Source{} = source_with_preloads) do
build_quality_options_for(%MediaItem{source: source_with_preloads})
end
diff --git a/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex b/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex
index c4a26e8..9daeda1 100644
--- a/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex
+++ b/lib/pinchflat/fast_indexing/fast_indexing_helpers.ex
@@ -72,7 +72,7 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpers do
defp create_media_item_from_media_id(source, media_id) do
url = "https://www.youtube.com/watch?v=#{media_id}"
- # TODO: test
+
command_opts =
[output: DownloadOptionBuilder.build_output_path_for(source)] ++
DownloadOptionBuilder.build_quality_options_for(source)
diff --git a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex
index 06d84d0..74e5f4c 100644
--- a/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex
+++ b/lib/pinchflat/slow_indexing/slow_indexing_helpers.ex
@@ -99,7 +99,6 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
handler = fn filepath -> setup_file_follower_watcher(pid, filepath, source) end
- # TODO: test
command_opts =
[output: DownloadOptionBuilder.build_output_path_for(source)] ++
DownloadOptionBuilder.build_quality_options_for(source)
diff --git a/test/pinchflat/downloading/download_option_builder_test.exs b/test/pinchflat/downloading/download_option_builder_test.exs
index 98aff6f..97ad118 100644
--- a/test/pinchflat/downloading/download_option_builder_test.exs
+++ b/test/pinchflat/downloading/download_option_builder_test.exs
@@ -461,6 +461,22 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
end
end
+ describe "build_quality_options_for/1" do
+ test "builds quality options for a media item", %{media_item: media_item} do
+ options = DownloadOptionBuilder.build_quality_options_for(media_item)
+
+ assert {:format_sort, "res:1080,+codec:avc:m4a"} in options
+ assert {:remux_video, "mp4"} in options
+ end
+
+ test "builds quality options for a source", %{media_item: media_item} do
+ options = DownloadOptionBuilder.build_quality_options_for(media_item.source)
+
+ assert {:format_sort, "res:1080,+codec:avc:m4a"} in options
+ assert {:remux_video, "mp4"} in options
+ end
+ end
+
defp update_media_profile_attribute(media_item_with_preloads, attrs) do
media_item_with_preloads.source.media_profile
|> Profiles.change_media_profile(attrs)
diff --git a/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs b/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs
index d2620f6..5422018 100644
--- a/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs
+++ b/test/pinchflat/fast_indexing/fast_indexing_helpers_test.exs
@@ -61,6 +61,18 @@ defmodule Pinchflat.FastIndexing.FastIndexingHelpersTest do
assert [_] = Tasks.list_tasks_for(media_item, "MediaDownloadWorker")
end
+ test "passes the source's download options to the yt-dlp runner", %{source: source} do
+ expect(HTTPClientMock, :get, fn _url -> {:ok, "test_1"} end)
+
+ expect(YtDlpRunnerMock, :run, fn _url, opts, _ot, _addl_opts ->
+ assert {:output, "/tmp/test/media/%(title)S.%(ext)S"} in opts
+ assert {:remux_video, "mp4"} in opts
+ {:ok, media_attributes_return_fixture()}
+ end)
+
+ FastIndexingHelpers.kickoff_download_tasks_from_youtube_rss_feed(source)
+ end
+
test "sets use_cookies if the source uses cookies" do
expect(HTTPClientMock, :get, fn _url -> {:ok, "test_1"} end)
diff --git a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs
index a4650e8..36abcd7 100644
--- a/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs
+++ b/test/pinchflat/slow_indexing/slow_indexing_helpers_test.exs
@@ -202,6 +202,16 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpersTest do
assert %Ecto.Changeset{} = changeset
end
+ test "passes the source's download options to the yt-dlp runner", %{source: source} do
+ expect(YtDlpRunnerMock, :run, fn _url, opts, _ot, _addl_opts ->
+ assert {:output, "/tmp/test/media/%(title)S.%(ext)S"} in opts
+ assert {:remux_video, "mp4"} in opts
+ {:ok, source_attributes_return_fixture()}
+ end)
+
+ SlowIndexingHelpers.index_and_enqueue_download_for_media_items(source)
+ end
+
test "sets use_cookies if the source uses cookies" do
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot, addl_opts ->
assert {:use_cookies, true} in addl_opts