Addressed TODOs
This commit is contained in:
parent
785be6cced
commit
5dbbd9cabe
6 changed files with 47 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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, "<yt:videoId>test_1</yt:videoId>"} 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, "<yt:videoId>test_1</yt:videoId>"} end)
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue