diff --git a/lib/pinchflat/yt_dlp/command_runner.ex b/lib/pinchflat/yt_dlp/command_runner.ex index a2454a8..c90511b 100644 --- a/lib/pinchflat/yt_dlp/command_runner.ex +++ b/lib/pinchflat/yt_dlp/command_runner.ex @@ -76,6 +76,24 @@ defmodule Pinchflat.YtDlp.CommandRunner do end end + @doc """ + Updates yt-dlp to the latest version + + Returns {:ok, binary()} | {:error, binary()} + """ + @impl YtDlpCommandRunner + def update do + command = backend_executable() + + case CliUtils.wrap_cmd(command, ["--update"]) do + {output, 0} -> + {:ok, String.trim(output)} + + {output, _} -> + {:error, output} + end + end + defp generate_output_filepath(addl_opts) do case Keyword.get(addl_opts, :output_filepath) do nil -> FSUtils.generate_metadata_tmpfile(:json) diff --git a/lib/pinchflat/yt_dlp/yt_dlp_command_runner.ex b/lib/pinchflat/yt_dlp/yt_dlp_command_runner.ex index ff1cbcf..e5c770e 100644 --- a/lib/pinchflat/yt_dlp/yt_dlp_command_runner.ex +++ b/lib/pinchflat/yt_dlp/yt_dlp_command_runner.ex @@ -9,4 +9,5 @@ defmodule Pinchflat.YtDlp.YtDlpCommandRunner do @callback run(binary(), atom(), keyword(), binary()) :: {:ok, binary()} | {:error, binary(), integer()} @callback run(binary(), atom(), keyword(), binary(), keyword()) :: {:ok, binary()} | {:error, binary(), integer()} @callback version() :: {:ok, binary()} | {:error, binary()} + @callback update() :: {:ok, binary()} | {:error, binary()} end diff --git a/test/pinchflat/yt_dlp/command_runner_test.exs b/test/pinchflat/yt_dlp/command_runner_test.exs index 9f8382b..4c55972 100644 --- a/test/pinchflat/yt_dlp/command_runner_test.exs +++ b/test/pinchflat/yt_dlp/command_runner_test.exs @@ -154,6 +154,14 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do end end + describe "update/0" do + test "adds the update arg" do + assert {:ok, output} = Runner.update() + + assert String.contains?(output, "--update") + end + end + defp wrap_executable(new_executable, fun) do Application.put_env(:pinchflat, :yt_dlp_executable, new_executable) fun.()