Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/hex/floki-0.36.2
Browse files Browse the repository at this point in the history
  • Loading branch information
trueChazza committed Jun 14, 2024
2 parents 5c501b8 + 932df8d commit 5813f15
Show file tree
Hide file tree
Showing 68 changed files with 524 additions and 934 deletions.
35 changes: 21 additions & 14 deletions .github/install-sonarr.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
#!/bin/bash

sudo apt install gnupg ca-certificates
# Install dependencies
sudo apt update
sudo apt install -y gnupg ca-certificates curl sqlite3

# Add Mono repository and key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb https://download.mono-project.com/repo/ubuntu stable-focal main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list
sudo apt update
sudo apt install mono-devel
sudo apt install -y mono-devel

# Setup Sonarr user and permissions
sudo groupadd media
sudo adduser --system --no-create-home --ingroup media sonarr
sudo usermod -a -G media sonarr

sudo chown -R sonarr:media /library/series
sudo chmod 775 /library/series

# Setup directories
sudo mkdir -p /var/lib/sonarr
sudo mv ${GITHUB_WORKSPACE}/dev/sonarr/config.xml /var/lib/sonarr
sudo cp ${GITHUB_WORKSPACE}/dev/sonarr/config.xml /var/lib/sonarr
sudo chown -R sonarr:media /var/lib/sonarr
sudo chmod 775 /var/lib/sonarr

sudo apt install curl sqlite3
# Install Sonarr
wget --content-disposition "https://download.sonarr.tv/v4/main/4.0.0.748/Sonarr.main.4.0.0.748.linux-x64.tar.gz"
tar -xvzf Sonarr*.linux*.tar.gz
sudo mv Sonarr /opt
sudo chown sonarr:media -R /opt/Sonarr
sudo chown -R sonarr:media /opt/Sonarr

# Create and enable Sonarr service
cat << EOF | sudo tee /etc/systemd/system/sonarr.service > /dev/null
[Unit]
Description=Sonarr Daemon
After=syslog.target network.target
After=network.target
[Service]
User=sonarr
Group=media
UMask=002
Type=simple
ExecStart=/usr/bin/mono --debug /opt/Sonarr/Sonarr.exe -nobrowser -data=/var/lib/sonarr
ExecStart=/opt/Sonarr/Sonarr -nobrowser -data=/var/lib/sonarr
TimeoutStopSec=20
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl -q daemon-reload
sudo systemctl enable --now -q sonarr
sudo journalctl --since today -u sonarr

sudo systemctl daemon-reload
sudo systemctl enable --now sonarr
17 changes: 6 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,14 @@ ARG SECRET_KEY_BASE=""
ENV MIX_ENV="${MIX_ENV}"
ENV SECRET_KEY_BASE="${SECRET_KEY_BASE}"

RUN MIX_ENV=$MIX_ENV
RUN SECRET_KEY_BASE=$SECRET_KEY_BASE

WORKDIR /app

COPY . ./
COPY --from=node /assets/node_modules /app/assets/node_modules/

RUN \
echo "@latest https://dl-cdn.alpinelinux.org/alpine/latest-stable/community" >> /etc/apk/repositories \
&& echo "https://dl-cdn.alpinelinux.org/alpine/v3.11/main" >> /etc/apk/repositories \
&& echo "https://dl-cdn.alpinelinux.org/alpine/v3.12/community" >> /etc/apk/repositories \
&& echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" >> /etc/apk/repositories \
&& echo "@edge-community https://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories \
echo "https://dl-cdn.alpinelinux.org/alpine/v3.18/main" > /etc/apk/repositories \
&& echo "https://dl-cdn.alpinelinux.org/alpine/v3.18/community" >> /etc/apk/repositories \
&& apk update

RUN \
Expand All @@ -42,11 +36,12 @@ RUN \
curl \
make \
g++ \
"libva-intel-driver@edge-community=2.4.1-r0" \
"shaderc@edge-community=2023.7-r0" \
libva-intel-driver \
shaderc \
libdav1d \
spirv-tools \
"ffmpeg@latest=6.1.1-r0" \
ffmpeg \
git \
&& \
mix local.hex --force \
&& mix local.rebar --force \
Expand Down
2 changes: 0 additions & 2 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ let liveSocket = new LiveSocket("/live", Socket, {

delete event["returnValue"]
})

