mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
[Enhancement] Add support for yt-dlp plugins + add lifecycle script event for app boot (#465)
* Added new script type to pre-job startup tasks * Updated Dockerfile to create the needful directories * added tests
This commit is contained in:
parent
83c10b2b00
commit
a02f71f304
5 changed files with 28 additions and 1 deletions
|
|
@ -88,6 +88,7 @@ RUN apt-get update -y && \
|
|||
ca-certificates \
|
||||
python3-mutagen \
|
||||
curl \
|
||||
zip \
|
||||
openssh-client \
|
||||
nano \
|
||||
python3 \
|
||||
|
|
@ -116,7 +117,8 @@ ENV LC_ALL en_US.UTF-8
|
|||
WORKDIR "/app"
|
||||
|
||||
# Set up data volumes
|
||||
RUN mkdir /config /downloads /etc/elixir_tzdata_data && chmod ugo+rw /etc/elixir_tzdata_data
|
||||
RUN mkdir -p /config /downloads /etc/elixir_tzdata_data /etc/yt-dlp/plugins && \
|
||||
chmod ugo+rw /etc/elixir_tzdata_data /etc/yt-dlp /etc/yt-dlp/plugins
|
||||
|
||||
# set runner ENV
|
||||
ENV MIX_ENV="prod"
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Utils.FilesystemUtils
|
||||
|
||||
alias Pinchflat.Lifecycle.UserScripts.CommandRunner, as: UserScriptRunner
|
||||
|
||||
def start_link(opts \\ []) do
|
||||
GenServer.start_link(__MODULE__, %{}, opts)
|
||||
end
|
||||
|
|
@ -36,6 +38,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
create_blank_yt_dlp_files()
|
||||
create_blank_user_script_file()
|
||||
apply_default_settings()
|
||||
run_app_init_script()
|
||||
|
||||
{:ok, state}
|
||||
end
|
||||
|
|
@ -95,6 +98,12 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
|||
Settings.set(apprise_version: apprise_version)
|
||||
end
|
||||
|
||||
defp run_app_init_script do
|
||||
runner = Application.get_env(:pinchflat, :user_script_runner, UserScriptRunner)
|
||||
|
||||
runner.run(:app_init, %{})
|
||||
end
|
||||
|
||||
defp yt_dlp_runner do
|
||||
Application.get_env(:pinchflat, :yt_dlp_runner)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
|
|||
@behaviour UserScriptCommandRunner
|
||||
|
||||
@event_types [
|
||||
:app_init,
|
||||
:media_pre_download,
|
||||
:media_downloaded,
|
||||
:media_deleted
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ defmodule Pinchflat.Release do
|
|||
[
|
||||
"/config",
|
||||
"/downloads",
|
||||
"/etc/yt-dlp",
|
||||
"/etc/yt-dlp/plugins",
|
||||
Application.get_env(:pinchflat, :media_directory),
|
||||
Application.get_env(:pinchflat, :tmpfile_directory),
|
||||
Application.get_env(:pinchflat, :extras_directory),
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||
setup do
|
||||
stub(YtDlpRunnerMock, :version, fn -> {:ok, "1"} end)
|
||||
stub(AppriseRunnerMock, :version, fn -> {:ok, "2"} end)
|
||||
stub(UserScriptRunnerMock, :run, fn _event_type, _data -> {:ok, "3", 0} end)
|
||||
|
||||
:ok
|
||||
end
|
||||
|
|
@ -112,4 +113,16 @@ defmodule Pinchflat.Boot.PreJobStartupTasksTest do
|
|||
assert Settings.get!(:apprise_version)
|
||||
end
|
||||
end
|
||||
|
||||
describe "run_app_init_script" do
|
||||
test "calls the app_init user script runner" do
|
||||
expect(UserScriptRunnerMock, :run, fn :app_init, data ->
|
||||
assert data == %{}
|
||||
|
||||
{:ok, "", 0}
|
||||
end)
|
||||
|
||||
PreJobStartupTasks.init(%{})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue