CAptured more details in logging
This commit is contained in:
parent
cfa3dd95bf
commit
79534132f6
5 changed files with 21 additions and 15 deletions
|
|
@ -28,17 +28,10 @@ defmodule Pinchflat.Utils.CliUtils do
|
|||
|
||||
Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}")
|
||||
|
||||
case System.cmd(wrapper_command, actual_command, passthrough_opts) do
|
||||
{output, 0 = status} ->
|
||||
Logger.debug("[command_wrapper]: #{command} called with: #{logging_arg_override} returned: #{status}")
|
||||
{output, status} = System.cmd(wrapper_command, actual_command, passthrough_opts)
|
||||
log_cmd_result(command, logging_arg_override, status, output)
|
||||
|
||||
{output, status}
|
||||
|
||||
{output, status} ->
|
||||
Logger.error("[command_wrapper]: #{command} called with: #{logging_arg_override} returned: #{status}")
|
||||
|
||||
{output, status}
|
||||
end
|
||||
{output, status}
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
@ -81,4 +74,11 @@ defmodule Pinchflat.Utils.CliUtils do
|
|||
defp parse_option(arg, acc) when is_binary(arg) do
|
||||
acc ++ [arg]
|
||||
end
|
||||
|
||||
defp log_cmd_result(command, logging_arg_override, status, output) do
|
||||
log_message = "[command_wrapper]: #{command} called with: #{logging_arg_override} exited: #{status} with: #{output}"
|
||||
log_level = if status == 0, do: :debug, else: :error
|
||||
|
||||
Logger.log(log_level, log_message)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||
|
||||
output_filepath = generate_output_filepath(addl_opts)
|
||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||
user_configured_opts = cookie_file_options() ++ global_options()
|
||||
user_configured_opts = cookie_file_options()
|
||||
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
||||
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts
|
||||
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts ++ global_options()
|
||||
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||
|
||||
case CliUtils.wrap_cmd(command, formatted_command_opts, stderr_to_stdout: true) do
|
||||
|
|
@ -71,7 +71,7 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
|||
end
|
||||
|
||||
defp global_options do
|
||||
[:windows_filenames]
|
||||
[:windows_filenames, :quiet]
|
||||
end
|
||||
|
||||
defp cookie_file_options do
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
|||
# `ignore_no_formats_error` is necessary because yt-dlp will error out if
|
||||
# the first video has not released yet (ie: is a premier). We don't care about
|
||||
# available formats since we're just getting the media details
|
||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error]
|
||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||
output_template = YtDlpMedia.indexing_output_template()
|
||||
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
||||
file_listener_handler = Keyword.get(addl_opts, :file_listener_handler, false)
|
||||
|
|
|
|||
|
|
@ -87,6 +87,12 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
|||
|
||||
assert String.contains?(output, "--windows-filenames")
|
||||
end
|
||||
|
||||
test "runs quietly" do
|
||||
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||
|
||||
assert String.contains?(output, "--quiet")
|
||||
end
|
||||
end
|
||||
|
||||
describe "version/0" do
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
|||
|
||||
test "it passes the expected default args" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, opts, ot, _addl_opts ->
|
||||
assert opts == [:simulate, :skip_download, :ignore_no_formats_error]
|
||||
assert opts == [:simulate, :skip_download, :ignore_no_formats_error, :no_warnings]
|
||||
assert ot == Media.indexing_output_template()
|
||||
|
||||
{:ok, ""}
|
||||
|
|
|
|||
Loading…
Reference in a new issue