Added actions to all callers of the yt-dlp runner

This commit is contained in:
Kieran Eglin 2024-12-13 10:07:52 -08:00
parent 493d36a8ad
commit 22183d87e8
No known key found for this signature in database
GPG key ID: 193984967FCF432D
2 changed files with 10 additions and 7 deletions

View file

@ -41,7 +41,7 @@ defmodule Pinchflat.YtDlp.Media do
def download(url, command_opts \\ [], addl_opts \\ []) do
all_command_opts = [:no_simulate] ++ command_opts
with {:ok, output} <- backend_runner().run(url, all_command_opts, "after_move:%()j", addl_opts),
with {:ok, output} <- backend_runner().run(url, :download, all_command_opts, "after_move:%()j", addl_opts),
{:ok, parsed_json} <- Phoenix.json_library().decode(output) do
{:ok, parsed_json}
else
@ -56,7 +56,7 @@ defmodule Pinchflat.YtDlp.Media do
Returns {:ok, :downloadable | :ignorable} | {:error, any}
"""
def get_downloadable_status(url) do
case backend_runner().run(url, [:simulate, :skip_download], "%(.{live_status})j") do
case backend_runner().run(url, :get_downloadable_status, [:simulate, :skip_download], "%(.{live_status})j") do
{:ok, output} ->
output
|> Phoenix.json_library().decode!()
@ -78,7 +78,7 @@ defmodule Pinchflat.YtDlp.Media do
# NOTE: it doesn't seem like this command actually returns anything in `after_move` since
# we aren't downloading the main media file
backend_runner().run(url, all_command_opts, "after_move:%()j", addl_opts)
backend_runner().run(url, :download_thumbnail, all_command_opts, "after_move:%()j", addl_opts)
end
@doc """
@ -92,7 +92,7 @@ defmodule Pinchflat.YtDlp.Media do
all_command_opts = [:simulate, :skip_download] ++ command_opts
output_template = indexing_output_template()
case backend_runner().run(url, all_command_opts, output_template, addl_opts) do
case backend_runner().run(url, :get_media_attributes, all_command_opts, output_template, addl_opts) do
{:ok, output} ->
output
|> Phoenix.json_library().decode!()

View file

@ -33,12 +33,13 @@ defmodule Pinchflat.YtDlp.MediaCollection do
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
file_listener_handler = Keyword.get(addl_opts, :file_listener_handler, false)
runner_opts = [output_filepath: output_filepath, use_cookies: use_cookies]
action = :get_media_attributes_for_collection
if file_listener_handler do
file_listener_handler.(output_filepath)
end
case runner.run(url, all_command_opts, output_template, runner_opts) do
case runner.run(url, action, all_command_opts, output_template, runner_opts) do
{:ok, output} ->
parsed_lines =
output
@ -82,8 +83,9 @@ defmodule Pinchflat.YtDlp.MediaCollection do
all_command_opts = default_opts ++ command_opts
output_template = "%(.{channel,channel_id,playlist_id,playlist_title,filename})j"
action = :get_source_details
with {:ok, output} <- backend_runner().run(source_url, all_command_opts, output_template, addl_opts),
with {:ok, output} <- backend_runner().run(source_url, action, all_command_opts, output_template, addl_opts),
{:ok, parsed_json} <- Phoenix.json_library().decode(output) do
{:ok, format_source_details(parsed_json)}
else
@ -121,8 +123,9 @@ defmodule Pinchflat.YtDlp.MediaCollection do
all_command_opts = [:skip_download] ++ command_opts
output_template = "playlist:%()j"
action = :get_source_metadata
with {:ok, output} <- backend_runner().run(source_url, all_command_opts, output_template, addl_opts),
with {:ok, output} <- backend_runner().run(source_url, action, all_command_opts, output_template, addl_opts),
{:ok, parsed_json} <- Phoenix.json_library().decode(output) do
{:ok, parsed_json}
else