Added a command for updating yt-dlp

This commit is contained in:
Kieran Eglin 2025-01-22 14:57:35 -08:00
parent 62214b80a6
commit 330f7404c3
No known key found for this signature in database
GPG key ID: 193984967FCF432D
3 changed files with 27 additions and 0 deletions

View file

@ -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)

View file

@ -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

View file

@ -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.()