Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add support for yt-dlp plugins + add lifecycle script event for app boot #465

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docker/selfhosted.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

Check warning on line 10 in docker/selfhosted.Dockerfile

View workflow job for this annotation

GitHub Actions / build_and_push_docker

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/

ARG TARGETPLATFORM
RUN echo "Building for ${TARGETPLATFORM:?}"
Expand Down Expand Up @@ -88,6 +88,7 @@
ca-certificates \
python3-mutagen \
curl \
zip \
openssh-client \
nano \
python3 \
Expand All @@ -109,14 +110,15 @@
rm -rf /var/lib/apt/lists/*

# More locale setup
ENV LANG en_US.UTF-8

Check warning on line 113 in docker/selfhosted.Dockerfile

View workflow job for this annotation

GitHub Actions / build_and_push_docker

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV LANGUAGE en_US:en

Check warning on line 114 in docker/selfhosted.Dockerfile

View workflow job for this annotation

GitHub Actions / build_and_push_docker

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/
ENV LC_ALL en_US.UTF-8

Check warning on line 115 in docker/selfhosted.Dockerfile

View workflow job for this annotation

GitHub Actions / build_and_push_docker

Legacy key/value format with whitespace separator should not be used

LegacyKeyValueFormat: "ENV key=value" should be used instead of legacy "ENV key value" format More info: https://docs.docker.com/go/dockerfile/rule/legacy-key-value-format/

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"
Expand Down
9 changes: 9 additions & 0 deletions lib/pinchflat/boot/pre_job_startup_tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/pinchflat/lifecycle/user_scripts/command_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule Pinchflat.Lifecycle.UserScripts.CommandRunner do
@behaviour UserScriptCommandRunner

@event_types [
:app_init,
:media_pre_download,
:media_downloaded,
:media_deleted
Expand Down
2 changes: 2 additions & 0 deletions lib/pinchflat/release.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
13 changes: 13 additions & 0 deletions test/pinchflat/boot/pre_job_startup_tasks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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