diff --git a/lib/pinchflat/boot/pre_job_startup_tasks.ex b/lib/pinchflat/boot/pre_job_startup_tasks.ex index 0e28d94..bc52ee1 100644 --- a/lib/pinchflat/boot/pre_job_startup_tasks.ex +++ b/lib/pinchflat/boot/pre_job_startup_tasks.ex @@ -14,6 +14,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do alias Pinchflat.Repo alias Pinchflat.Settings + alias Pinchflat.YtDlp.CommandRunner alias Pinchflat.Filesystem.FilesystemHelpers def start_link(opts \\ []) do @@ -62,7 +63,10 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do end defp apply_default_settings do + {:ok, yt_dlp_version} = CommandRunner.version() + Settings.fetch!(:onboarding, true) Settings.fetch!(:pro_enabled, false) + Settings.set!(:yt_dlp_version, yt_dlp_version) end end diff --git a/lib/pinchflat/yt_dlp/backend_command_runner.ex b/lib/pinchflat/yt_dlp/backend_command_runner.ex index fef612c..e09eaeb 100644 --- a/lib/pinchflat/yt_dlp/backend_command_runner.ex +++ b/lib/pinchflat/yt_dlp/backend_command_runner.ex @@ -8,4 +8,5 @@ defmodule Pinchflat.YtDlp.BackendCommandRunner do @callback run(binary(), keyword(), binary()) :: {:ok, binary()} | {:error, binary(), integer()} @callback run(binary(), keyword(), binary(), keyword()) :: {:ok, binary()} | {:error, binary(), integer()} + @callback version() :: {:ok, binary()} | {:error, binary()} end diff --git a/lib/pinchflat/yt_dlp/command_runner.ex b/lib/pinchflat/yt_dlp/command_runner.ex index 9fa2136..7512768 100644 --- a/lib/pinchflat/yt_dlp/command_runner.ex +++ b/lib/pinchflat/yt_dlp/command_runner.ex @@ -48,6 +48,19 @@ defmodule Pinchflat.YtDlp.CommandRunner do end end + @impl BackendCommandRunner + def version do + command = backend_executable() + + case System.cmd(command, ["--version"]) do + {output, 0} -> + {:ok, String.trim(output)} + + {output, _} -> + {:error, output} + end + end + defp build_cookie_options do base_dir = Application.get_env(:pinchflat, :extras_directory) cookie_file = Path.join(base_dir, "cookies.txt") diff --git a/lib/pinchflat_web/components/layouts/partials/sidebar.html.heex b/lib/pinchflat_web/components/layouts/partials/sidebar.html.heex index fc34749..978c471 100644 --- a/lib/pinchflat_web/components/layouts/partials/sidebar.html.heex +++ b/lib/pinchflat_web/components/layouts/partials/sidebar.html.heex @@ -58,8 +58,11 @@
  • - - v<%= Application.spec(:pinchflat)[:vsn] %> + + Pinchflat v<%= Application.spec(:pinchflat)[:vsn] %> + + + yt-dlp <%= Settings.get!(:yt_dlp_version) %>
  • diff --git a/test/pinchflat/yt_dlp/command_runner_test.exs b/test/pinchflat/yt_dlp/command_runner_test.exs index f230956..889b030 100644 --- a/test/pinchflat/yt_dlp/command_runner_test.exs +++ b/test/pinchflat/yt_dlp/command_runner_test.exs @@ -102,6 +102,14 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do end end + describe "version/0" do + test "adds the version arg" do + assert {:ok, output} = Runner.version() + + assert String.contains?(output, "--version") + end + end + defp wrap_executable(new_executable, fun) do Application.put_env(:pinchflat, :yt_dlp_executable, new_executable) fun.() diff --git a/test/support/scripts/yt-dlp-mocks/repeater.sh b/test/support/scripts/yt-dlp-mocks/repeater.sh index da53a84..50407a1 100755 --- a/test/support/scripts/yt-dlp-mocks/repeater.sh +++ b/test/support/scripts/yt-dlp-mocks/repeater.sh @@ -12,5 +12,9 @@ for ((i = 1; i <= $#; i++)); do fi done -# Write all args to the file -echo "$@" >"$file_location" +if [ "${!i}" == "--print-to-file" ]; then + # Write all args to the file + echo "$@" >"$file_location" +else + echo "$@" +fi