this.pushEvent("video_played")
},
destroyed() {
window.removeEventListener("beforeunload")
Expand Down
10 changes: 5 additions & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ config :media_server, MediaServer.Repo,
database: System.get_env("DB_DATABASE"),
hostname: System.get_env("DB_HOSTNAME")

config :web_push_elixir,
vapid_public_key: System.get_env("VAPID_PUBLIC_KEY"),
vapid_private_key: System.get_env("VAPID_PRIVATE_KEY"),
vapid_subject: System.get_env("VAPID_SUBJECT")

config :oapi_tmdb,
api_key: System.get_env("TMDB_API_KEY")

config :media_server, Oban,
engine: Oban.Engines.Basic,
queues: [default: 10],
repo: MediaServer.Repo

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{config_env()}.exs"
2 changes: 2 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ config :logger, level: :warning

# Initialize plugs at runtime for faster test compilation
config :phoenix, :plug_init_mode, :runtime

config :media_server, Oban, testing: :inline
2 changes: 1 addition & 1 deletion dev/sonarr/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<UpdateMechanism>Docker</UpdateMechanism>
<LaunchBrowser>True</LaunchBrowser>
<Branch>main</Branch>
<SslCertHash></SslCertHash>
<InstanceName>Sonarr</InstanceName>
<AuthenticationRequired>Enabled</AuthenticationRequired>
</Config>
8 changes: 4 additions & 4 deletions entry-local.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh

curl -d "@dev/radarr/root-folder.json" -H "Content-Type:application/json" -X POST "http://radarr:7878/api/v3/rootfolder?apiKey=d031e8c9b9df4b2fab311d1c3b3fa2c5"
curl -d "@dev/radarr/movies.json" -H "Content-Type:application/json" -X POST "http://radarr:7878/api/v3/movie/import?apiKey=d031e8c9b9df4b2fab311d1c3b3fa2c5"
curl -d "@dev/radarr/root-folder.json" -H "Content-Type:application/json" -X POST "http://radarr-dev:7878/api/v3/rootfolder?apiKey=d031e8c9b9df4b2fab311d1c3b3fa2c5"
curl -d "@dev/radarr/movies.json" -H "Content-Type:application/json" -X POST "http://radarr-dev:7878/api/v3/movie/import?apiKey=d031e8c9b9df4b2fab311d1c3b3fa2c5"

curl -d "@dev/sonarr/root-folder.json" -H "Content-Type:application/json" -X POST "http://sonarr:8989/api/v3/rootfolder?apikey=1accda4476394bfcaddefe8c4fd77d4a"
curl -d "@dev/sonarr/series.json" -H "Content-Type:application/json" -X POST "http://sonarr:8989/api/v3/series/import?apikey=1accda4476394bfcaddefe8c4fd77d4a"
curl -d "@dev/sonarr/root-folder.json" -H "Content-Type:application/json" -X POST "http://sonarr-dev:8989/api/v3/rootfolder?apikey=1accda4476394bfcaddefe8c4fd77d4a"
curl -d "@dev/sonarr/series.json" -H "Content-Type:application/json" -X POST "http://sonarr-dev:8989/api/v3/series/import?apikey=1accda4476394bfcaddefe8c4fd77d4a"

mix deps.get

Expand Down
2 changes: 1 addition & 1 deletion lib/media_server/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule MediaServer.Accounts do
def get_user!(id), do: Repo.get!(User, id)

def register_user(attrs) do
case %User{} |> User.registration_changeset(attrs) |> Repo.insert() do
case %User{} |> User.registration_changeset(attrs) |> Repo.insert(on_conflict: :nothing) do
{:ok, user} ->
MediaServer.Accounts.generate_user_api_token(user)

Expand Down
4 changes: 0 additions & 4 deletions lib/media_server/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ defmodule MediaServer.Accounts.User do
field :confirmed_at, :naive_datetime
field :is_admin, :boolean

has_many :continues, MediaServer.Continues
has_many :media_actions, MediaServer.MediaActions
has_many :push_subscriptions, MediaServer.PushSubscriptions

has_one :api_token, MediaServer.Accounts.UserToken, where: [context: "api"]

timestamps()
Expand Down
35 changes: 0 additions & 35 deletions lib/media_server/actions.ex

This file was deleted.

17 changes: 17 additions & 0 deletions lib/media_server/actions/add_episode.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule MediaServer.AddEpisode do
use Oban.Worker, queue: :default, max_attempts: 3

@impl true
@spec perform(%{:args => map(), optional(any()) => any()}) :: :ok
def perform(%Oban.Job{args: %{"items" => items}}) do
items
|> Enum.each(fn item ->
MediaServer.Episodes.insert(%{
series_id: item["series_id"],
external_id: item["external_id"]
})
end)

:ok
end
end
16 changes: 16 additions & 0 deletions lib/media_server/actions/add_movies.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule MediaServer.AddMovies do
use Oban.Worker, queue: :default, max_attempts: 3

@impl true
@spec perform(%{:args => map(), optional(any()) => any()}) :: :ok
def perform(%Oban.Job{args: %{"items" => items}}) do
items
|> Enum.each(fn item ->
MediaServer.Movies.insert(%{
external_id: item["external_id"]
})
end)

:ok
end
end
18 changes: 18 additions & 0 deletions lib/media_server/actions/add_people.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule MediaServer.AddPeople do
use Oban.Worker, queue: :default, max_attempts: 3

@impl true
@spec perform(%{:args => map(), optional(any()) => any()}) :: :ok
def perform(%Oban.Job{args: %{"items" => items}}) do
items
|> Enum.each(fn item ->
MediaServer.People.insert(%{
tmdb_id: item["tmdb_id"],
name: item["name"],
image: item["image"]
})
end)

:ok
end
end
16 changes: 16 additions & 0 deletions lib/media_server/actions/add_series.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule MediaServer.AddSeries do
use Oban.Worker, queue: :default, max_attempts: 3

@impl true
@spec perform(%{:args => map(), optional(any()) => any()}) :: :ok
def perform(%Oban.Job{args: %{"items" => items}}) do
items
|> Enum.each(fn item ->
MediaServer.Series.insert(%{
external_id: item["external_id"]
})
end)

:ok
end
end
1 change: 1 addition & 0 deletions lib/media_server/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule MediaServer.Application do
# {MediaServer.Worker, arg}
MediaServerWeb.Presence,
{DynamicSupervisor, name: MediaServer.DynamicSupervisor},
{Oban, Application.fetch_env!(:media_server, Oban)},
MediaServer.MoviesIndex,
MediaServer.SeriesIndex
]
Expand Down
52 changes: 0 additions & 52 deletions lib/media_server/continues.ex

This file was deleted.

45 changes: 45 additions & 0 deletions lib/media_server/episode_continues.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule MediaServer.EpisodeContinues do
use Ecto.Schema
import Ecto.Changeset

alias MediaServer.Repo

schema "episode_continues" do
belongs_to :episode, MediaServer.Episodes, foreign_key: :episodes_id
belongs_to :user, MediaServer.Accounts.User

field :current_time, :integer
field :duration, :integer

timestamps()
end

def changeset(continue, attrs) do
continue
|> cast(attrs, [:episodes_id, :current_time, :duration, :user_id])
|> validate_required([:episodes_id, :current_time, :duration, :user_id])
end

def insert_or_update(attrs) do
case Repo.get_by(__MODULE__, episodes_id: attrs.episodes_id, user_id: attrs.user_id) do
nil ->
%__MODULE__{
episodes_id: attrs.episodes_id,
user_id: attrs.user_id
}

item ->
item
end
|> changeset(
Enum.into(attrs, %{
updated_at: DateTime.utc_now()
})
)
|> Repo.insert_or_update()
end

def where(attrs) do
Repo.get_by(__MODULE__, attrs)
end
end
Loading

0 comments on commit 5813f15

Please sign in to comment.