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}")
|
Logger.info("[command_wrapper]: #{command} called with: #{logging_arg_override}")
|
||||||
|
|
||||||
case System.cmd(wrapper_command, actual_command, passthrough_opts) do
|
{output, status} = System.cmd(wrapper_command, actual_command, passthrough_opts)
|
||||||
{output, 0 = status} ->
|
log_cmd_result(command, logging_arg_override, status, output)
|
||||||
Logger.debug("[command_wrapper]: #{command} called with: #{logging_arg_override} returned: #{status}")
|
|
||||||
|
|
||||||
{output, status}
|
{output, status}
|
||||||
|
|
||||||
{output, status} ->
|
|
||||||
Logger.error("[command_wrapper]: #{command} called with: #{logging_arg_override} returned: #{status}")
|
|
||||||
|
|
||||||
{output, status}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
|
@ -81,4 +74,11 @@ defmodule Pinchflat.Utils.CliUtils do
|
||||||
defp parse_option(arg, acc) when is_binary(arg) do
|
defp parse_option(arg, acc) when is_binary(arg) do
|
||||||
acc ++ [arg]
|
acc ++ [arg]
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
|
|
||||||
output_filepath = generate_output_filepath(addl_opts)
|
output_filepath = generate_output_filepath(addl_opts)
|
||||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
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.
|
# 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)
|
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||||
|
|
||||||
case CliUtils.wrap_cmd(command, formatted_command_opts, stderr_to_stdout: true) do
|
case CliUtils.wrap_cmd(command, formatted_command_opts, stderr_to_stdout: true) do
|
||||||
|
|
@ -71,7 +71,7 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp global_options do
|
defp global_options do
|
||||||
[:windows_filenames]
|
[:windows_filenames, :quiet]
|
||||||
end
|
end
|
||||||
|
|
||||||
defp cookie_file_options do
|
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
|
# `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
|
# 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
|
# 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_template = YtDlpMedia.indexing_output_template()
|
||||||
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
output_filepath = FilesystemUtils.generate_metadata_tmpfile(:json)
|
||||||
file_listener_handler = Keyword.get(addl_opts, :file_listener_handler, false)
|
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")
|
assert String.contains?(output, "--windows-filenames")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "runs quietly" do
|
||||||
|
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||||
|
|
||||||
|
assert String.contains?(output, "--quiet")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "version/0" do
|
describe "version/0" do
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||||
|
|
||||||
test "it passes the expected default args" do
|
test "it passes the expected default args" do
|
||||||
expect(YtDlpRunnerMock, :run, fn _url, opts, ot, _addl_opts ->
|
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()
|
assert ot == Media.indexing_output_template()
|
||||||
|
|
||||||
{:ok, ""}
|
{:ok, ""}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue