Compare commits
32 Commits
v0.1.0-alpha.5
...
v0.1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 64ebf756ab | |||
| 377bc617ea | |||
| a03f69a8d4 | |||
| d39ebe7ac1 | |||
| 8b5dcc15d6 | |||
| 5e58dcd879 | |||
| a9d5407071 | |||
| 37c1da8014 | |||
| 937a14985f | |||
| a6a20c111f | |||
| 2bb96edc00 | |||
| 87f07ff634 | |||
| dd60cb5419 | |||
| 610b00566b | |||
| aba15ed886 | |||
| 87da716fdf | |||
| 45f056c6e0 | |||
| 11d160008c | |||
| ba0a1ba100 | |||
| 8c51a286c9 | |||
| 46c27e4875 | |||
| b639918555 | |||
| 5596351f58 | |||
| ad150b6f16 | |||
| f6d8e15670 | |||
| 2906ff1b30 | |||
| 0582a7bfd5 | |||
| 3db2e8190f | |||
| 087c9c2d0f | |||
| c046abf36f | |||
| 70dd95211f | |||
| 8491f8b317 |
@@ -13,3 +13,5 @@ N/A
|
||||
## Any other comments?
|
||||
|
||||
N/A
|
||||
|
||||
- [ ] I am the original author of this code and I am giving it freely to the community and Pinchflat project maintainers
|
||||
|
||||
@@ -7,6 +7,10 @@ on:
|
||||
description: 'Docker Image Tag'
|
||||
required: true
|
||||
default: 'dev'
|
||||
platforms:
|
||||
description: 'Build Platforms'
|
||||
required: true
|
||||
default: 'linux/amd64,linux/arm64'
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
@@ -24,9 +28,19 @@ jobs:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
platforms: ${{ github.event.inputs.platforms }}
|
||||
push: true
|
||||
file: ./selfhosted.Dockerfile
|
||||
tags: 'keglin/pinchflat:${{ github.event.inputs.image_tag }}'
|
||||
tags: |
|
||||
keglin/pinchflat:${{ github.event.inputs.image_tag }}
|
||||
ghcr.io/${{ github.repository_owner }}/pinchflat:${{ github.event.inputs.image_tag }}
|
||||
|
||||
@@ -22,42 +22,4 @@ alias Pinchflat.Metadata.MetadataFileHelpers
|
||||
|
||||
alias Pinchflat.SlowIndexing.FileFollowerServer
|
||||
|
||||
defmodule IexHelpers do
|
||||
def playlist_url do
|
||||
"https://www.youtube.com/playlist?list=PLmqC3wPkeL8kSlTCcSMDD63gmSi7evcXS"
|
||||
end
|
||||
|
||||
def channel_url do
|
||||
"https://www.youtube.com/c/TheUselessTrials"
|
||||
end
|
||||
|
||||
def video_url do
|
||||
"https://www.youtube.com/watch?v=bR52O78ZIUw"
|
||||
end
|
||||
|
||||
def last_media_item do
|
||||
Repo.one(from m in MediaItem, limit: 1)
|
||||
end
|
||||
|
||||
def details(type) do
|
||||
source =
|
||||
case type do
|
||||
:playlist -> playlist_url()
|
||||
:channel -> channel_url()
|
||||
end
|
||||
|
||||
YtDlpCollection.get_source_details(source)
|
||||
end
|
||||
|
||||
def ids(type) do
|
||||
source =
|
||||
case type do
|
||||
:playlist -> playlist_url()
|
||||
:channel -> channel_url()
|
||||
end
|
||||
|
||||
YtDlpCollection.get_media_attributes_for_collection(source)
|
||||
end
|
||||
end
|
||||
|
||||
import IexHelpers
|
||||
Pinchflat.Release.check_file_permissions()
|
||||
|
||||
@@ -1,39 +1,144 @@
|
||||
# Pinchflat (Alpha)
|
||||
<p align="center">
|
||||
<img
|
||||
src="priv/static/images/originals/logo-white-wordmark-with-background.png"
|
||||
alt="Pinchflat Logo by @hernandito"
|
||||
width="700"
|
||||
/>
|
||||
</p>
|
||||
|
||||
This is alpha software and anything can break at any time. I make not guarantees about the stability of this software, forward-compatibility of updates, or integrity (both related to and independent of Pinchflat). Essentially, use at your own risk and expect there will be rough edges.
|
||||
<p align="center">
|
||||
<sup>
|
||||
<em>logo by <a href="https://github.com/hernandito" target="_blank">@hernandito</a></em>
|
||||
</sup>
|
||||
</p>
|
||||
|
||||
## What is Pinchflat?
|
||||
# Your next YouTube media manager
|
||||
|
||||
TODO: expand on this.
|
||||
## Table of contents:
|
||||
|
||||
Pinchflat is a lightweight self-contained app for downloading YouTube content. For now, it is not intended as a way to consume content, but instead as a way to download content to disk using specified rules and schedules.
|
||||
- [What it does](#what-it-does)
|
||||
- [Features](#features)
|
||||
- [Screenshots](#screenshots)
|
||||
- [Installation](#installation)
|
||||
- [Unraid](#unraid)
|
||||
- [Docker](#docker)
|
||||
- [Authentication](#authentication)
|
||||
- [Frequently asked questions](https://github.com/kieraneglin/pinchflat/wiki/Frequently-Asked-Questions)
|
||||
- [Documentation](https://github.com/kieraneglin/pinchflat/wiki)
|
||||
- [EFF donations](#eff-donations)
|
||||
- [Pre-release disclaimer](#pre-release-disclaimer)
|
||||
- [Development](#development)
|
||||
|
||||
I have plans for more to come, but for now this is the focus. Think of Pinchflat as nothing more than an automated way to get content from YouTube to your disk.
|
||||
## What it does
|
||||
|
||||
Pinchflat is a self-hosted app for downloading YouTube content built using [yt-dlp](https://github.com/yt-dlp/yt-dlp). It's designed to be lightweight, self-contained, and easy to use. You set up rules for how to download content from YouTube channels or playlists and it'll do the rest, checking periodically for new content. It's perfect for people who want to download content for use in with a media center app (Plex, Jellyfin, Kodi) or for those who want to archive media!
|
||||
|
||||
It's _not_ great for downloading one-off videos - it's built to download large amounts of content and keep it up to date. It's also not meant for consuming content in-app - Pinchflat downloads content to disk where you can then watch it with a media center app or VLC.
|
||||
|
||||
If it doesn't work for your use case, please make a feature request! You can also check out these great alternatives: [Tube Archivist](https://github.com/tubearchivist/tubearchivist), [ytdl-sub](https://github.com/jmbannon/ytdl-sub), and [TubeSync](https://github.com/meeb/tubesync)
|
||||
|
||||
## Features
|
||||
|
||||
- Self-contained - just one Docker container with no external dependencies
|
||||
- Powerful naming system so content is stored where and how you want it
|
||||
- Easy-to-use web interface with presets to get you started right away
|
||||
- First-class support for media center apps like Plex, Jellyfin, and Kodi
|
||||
- Automatically downloads new content from channels and playlists
|
||||
- Uses a novel approach to download new content more quickly than other apps
|
||||
- Supports downloading audio content
|
||||
- Custom rules for handling YouTube Shorts and livestreams
|
||||
- Advanced options like setting cutoff dates and filtering by title
|
||||
- Reliable hands-off operation
|
||||
- Can pass cookies to YouTube to download your private playlists ([docs](https://github.com/kieraneglin/pinchflat/wiki/YouTube-Cookies))
|
||||
|
||||
## Screenshots
|
||||
|
||||
<img src="priv/static/images/app-form-screenshot.png" alt="Pinchflat screenshot" width="700" />
|
||||
<img src="priv/static/images/app-screenshot.png" alt="Pinchflat screenshot" width="700" />
|
||||
|
||||
## Installation
|
||||
|
||||
Pinchflat is designed to be self-hosted. I'm building it for my own needs which means it's designed to work well with Unraid, but it should work on any computer/server that can run Docker images.
|
||||
### Unraid
|
||||
|
||||
I'll update with Unraid instructions once I get something in the Community Apps store. Until then, here's how you build it with Docker:
|
||||
Simply search for Pinchflat in the Community Apps store!
|
||||
|
||||
```bash
|
||||
docker build . --file selfhosted.Dockerfile -t pinchflat:dev
|
||||
### Portainer
|
||||
|
||||
docker run \
|
||||
-p 8945:8945 \
|
||||
-v /Users/work/Desktop/test_volumes/config:/config \
|
||||
-v /Users/work/Desktop/test_volumes/downloads:/downloads \
|
||||
pinchflat:dev
|
||||
Docker Compose file:
|
||||
|
||||
```yaml
|
||||
version: '3'
|
||||
services:
|
||||
pinchflat:
|
||||
image: keglin/pinchflat:latest
|
||||
ports:
|
||||
- '8945:8945'
|
||||
volumes:
|
||||
- /host/path/to/config:/config
|
||||
- /host/path/to/downloads:/downloads
|
||||
```
|
||||
|
||||
## Authentication
|
||||
### Docker
|
||||
|
||||
Currently HTTP basic auth is optionally supported. To use it, set the `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` environment variables when starting the container. If you don't set both of these, no authentication will be required.
|
||||
1. Create two directories on your host machine: one for storing config and one for storing downloaded media. Make sure they're both writable by the user running the Docker container.
|
||||
2. Prepare the docker image in one of the two ways below:
|
||||
- **From GHCR:** `docker pull ghcr.io/kieraneglin/pinchflat:latest`
|
||||
- NOTE: also available on Docker Hub at `keglin/pinchflat:latest`
|
||||
- **Building locally:** `docker build . --file selfhosted.Dockerfile -t ghcr.io/kieraneglin/pinchflat:latest`
|
||||
3. Run the container:
|
||||
|
||||
```bash
|
||||
# Be sure to replace /host/path/to/config and /host/path/to/downloads below with
|
||||
# the paths to the directories you created in step 1
|
||||
docker run \
|
||||
-p 8945:8945 \
|
||||
-v /host/path/to/config:/config \
|
||||
-v /host/path/to/downloads:/downloads \
|
||||
ghcr.io/kieraneglin/pinchflat:latest
|
||||
```
|
||||
|
||||
### IMPORTANT: File permissions
|
||||
|
||||
You _must_ ensure the host directories you've mounted are writable by the user running the Docker container. If you get a permission error follow the steps it suggests. See [#106](https://github.com/kieraneglin/pinchflat/issues/106) for more.
|
||||
|
||||
It's recommended to not run the container as root. Doing so can create permission issues if other apps need to work with the downloaded media. If you need to run any command as root, you can run `su` from the container's shell as there is no password set for the root user.
|
||||
|
||||
## Username and Password
|
||||
|
||||
HTTP basic authentication is optionally supported. To use it, set the `BASIC_AUTH_USERNAME` and `BASIC_AUTH_PASSWORD` environment variables when starting the container. No authentication will be required unless you set _both_ of these.
|
||||
|
||||
## EFF donations
|
||||
|
||||
A portion of all donations to Pinchflat will be donated to the [Electronic Frontier Foundation](https://www.eff.org/). The EFF defends your online liberties and [backed](https://github.com/github/dmca/blob/9a85e0f021f7967af80e186b890776a50443f06c/2020/11/2020-11-16-RIAA-reversal-effletter.pdf) `youtube-dl` when Google took them down. [See here](https://github.com/kieraneglin/pinchflat/wiki/EFF-Donation-Receipts) for a list of donation receipts.
|
||||
|
||||
## Pre-release disclaimer
|
||||
|
||||
This is pre-release software and anything can break at any time. I make not guarantees about the stability of this software, forward-compatibility of updates, or integrity (both related to and independent of Pinchflat). Essentially, use at your own risk and expect there will be rough edges for now.
|
||||
|
||||
## Development
|
||||
|
||||
Pinchflat is written in Elixir - a functional programming language that runs on the Erlang VM. It uses the Phoenix web framework and SQLite for the database. The frontend is mostly normal server-rendered HTML with a little Alpine.js as-needed.
|
||||
|
||||
Elixir is a personal favourite of mine and is ideal for building fault-tolerant systems. It's also a joy to work with and has a great community. If you're interested in contributing, I'd be happy to help you get started with Elixir - just open an issue with some questions and we can chat!
|
||||
|
||||
### Local setup
|
||||
|
||||
- `docker compose build --no-cache`
|
||||
- `docker compose up -d && docker attach pinchflat-phx-1`
|
||||
- After a few minutes the app should be accessible at `localhost:4008`
|
||||
- Please let me know if you run into any hiccups here - I haven't had to bootstrap the app from scratch in a long time and I might have forgotten something
|
||||
- Media downloads and config will be stored in the `tmp` directory. Not the OS's `/tmp` directory, but the one in the root of the project
|
||||
|
||||
### Running tests and linting
|
||||
|
||||
- Open a shell with `docker compose exec phx bash`
|
||||
- Run `mix test` to run the tests
|
||||
- Run `mix check` to do a full testing, linting, and static analysis pass
|
||||
|
||||
### Top tips
|
||||
|
||||
- Look for any module that ends in `*_worker.ex` - these are where the interesting stuff happens and you can trace back from there to see how the app works. `lib/pinchflat/slow_indexing/media_collection_indexing_worker.ex` is a good place to start
|
||||
|
||||
## License
|
||||
|
||||
See `LICENSE` file
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
@@ -16,6 +16,7 @@ config :pinchflat,
|
||||
media_directory: "/downloads",
|
||||
# The user may or may not store metadata for their needs, but the app will always store its copy
|
||||
metadata_directory: "/config/metadata",
|
||||
extras_directory: "/config/extras",
|
||||
tmpfile_directory: Path.join([System.tmp_dir!(), "pinchflat", "data"]),
|
||||
# Setting BASIC_AUTH_USERNAME and BASIC_AUTH_PASSWORD implies you want to use basic auth.
|
||||
# If either is unset, basic auth will not be used.
|
||||
|
||||
@@ -3,6 +3,7 @@ import Config
|
||||
config :pinchflat,
|
||||
media_directory: Path.join([File.cwd!(), "tmp", "media"]),
|
||||
metadata_directory: Path.join([File.cwd!(), "tmp", "metadata"]),
|
||||
extras_directory: Path.join([File.cwd!(), "tmp", "extras"]),
|
||||
tmpfile_directory: Path.join([File.cwd!(), "tmp", "tmpfiles"])
|
||||
|
||||
# Configure your database
|
||||
|
||||
@@ -25,17 +25,27 @@ config :pinchflat,
|
||||
basic_auth_username: System.get_env("BASIC_AUTH_USERNAME"),
|
||||
basic_auth_password: System.get_env("BASIC_AUTH_PASSWORD")
|
||||
|
||||
if config_env() == :prod do
|
||||
config_path =
|
||||
System.get_env("CONFIG_PATH") ||
|
||||
raise """
|
||||
environment variable CONFIG_PATH is missing.
|
||||
For example: /etc/pinchflat/config
|
||||
"""
|
||||
arch_string = to_string(:erlang.system_info(:system_architecture))
|
||||
|
||||
system_arch =
|
||||
cond do
|
||||
String.contains?(arch_string, "arm") -> "arm"
|
||||
String.contains?(arch_string, "aarch") -> "arm"
|
||||
String.contains?(arch_string, "x86") -> "x86"
|
||||
true -> "unknown"
|
||||
end
|
||||
|
||||
config :pinchflat, Pinchflat.Repo,
|
||||
load_extensions: [
|
||||
Path.join([:code.priv_dir(:pinchflat), "repo", "extensions", "sqlean-linux-#{system_arch}", "sqlean"])
|
||||
]
|
||||
|
||||
if config_env() == :prod do
|
||||
config_path = "/config"
|
||||
db_path = System.get_env("DATABASE_PATH", Path.join([config_path, "db", "pinchflat.db"]))
|
||||
log_path = System.get_env("LOG_PATH", Path.join([config_path, "logs", "pinchflat.log"]))
|
||||
metadata_path = System.get_env("METADATA_PATH", Path.join([config_path, "metadata"]))
|
||||
extras_path = System.get_env("EXTRAS_PATH", Path.join([config_path, "extras"]))
|
||||
|
||||
# We want to force _some_ level of useful logging in production
|
||||
acceptable_log_levels = ~w(debug info)a
|
||||
@@ -50,7 +60,10 @@ if config_env() == :prod do
|
||||
|
||||
config :pinchflat,
|
||||
yt_dlp_executable: System.find_executable("yt-dlp"),
|
||||
media_directory: "/downloads",
|
||||
metadata_directory: metadata_path,
|
||||
extras_directory: extras_path,
|
||||
tmpfile_directory: Path.join([System.tmp_dir!(), "pinchflat", "data"]),
|
||||
dns_cluster_query: System.get_env("DNS_CLUSTER_QUERY")
|
||||
|
||||
config :pinchflat, Pinchflat.Repo,
|
||||
|
||||
@@ -18,7 +18,6 @@ defmodule Pinchflat.Boot.DataBackfillWorker do
|
||||
|
||||
alias __MODULE__
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Media.MediaItem
|
||||
|
||||
@doc """
|
||||
Cancels all pending backfill jobs. Useful for ensuring worker runs immediately
|
||||
@@ -44,26 +43,14 @@ defmodule Pinchflat.Boot.DataBackfillWorker do
|
||||
"""
|
||||
def perform(%Oban.Job{}) do
|
||||
Logger.info("Running data backfill worker")
|
||||
backfill_shorts_data()
|
||||
# Nothing to do for now - just reschedule
|
||||
# Keeping in-place because we _will_ need it in the future
|
||||
|
||||
reschedule_backfill()
|
||||
|
||||
:ok
|
||||
end
|
||||
|
||||
defp backfill_shorts_data do
|
||||
query =
|
||||
from(
|
||||
m in MediaItem,
|
||||
where: fragment("? like ?", m.original_url, "%/shorts/%"),
|
||||
where: m.short_form_content == false
|
||||
)
|
||||
|
||||
{count, _} = Repo.update_all(query, set: [short_form_content: true])
|
||||
|
||||
Logger.info("Backfill worker set short_form_content to true for #{count} media items.")
|
||||
end
|
||||
|
||||
defp reschedule_backfill do
|
||||
# Run hourly
|
||||
next_run_in = 60 * 60
|
||||
|
||||
@@ -31,59 +31,38 @@ defmodule Pinchflat.Boot.PreJobStartupTasks do
|
||||
"""
|
||||
@impl true
|
||||
def init(state) do
|
||||
reset_executing_jobs()
|
||||
create_blank_cookie_file()
|
||||
apply_default_settings()
|
||||
ensure_directories_are_writeable()
|
||||
rename_old_job_workers()
|
||||
|
||||
{:ok, state}
|
||||
end
|
||||
|
||||
# If a node cannot gracefully shut down, the currently executing jobs get stuck
|
||||
# in the "executing" state. This is a problem because the job runner will not
|
||||
# pick them up again
|
||||
defp reset_executing_jobs do
|
||||
{count, _} =
|
||||
Oban.Job
|
||||
|> where(state: "executing")
|
||||
|> Repo.update_all(set: [state: "retryable"])
|
||||
|
||||
Logger.info("Reset #{count} executing jobs")
|
||||
end
|
||||
|
||||
defp create_blank_cookie_file do
|
||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||
filepath = Path.join(base_dir, "cookies.txt")
|
||||
|
||||
if !File.exists?(filepath) do
|
||||
Logger.info("Cookies does not exist - creating it")
|
||||
|
||||
FilesystemHelpers.write_p!(filepath, "")
|
||||
end
|
||||
end
|
||||
|
||||
defp apply_default_settings do
|
||||
Settings.fetch!(:onboarding, true)
|
||||
Settings.fetch!(:pro_enabled, false)
|
||||
end
|
||||
|
||||
defp ensure_directories_are_writeable do
|
||||
directories = [
|
||||
Application.get_env(:pinchflat, :media_directory),
|
||||
Application.get_env(:pinchflat, :tmpfile_directory),
|
||||
Application.get_env(:pinchflat, :metadata_directory)
|
||||
]
|
||||
|
||||
Enum.each(directories, fn dir ->
|
||||
file = Path.join([dir, ".keep"])
|
||||
|
||||
# This will fail if the directory is not writeable, stopping boot
|
||||
FilesystemHelpers.write_p!(file, "")
|
||||
end)
|
||||
end
|
||||
|
||||
# As part of a large refactor, I ended up moving a bunch of workers around. This
|
||||
# is a problem because the workers are stored in the database and the runner
|
||||
# will try to run the OLD jobs. This is also why these tasks run before the job
|
||||
# runner starts up.
|
||||
#
|
||||
# Can be removed after a few months (created: 2024-03-12)
|
||||
defp rename_old_job_workers do
|
||||
# [ [old_name, new_name], ...]
|
||||
rename_map = [
|
||||
["Pinchflat.Workers.MediaIndexingWorker", "Pinchflat.FastIndexing.MediaIndexingWorker"],
|
||||
["Pinchflat.Workers.MediaDownloadWorker", "Pinchflat.Downloading.MediaDownloadWorker"],
|
||||
["Pinchflat.Workers.FastIndexingWorker", "Pinchflat.FastIndexing.FastIndexingWorker"],
|
||||
["Pinchflat.Workers.MediaCollectionIndexingWorker", "Pinchflat.SlowIndexing.MediaCollectionIndexingWorker"],
|
||||
["Pinchflat.Workers.DataBackfillWorker", "Pinchflat.Boot.DataBackfillWorker"]
|
||||
]
|
||||
|
||||
jobs_renamed =
|
||||
Enum.reduce(rename_map, 0, fn [old_name, new_name], acc ->
|
||||
{count, _} =
|
||||
Oban.Job
|
||||
|> where(worker: ^old_name)
|
||||
|> Repo.update_all(set: [worker: new_name])
|
||||
|
||||
acc + count
|
||||
end)
|
||||
|
||||
Logger.info("Renamed #{jobs_renamed} old job workers")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,6 +3,7 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
|
||||
Builds the options for yt-dlp to download media based on the given media profile.
|
||||
"""
|
||||
|
||||
alias Pinchflat.Sources.Source
|
||||
alias Pinchflat.Media.MediaItem
|
||||
alias Pinchflat.Downloading.OutputPathBuilder
|
||||
|
||||
@@ -26,6 +27,18 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
|
||||
{:ok, built_options}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Builds the output path for yt-dlp to download media based on the given source's
|
||||
media profile.
|
||||
|
||||
Returns binary()
|
||||
"""
|
||||
def build_output_path_for(%Source{} = source_with_preloads) do
|
||||
output_path_template = source_with_preloads.media_profile.output_path_template
|
||||
|
||||
build_output_path(output_path_template, source_with_preloads)
|
||||
end
|
||||
|
||||
defp default_options do
|
||||
[:no_progress, :windows_filenames]
|
||||
end
|
||||
@@ -104,23 +117,19 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
|
||||
end
|
||||
|
||||
defp output_options(media_item_with_preloads) do
|
||||
output_path_template = media_item_with_preloads.source.media_profile.output_path_template
|
||||
|
||||
[
|
||||
output: build_output_path(output_path_template, media_item_with_preloads)
|
||||
output: build_output_path_for(media_item_with_preloads.source)
|
||||
]
|
||||
end
|
||||
|
||||
defp build_output_path(string, media_item_with_preloads) do
|
||||
additional_options_map = output_options_map(media_item_with_preloads)
|
||||
defp build_output_path(string, source) do
|
||||
additional_options_map = output_options_map(source)
|
||||
{:ok, output_path} = OutputPathBuilder.build(string, additional_options_map)
|
||||
|
||||
Path.join(base_directory(), output_path)
|
||||
end
|
||||
|
||||
defp output_options_map(media_item_with_preloads) do
|
||||
source = media_item_with_preloads.source
|
||||
|
||||
defp output_options_map(source) do
|
||||
%{
|
||||
"source_custom_name" => source.custom_name,
|
||||
"source_collection_type" => source.collection_type
|
||||
@@ -137,7 +146,7 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
|
||||
|> String.split(~r{\.}, include_captures: true)
|
||||
|> List.insert_at(-3, "-thumb")
|
||||
|> Enum.join()
|
||||
|> build_output_path(media_item_with_preloads)
|
||||
|> build_output_path(media_item_with_preloads.source)
|
||||
end
|
||||
|
||||
defp base_directory do
|
||||
|
||||
@@ -56,7 +56,9 @@ defmodule Pinchflat.Downloading.MediaDownloader do
|
||||
|
||||
defp determine_nfo_filepath(media_item, parsed_json) do
|
||||
if media_item.source.media_profile.download_nfo do
|
||||
NfoBuilder.build_and_store_for_media_item(parsed_json)
|
||||
filepath = Path.rootname(parsed_json["filepath"]) <> ".nfo"
|
||||
|
||||
NfoBuilder.build_and_store_for_media_item(filepath, parsed_json)
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
@@ -42,7 +42,8 @@ defmodule Pinchflat.Downloading.OutputPathBuilder do
|
||||
"upload_day" => "%(upload_date>%d)S",
|
||||
"upload_yyyy_mm_dd" => "%(upload_date>%Y-%m-%d)S",
|
||||
"season_from_date" => "%(upload_date>%Y)S",
|
||||
"season_episode_from_date" => "s%(upload_date>%Y)Se%(upload_date>%m%d)S"
|
||||
"season_episode_from_date" => "s%(upload_date>%Y)Se%(upload_date>%m%d)S",
|
||||
"artist_name" => "%(artist,creator,uploader,uploader_id)S"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,6 +20,21 @@ defmodule Pinchflat.Filesystem.FilesystemHelpers do
|
||||
filepath
|
||||
end
|
||||
|
||||
@doc """
|
||||
Writes content to a file, creating directories as needed.
|
||||
Takes the same args as File.write/3.
|
||||
|
||||
Returns :ok | {:error, any()}
|
||||
"""
|
||||
def write_p(file, content, modes \\ []) do
|
||||
dirname = Path.dirname(file)
|
||||
|
||||
case File.mkdir_p(dirname) do
|
||||
:ok -> File.write(file, content, modes)
|
||||
err -> err
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Writes content to a file, creating directories as needed.
|
||||
Takes the same args as File.write!/3.
|
||||
@@ -27,11 +42,20 @@ defmodule Pinchflat.Filesystem.FilesystemHelpers do
|
||||
Returns :ok | raises on error
|
||||
"""
|
||||
def write_p!(filepath, content, modes \\ []) do
|
||||
filepath
|
||||
:ok = write_p(filepath, content, modes)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Copies a file from source to destination, creating directories as needed.
|
||||
|
||||
Returns :ok | raises on error
|
||||
"""
|
||||
def cp_p!(source, destination) do
|
||||
destination
|
||||
|> Path.dirname()
|
||||
|> File.mkdir_p!()
|
||||
|
||||
File.write!(filepath, content, modes)
|
||||
File.cp!(source, destination)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -66,6 +66,7 @@ defmodule Pinchflat.Media do
|
||||
|> where([mi], mi.source_id == ^source.id and is_nil(mi.media_filepath))
|
||||
|> where(^build_format_clauses(media_profile))
|
||||
|> where(^maybe_apply_cutoff_date(source))
|
||||
|> where(^maybe_apply_title_regex(source))
|
||||
|> Repo.maybe_limit(limit)
|
||||
|> Repo.all()
|
||||
end
|
||||
@@ -247,6 +248,14 @@ defmodule Pinchflat.Media do
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_apply_title_regex(source) do
|
||||
if source.title_filter_regex do
|
||||
dynamic([mi], fragment("regexp_like(?, ?)", mi.title, ^source.title_filter_regex))
|
||||
else
|
||||
dynamic(true)
|
||||
end
|
||||
end
|
||||
|
||||
defp build_format_clauses(media_profile) do
|
||||
mapped_struct = Map.from_struct(media_profile)
|
||||
|
||||
|
||||
@@ -11,6 +11,22 @@ defmodule Pinchflat.Metadata.MetadataFileHelpers do
|
||||
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
@doc """
|
||||
Returns the directory where metadata for a database record should be stored.
|
||||
|
||||
Returns binary()
|
||||
"""
|
||||
def metadata_directory_for(database_record) do
|
||||
metadata_directory = Application.get_env(:pinchflat, :metadata_directory)
|
||||
record_table_name = database_record.__meta__.source
|
||||
|
||||
Path.join([
|
||||
metadata_directory,
|
||||
record_table_name,
|
||||
to_string(database_record.id)
|
||||
])
|
||||
end
|
||||
|
||||
@doc """
|
||||
Compresses and stores metadata for a media item, returning the filepath.
|
||||
|
||||
@@ -63,6 +79,43 @@ defmodule Pinchflat.Metadata.MetadataFileHelpers do
|
||||
Date.from_iso8601!("#{year}-#{month}-#{day}")
|
||||
end
|
||||
|
||||
@doc """
|
||||
Attempts to determine the series directory from a media filepath.
|
||||
The series directory is the "root" directory for a given source
|
||||
which should contain all the season-level folders of that source.
|
||||
|
||||
Used for determining where to store things like NFO data and banners
|
||||
for media center apps. Not useful without a media center app.
|
||||
|
||||
Returns {:ok, binary()} | {:error, :indeterminable}
|
||||
"""
|
||||
def series_directory_from_media_filepath(media_filepath) do
|
||||
# Matches "s" or "season" (case-insensitive)
|
||||
# followed by an optional non-word character (. or _ or <space>, etc)
|
||||
# followed by at least one digit
|
||||
# followed immediately by the end of the string
|
||||
# Example matches: s1, s.1, s01 season 1, Season.01, Season_1, Season 1, Season1
|
||||
# Example non-matches: s01e01, season, series 1,
|
||||
season_regex = ~r/^s(eason)?(\W|_)?\d{1,}$/i
|
||||
|
||||
{series_directory, found_series_directory} =
|
||||
media_filepath
|
||||
|> Path.split()
|
||||
|> Enum.reduce_while({[], false}, fn part, {directory_acc, _} ->
|
||||
if String.match?(part, season_regex) do
|
||||
{:halt, {directory_acc, true}}
|
||||
else
|
||||
{:cont, {directory_acc ++ [part], false}}
|
||||
end
|
||||
end)
|
||||
|
||||
if found_series_directory do
|
||||
{:ok, Path.join(series_directory)}
|
||||
else
|
||||
{:error, :indeterminable}
|
||||
end
|
||||
end
|
||||
|
||||
defp fetch_thumbnail_from_url(url) do
|
||||
http_client = Application.get_env(:pinchflat, :http_client, Pinchflat.HTTP.HTTPClient)
|
||||
{:ok, body} = http_client.get(url, [], body_format: :binary)
|
||||
@@ -71,13 +124,8 @@ defmodule Pinchflat.Metadata.MetadataFileHelpers do
|
||||
end
|
||||
|
||||
defp generate_filepath_for(database_record, filename) do
|
||||
metadata_directory = Application.get_env(:pinchflat, :metadata_directory)
|
||||
record_table_name = database_record.__meta__.source
|
||||
|
||||
Path.join([
|
||||
metadata_directory,
|
||||
record_table_name,
|
||||
to_string(database_record.id),
|
||||
metadata_directory_for(database_record),
|
||||
filename
|
||||
])
|
||||
end
|
||||
|
||||
@@ -58,23 +58,35 @@ defmodule Pinchflat.Metadata.MetadataParser do
|
||||
# NOTE: whole ordeal needed due to a bug I found in yt-dlp
|
||||
# https://github.com/yt-dlp/yt-dlp/issues/9445
|
||||
# Can be reverted to remove this entire conditional once fixed
|
||||
%{
|
||||
thumbnail_filepath:
|
||||
filepath =
|
||||
thumbnail_filepath
|
||||
|> String.split(~r{\.}, include_captures: true)
|
||||
|> List.insert_at(-3, "-thumb")
|
||||
|> Enum.join()
|
||||
|
||||
%{
|
||||
thumbnail_filepath: filepath_if_exists(filepath)
|
||||
}
|
||||
else
|
||||
%{
|
||||
thumbnail_filepath: thumbnail_filepath
|
||||
thumbnail_filepath: nil
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
defp parse_infojson_metadata(metadata) do
|
||||
%{
|
||||
metadata_filepath: metadata["infojson_filename"]
|
||||
metadata_filepath: filepath_if_exists(metadata["infojson_filename"])
|
||||
}
|
||||
end
|
||||
|
||||
defp filepath_if_exists(nil), do: nil
|
||||
|
||||
defp filepath_if_exists(filepath) do
|
||||
if File.exists?(filepath) do
|
||||
filepath
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,13 +9,11 @@ defmodule Pinchflat.Metadata.NfoBuilder do
|
||||
|
||||
@doc """
|
||||
Builds an NFO file for a media item (read: single "episode") and
|
||||
stores it in the same directory as the media file. Has the same name
|
||||
as the media file, but with a .nfo extension.
|
||||
stores it at the specified location.
|
||||
|
||||
Returns the filepath of the NFO file.
|
||||
"""
|
||||
def build_and_store_for_media_item(metadata) do
|
||||
filepath = Path.rootname(metadata["filepath"]) <> ".nfo"
|
||||
def build_and_store_for_media_item(filepath, metadata) do
|
||||
nfo = build_for_media_item(metadata)
|
||||
|
||||
FilesystemHelpers.write_p!(filepath, nfo)
|
||||
@@ -23,6 +21,20 @@ defmodule Pinchflat.Metadata.NfoBuilder do
|
||||
filepath
|
||||
end
|
||||
|
||||
@doc """
|
||||
Builds an NFO file for a souce and stores it at the specified location.
|
||||
Technically works for playlists, but it's really made for channels.
|
||||
|
||||
Returns the filepath of the NFO file.
|
||||
"""
|
||||
def build_and_store_for_source(filepath, metadata) do
|
||||
nfo = build_for_source(metadata)
|
||||
|
||||
FilesystemHelpers.write_p!(filepath, nfo)
|
||||
|
||||
filepath
|
||||
end
|
||||
|
||||
defp build_for_media_item(metadata) do
|
||||
upload_date = MetadataFileHelpers.parse_upload_date(metadata["upload_date"])
|
||||
# Cribbed from a combination of the Kodi wiki, ytdl-nfo, and ytdl-sub.
|
||||
@@ -34,11 +46,23 @@ defmodule Pinchflat.Metadata.NfoBuilder do
|
||||
<showtitle>#{metadata["uploader"]}</showtitle>
|
||||
<uniqueid type="youtube" default="true">#{metadata["id"]}</uniqueid>
|
||||
<plot>#{metadata["description"]}</plot>
|
||||
<premiered>#{upload_date}</premiered>
|
||||
<aired>#{upload_date}</aired>
|
||||
<season>#{upload_date.year}</season>
|
||||
<episode>#{Calendar.strftime(upload_date, "%m%d")}</episode>
|
||||
<genre>YouTube</genre>
|
||||
</episodedetails>
|
||||
"""
|
||||
end
|
||||
|
||||
defp build_for_source(metadata) do
|
||||
"""
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||
<tvshow>
|
||||
<title>#{metadata["title"]}</title>
|
||||
<plot>#{metadata["description"]}</plot>
|
||||
<uniqueid type="youtube" default="true">#{metadata["id"]}</uniqueid>
|
||||
<genre>YouTube</genre>
|
||||
</tvshow>
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
defmodule Pinchflat.Metadata.SourceImageParser do
|
||||
@moduledoc """
|
||||
Functions for parsing and storing source images.
|
||||
"""
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
@doc """
|
||||
Given a base directory and source metadata, look for the appropriate images
|
||||
and move them to the base directory. Returns a map of image types and their
|
||||
filepaths (specifically for a source). If a given image type is not found,
|
||||
the key will not be present in the map.
|
||||
|
||||
The metadata is expected to contain the `filepath` key for images, implying
|
||||
that the images have already been downloaded by yt-dlp. This method will NOT
|
||||
download images from the internet - it just copys them around.
|
||||
|
||||
Returns a map with the possible keys :poster_filepath, :fanart_filepath, and
|
||||
:banner_filepath.
|
||||
"""
|
||||
def store_source_images(base_directory, source_metadata) do
|
||||
(source_metadata["thumbnails"] || [])
|
||||
|> Enum.filter(&(&1["filepath"] != nil))
|
||||
|> select_useful_images()
|
||||
|> Enum.map(&move_image(&1, base_directory))
|
||||
|> Enum.into(%{})
|
||||
end
|
||||
|
||||
defp select_useful_images(images) do
|
||||
labelled_images =
|
||||
Enum.reduce(images, [], fn image_map, acc ->
|
||||
case image_map do
|
||||
%{"id" => "avatar_uncropped"} ->
|
||||
acc ++ [{:poster, :poster_filepath, image_map["filepath"]}]
|
||||
|
||||
%{"id" => "banner_uncropped"} ->
|
||||
acc ++ [{:fanart, :fanart_filepath, image_map["filepath"]}]
|
||||
|
||||
_ ->
|
||||
acc
|
||||
end
|
||||
end)
|
||||
|
||||
labelled_images
|
||||
|> Enum.concat([{:banner, :banner_filepath, determine_best_banner(images)}])
|
||||
|> Enum.filter(fn {_, _, tmp_filepath} -> tmp_filepath end)
|
||||
end
|
||||
|
||||
defp determine_best_banner(images) do
|
||||
best_candidate =
|
||||
images
|
||||
# Filter out images that don't have a width and height attribute
|
||||
|> Enum.filter(&(&1["width"] && &1["height"]))
|
||||
# Sort images with the highest width first
|
||||
|> Enum.sort(&(&1["width"] >= &2["width"]))
|
||||
# Find the first image where the ratio of width to height is greater than 3
|
||||
|> Enum.find(&(&1["width"] / &1["height"] > 3))
|
||||
|
||||
Map.get(best_candidate || %{}, "filepath")
|
||||
end
|
||||
|
||||
defp move_image({filename, source_attr_name, tmp_filepath}, base_directory) do
|
||||
extension = Path.extname(tmp_filepath)
|
||||
final_filepath = Path.join([base_directory, "#{filename}#{extension}"])
|
||||
|
||||
FilesystemHelpers.cp_p!(tmp_filepath, final_filepath)
|
||||
|
||||
{source_attr_name, final_filepath}
|
||||
end
|
||||
end
|
||||
@@ -10,11 +10,20 @@ defmodule Pinchflat.Metadata.SourceMetadata do
|
||||
|
||||
alias Pinchflat.Sources.Source
|
||||
|
||||
@allowed_fields ~w(metadata_filepath)a
|
||||
@allowed_fields ~w(
|
||||
metadata_filepath
|
||||
fanart_filepath
|
||||
poster_filepath
|
||||
banner_filepath
|
||||
)a
|
||||
|
||||
@required_fields ~w(metadata_filepath)a
|
||||
|
||||
schema "source_metadata" do
|
||||
field :metadata_filepath, :string
|
||||
field :fanart_filepath, :string
|
||||
field :poster_filepath, :string
|
||||
field :banner_filepath, :string
|
||||
|
||||
belongs_to :source, Source
|
||||
|
||||
@@ -31,6 +40,11 @@ defmodule Pinchflat.Metadata.SourceMetadata do
|
||||
|
||||
@doc false
|
||||
def filepath_attributes do
|
||||
~w(metadata_filepath)a
|
||||
~w(
|
||||
metadata_filepath
|
||||
fanart_filepath
|
||||
poster_filepath
|
||||
banner_filepath
|
||||
)a
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,10 +4,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
||||
use Oban.Worker,
|
||||
queue: :remote_metadata,
|
||||
tags: ["media_source", "source_metadata", "remote_metadata"],
|
||||
max_attempts: 1,
|
||||
# This is the only thing stopping this job from calling itself
|
||||
# in an infinite loop.
|
||||
unique: [period: 600]
|
||||
max_attempts: 3
|
||||
|
||||
require Logger
|
||||
|
||||
@@ -15,8 +12,12 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Tasks
|
||||
alias Pinchflat.Sources
|
||||
alias Pinchflat.Utils.StringUtils
|
||||
alias Pinchflat.Metadata.NfoBuilder
|
||||
alias Pinchflat.YtDlp.MediaCollection
|
||||
alias Pinchflat.Metadata.SourceImageParser
|
||||
alias Pinchflat.Metadata.MetadataFileHelpers
|
||||
alias Pinchflat.Downloading.DownloadOptionBuilder
|
||||
|
||||
@doc """
|
||||
Starts the source metadata storage worker and creates a task for the source.
|
||||
@@ -30,27 +31,84 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
||||
end
|
||||
|
||||
@doc """
|
||||
Fetches and stores metadata for a source in the secret metadata location.
|
||||
Fetches and stores various forms of metadata for a source:
|
||||
- JSON metadata for internal use
|
||||
- The series directory for the source
|
||||
- The NFO file for the source (if specified)
|
||||
- Downloads and stores source images (if specified)
|
||||
|
||||
The worker is kicked off after a source is inserted/updated - this can
|
||||
take an unknown amount of time so don't rely on this data being here
|
||||
before, say, the first indexing or downloading task is complete.
|
||||
|
||||
Returns :ok
|
||||
"""
|
||||
@impl Oban.Worker
|
||||
def perform(%Oban.Job{args: %{"id" => source_id}}) do
|
||||
source = Repo.preload(Sources.get_source!(source_id), :metadata)
|
||||
{:ok, metadata} = MediaCollection.get_source_metadata(source.original_url)
|
||||
source = Repo.preload(Sources.get_source!(source_id), [:metadata, :media_profile])
|
||||
series_directory = determine_series_directory(source)
|
||||
|
||||
# Since updating a source kicks this job off again, we enforce job uniqueness (above)
|
||||
# to once, per source, per x minutes. This is to prevent a job from calling itself
|
||||
# in an infinite loop.
|
||||
Sources.update_source(source, %{
|
||||
metadata: %{
|
||||
metadata_filepath: MetadataFileHelpers.compress_and_store_metadata_for(source, metadata)
|
||||
}
|
||||
})
|
||||
{source_metadata, source_image_attrs, metadata_image_attrs} =
|
||||
fetch_source_metadata_and_images(series_directory, source)
|
||||
|
||||
source_metadata_filepath = MetadataFileHelpers.compress_and_store_metadata_for(source, source_metadata)
|
||||
|
||||
Sources.update_source(
|
||||
source,
|
||||
Map.merge(
|
||||
%{
|
||||
series_directory: series_directory,
|
||||
nfo_filepath: store_source_nfo(source, series_directory, source_metadata),
|
||||
metadata: Map.merge(%{metadata_filepath: source_metadata_filepath}, metadata_image_attrs)
|
||||
},
|
||||
source_image_attrs
|
||||
),
|
||||
# `run_post_commit_tasks: false` prevents this from running in an infinite loop
|
||||
run_post_commit_tasks: false
|
||||
)
|
||||
|
||||
:ok
|
||||
rescue
|
||||
Ecto.NoResultsError -> Logger.info("#{__MODULE__} discarded: source #{source_id} not found")
|
||||
Ecto.StaleEntryError -> Logger.info("#{__MODULE__} discarded: source #{source_id} stale")
|
||||
end
|
||||
|
||||
defp fetch_source_metadata_and_images(series_directory, source) do
|
||||
metadata_directory = MetadataFileHelpers.metadata_directory_for(source)
|
||||
tmp_output_path = "#{tmp_directory()}/#{StringUtils.random_string(16)}/source_image.%(ext)S"
|
||||
opts = [:write_all_thumbnails, convert_thumbnails: "jpg", output: tmp_output_path]
|
||||
|
||||
{:ok, metadata} = MediaCollection.get_source_metadata(source.original_url, opts)
|
||||
metadata_image_attrs = SourceImageParser.store_source_images(metadata_directory, metadata)
|
||||
|
||||
if source.media_profile.download_source_images && series_directory do
|
||||
source_image_attrs = SourceImageParser.store_source_images(series_directory, metadata)
|
||||
|
||||
{metadata, source_image_attrs, metadata_image_attrs}
|
||||
else
|
||||
{metadata, %{}, metadata_image_attrs}
|
||||
end
|
||||
end
|
||||
|
||||
defp determine_series_directory(source) do
|
||||
output_path = DownloadOptionBuilder.build_output_path_for(source)
|
||||
{:ok, %{filepath: filepath}} = MediaCollection.get_source_details(source.original_url, output: output_path)
|
||||
|
||||
case MetadataFileHelpers.series_directory_from_media_filepath(filepath) do
|
||||
{:ok, series_directory} -> series_directory
|
||||
{:error, _} -> nil
|
||||
end
|
||||
end
|
||||
|
||||
defp store_source_nfo(source, series_directory, metadata) do
|
||||
if source.media_profile.download_nfo && series_directory do
|
||||
nfo_filepath = Path.join(series_directory, "tvshow.nfo")
|
||||
|
||||
NfoBuilder.build_and_store_for_source(nfo_filepath, metadata)
|
||||
end
|
||||
end
|
||||
|
||||
defp tmp_directory do
|
||||
Application.get_env(:pinchflat, :tmpfile_directory)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,6 +17,7 @@ defmodule Pinchflat.Profiles.MediaProfile do
|
||||
sub_langs
|
||||
download_thumbnail
|
||||
embed_thumbnail
|
||||
download_source_images
|
||||
download_metadata
|
||||
embed_metadata
|
||||
download_nfo
|
||||
@@ -40,6 +41,7 @@ defmodule Pinchflat.Profiles.MediaProfile do
|
||||
|
||||
field :download_thumbnail, :boolean, default: false
|
||||
field :embed_thumbnail, :boolean, default: false
|
||||
field :download_source_images, :boolean, default: false
|
||||
|
||||
field :download_metadata, :boolean, default: false
|
||||
field :embed_metadata, :boolean, default: false
|
||||
|
||||
@@ -5,6 +5,10 @@ defmodule Pinchflat.Release do
|
||||
"""
|
||||
@app :pinchflat
|
||||
|
||||
require Logger
|
||||
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
def migrate do
|
||||
load_app()
|
||||
|
||||
@@ -18,6 +22,37 @@ defmodule Pinchflat.Release do
|
||||
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
|
||||
end
|
||||
|
||||
def check_file_permissions do
|
||||
load_app()
|
||||
|
||||
directories = [
|
||||
"/config",
|
||||
"/downloads",
|
||||
Application.get_env(:pinchflat, :media_directory),
|
||||
Application.get_env(:pinchflat, :tmpfile_directory),
|
||||
Application.get_env(:pinchflat, :extras_directory),
|
||||
Application.get_env(:pinchflat, :metadata_directory)
|
||||
]
|
||||
|
||||
Enum.each(directories, fn dir ->
|
||||
Logger.info("Checking permissions for #{dir}")
|
||||
filepath = Path.join([dir, ".keep"])
|
||||
|
||||
case FilesystemHelpers.write_p(filepath, "") do
|
||||
:ok ->
|
||||
Logger.info("Permissions OK")
|
||||
|
||||
{:error, :eacces} ->
|
||||
Logger.error(permission_denied_screed(dir))
|
||||
raise "Permission denied"
|
||||
|
||||
err ->
|
||||
Logger.error("Permissions check failed: #{inspect(err)}")
|
||||
raise "Unknown error"
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
defp repos do
|
||||
Application.fetch_env!(@app, :ecto_repos)
|
||||
end
|
||||
@@ -25,4 +60,31 @@ defmodule Pinchflat.Release do
|
||||
defp load_app do
|
||||
Application.load(@app)
|
||||
end
|
||||
|
||||
defp permission_denied_screed(dir) do
|
||||
"""
|
||||
The directory "#{dir}" is not writeable by the Docker container.
|
||||
|
||||
Please ensure that the directory exists and is writeable by the Docker
|
||||
container. All setups are different, but you may be able to run something
|
||||
like this on the *host*:
|
||||
|
||||
chown nobody -R <host path that maps to #{dir}>
|
||||
chmod 755 -R <host path that maps to #{dir}>
|
||||
|
||||
Swapping in your real host path. Then, you should set the user running
|
||||
this container by editing your `docker run` command like so:
|
||||
|
||||
docker run --user 99:100 <rest of the command>
|
||||
|
||||
Or adding `user: '99:100'` to the Pinchflat service of your Docker Compose
|
||||
file. Again, there are many ways to do this depending on your setup and
|
||||
this is just one example. See issue #106 in the Pinchflat Github for more.
|
||||
|
||||
No matter the case, this _is_ a permissions error and allowing the container
|
||||
to write to the directory is the only way to fix it. It is not recommended
|
||||
to run the container as `root` because files created by Pinchflat may not
|
||||
be accessible to other apps that want to modify them.
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ defmodule Pinchflat.SlowIndexing.FileFollowerServer do
|
||||
require Logger
|
||||
|
||||
@poll_interval_ms Application.compile_env(:pinchflat, :file_watcher_poll_interval)
|
||||
@activity_timeout_ms 60_000
|
||||
@activity_timeout_ms 600_000
|
||||
|
||||
# Client API
|
||||
@doc """
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
|
||||
|
||||
require Logger
|
||||
|
||||
alias Pinchflat.Repo
|
||||
alias Pinchflat.Media
|
||||
alias Pinchflat.Tasks
|
||||
alias Pinchflat.Sources
|
||||
@@ -60,6 +61,9 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
|
||||
# See the method definition below for more info on how file watchers work
|
||||
# (important reading if you're not familiar with it)
|
||||
{:ok, media_attributes} = get_media_attributes_for_collection_and_setup_file_watcher(source)
|
||||
# Reload because the source may have been updated during the (long-running) indexing process
|
||||
# and important settings like `download_media` may have changed.
|
||||
source = Repo.reload!(source)
|
||||
|
||||
result =
|
||||
Enum.map(media_attributes, fn media_attrs ->
|
||||
@@ -117,6 +121,10 @@ defmodule Pinchflat.SlowIndexing.SlowIndexingHelpers do
|
||||
end
|
||||
|
||||
defp create_media_item_and_enqueue_download(source, media_attrs) do
|
||||
# Reload because the source may have been updated during the (long-running) indexing process
|
||||
# and important settings like `download_media` may have changed.
|
||||
source = Repo.reload!(source)
|
||||
|
||||
case Media.create_media_item_from_backend_attrs(source, media_attrs) do
|
||||
{:ok, %MediaItem{} = media_item} ->
|
||||
if source.download_media && Media.pending_download?(media_item) do
|
||||
|
||||
@@ -17,12 +17,18 @@ defmodule Pinchflat.Sources.Source do
|
||||
collection_id
|
||||
collection_type
|
||||
custom_name
|
||||
nfo_filepath
|
||||
poster_filepath
|
||||
fanart_filepath
|
||||
banner_filepath
|
||||
series_directory
|
||||
index_frequency_minutes
|
||||
fast_index
|
||||
download_media
|
||||
last_indexed_at
|
||||
original_url
|
||||
download_cutoff_date
|
||||
title_filter_regex
|
||||
media_profile_id
|
||||
)a
|
||||
|
||||
@@ -59,6 +65,13 @@ defmodule Pinchflat.Sources.Source do
|
||||
# Only download media items that were published after this date
|
||||
field :download_cutoff_date, :date
|
||||
field :original_url, :string
|
||||
field :title_filter_regex, :string
|
||||
|
||||
field :series_directory, :string
|
||||
field :nfo_filepath, :string
|
||||
field :poster_filepath, :string
|
||||
field :fanart_filepath, :string
|
||||
field :banner_filepath, :string
|
||||
|
||||
belongs_to :media_profile, MediaProfile
|
||||
|
||||
@@ -85,7 +98,6 @@ defmodule Pinchflat.Sources.Source do
|
||||
|> dynamic_default(:custom_name, fn cs -> get_field(cs, :collection_name) end)
|
||||
|> validate_required(required_fields)
|
||||
|> cast_assoc(:metadata, with: &SourceMetadata.changeset/2, required: false)
|
||||
|> unique_constraint([:collection_id, :media_profile_id])
|
||||
end
|
||||
|
||||
@doc false
|
||||
@@ -99,4 +111,9 @@ defmodule Pinchflat.Sources.Source do
|
||||
# minutes
|
||||
15
|
||||
end
|
||||
|
||||
@doc false
|
||||
def filepath_attributes do
|
||||
~w(nfo_filepath fanart_filepath poster_filepath banner_filepath)a
|
||||
end
|
||||
end
|
||||
|
||||
@@ -51,15 +51,19 @@ defmodule Pinchflat.Sources do
|
||||
though we know it's going to fail so it picks up any addl. database errors
|
||||
and fulfills our return contract.
|
||||
|
||||
You can pass options to control the behavior of the function:
|
||||
- `run_post_commit_tasks` (default: true) - If false, the function will not
|
||||
enqueue any tasks in `commit_and_handle_tasks`.
|
||||
|
||||
Returns {:ok, %Source{}} | {:error, %Ecto.Changeset{}}
|
||||
"""
|
||||
def create_source(attrs) do
|
||||
def create_source(attrs, opts \\ []) do
|
||||
case change_source(%Source{}, attrs, :initial) do
|
||||
%Ecto.Changeset{valid?: true} ->
|
||||
%Source{}
|
||||
|> maybe_change_source_from_url(attrs)
|
||||
|> maybe_change_indexing_frequency()
|
||||
|> commit_and_handle_tasks()
|
||||
|> commit_and_handle_tasks(opts)
|
||||
|
||||
changeset ->
|
||||
Repo.insert(changeset)
|
||||
@@ -79,15 +83,19 @@ defmodule Pinchflat.Sources do
|
||||
though we know it's going to fail so it picks up any addl. database errors
|
||||
and fulfills our return contract.
|
||||
|
||||
You can pass options to control the behavior of the function:
|
||||
- `run_post_commit_tasks` (default: true) - If false, the function will not
|
||||
enqueue any tasks in `commit_and_handle_tasks`.
|
||||
|
||||
Returns {:ok, %Source{}} | {:error, %Ecto.Changeset{}}
|
||||
"""
|
||||
def update_source(%Source{} = source, attrs) do
|
||||
def update_source(%Source{} = source, attrs, opts \\ []) do
|
||||
case change_source(source, attrs, :initial) do
|
||||
%Ecto.Changeset{valid?: true} ->
|
||||
source
|
||||
|> maybe_change_source_from_url(attrs)
|
||||
|> maybe_change_indexing_frequency()
|
||||
|> commit_and_handle_tasks()
|
||||
|> commit_and_handle_tasks(opts)
|
||||
|
||||
changeset ->
|
||||
Repo.update(changeset)
|
||||
@@ -102,7 +110,6 @@ defmodule Pinchflat.Sources do
|
||||
"""
|
||||
def delete_source(%Source{} = source, opts \\ []) do
|
||||
delete_files = Keyword.get(opts, :delete_files, false)
|
||||
|
||||
Tasks.delete_tasks_for(source)
|
||||
|
||||
source
|
||||
@@ -111,7 +118,11 @@ defmodule Pinchflat.Sources do
|
||||
Media.delete_media_item(media_item, delete_files: delete_files)
|
||||
end)
|
||||
|
||||
delete_source_metadata_files(source)
|
||||
if delete_files do
|
||||
delete_source_files(source)
|
||||
end
|
||||
|
||||
delete_internal_metadata_files(source)
|
||||
Repo.delete(source)
|
||||
end
|
||||
|
||||
@@ -134,22 +145,27 @@ defmodule Pinchflat.Sources do
|
||||
end
|
||||
end
|
||||
|
||||
defp delete_source_metadata_files(source) do
|
||||
defp delete_source_files(source) do
|
||||
mapped_struct = Map.from_struct(source)
|
||||
|
||||
Source.filepath_attributes()
|
||||
|> Enum.map(fn field -> mapped_struct[field] end)
|
||||
|> Enum.filter(&is_binary/1)
|
||||
|> Enum.each(&FilesystemHelpers.delete_file_and_remove_empty_directories/1)
|
||||
end
|
||||
|
||||
defp delete_internal_metadata_files(source) do
|
||||
metadata = Repo.preload(source, :metadata).metadata || %SourceMetadata{}
|
||||
mapped_struct = Map.from_struct(metadata)
|
||||
|
||||
filepaths =
|
||||
SourceMetadata.filepath_attributes()
|
||||
|> Enum.map(fn field -> mapped_struct[field] end)
|
||||
|> Enum.filter(&is_binary/1)
|
||||
|
||||
Enum.each(filepaths, &FilesystemHelpers.delete_file_and_remove_empty_directories/1)
|
||||
|> Enum.each(&FilesystemHelpers.delete_file_and_remove_empty_directories/1)
|
||||
end
|
||||
|
||||
defp add_source_details_to_changeset(source, changeset) do
|
||||
%Ecto.Changeset{changes: changes} = changeset
|
||||
|
||||
case MediaCollection.get_source_details(changes.original_url) do
|
||||
case MediaCollection.get_source_details(changeset.changes.original_url) do
|
||||
{:ok, source_details} ->
|
||||
add_source_details_by_collection_type(source, changeset, source_details)
|
||||
|
||||
@@ -198,12 +214,16 @@ defmodule Pinchflat.Sources do
|
||||
end
|
||||
end
|
||||
|
||||
defp commit_and_handle_tasks(changeset) do
|
||||
defp commit_and_handle_tasks(changeset, opts) do
|
||||
run_post_commit_tasks = Keyword.get(opts, :run_post_commit_tasks, true)
|
||||
|
||||
case Repo.insert_or_update(changeset) do
|
||||
{:ok, %Source{} = source} ->
|
||||
if run_post_commit_tasks do
|
||||
maybe_handle_media_tasks(changeset, source)
|
||||
maybe_run_indexing_task(changeset, source)
|
||||
run_metadata_storage_task(source)
|
||||
end
|
||||
|
||||
{:ok, source}
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||
# Also, can't use RAM file since yt-dlp needs a concrete filepath.
|
||||
output_filepath = Keyword.get(addl_opts, :output_filepath, FSUtils.generate_metadata_tmpfile(:json))
|
||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||
formatted_command_opts = [url] ++ parse_options(command_opts ++ print_to_file_opts)
|
||||
cookie_opts = build_cookie_options()
|
||||
formatted_command_opts = [url] ++ parse_options(command_opts ++ print_to_file_opts ++ cookie_opts)
|
||||
|
||||
Logger.info("[yt-dlp] called with: #{Enum.join(formatted_command_opts, " ")}")
|
||||
|
||||
@@ -47,6 +48,19 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||
end
|
||||
end
|
||||
|
||||
defp build_cookie_options do
|
||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||
cookie_file = Path.join(base_dir, "cookies.txt")
|
||||
|
||||
case File.read(cookie_file) do
|
||||
{:ok, cookie_data} ->
|
||||
if String.trim(cookie_data) != "", do: [cookies: cookie_file], else: []
|
||||
|
||||
{:error, _} ->
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
# We want to satisfy the following behaviours:
|
||||
#
|
||||
# 1. If the key is an atom, convert it to a string and convert it to kebab case (for convenience)
|
||||
|
||||
@@ -64,14 +64,14 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
||||
|
||||
Returns {:ok, map()} | {:error, any, ...}.
|
||||
"""
|
||||
def get_source_details(source_url) do
|
||||
def get_source_details(source_url, addl_opts \\ []) do
|
||||
# `ignore_no_formats_error` is necessary because yt-dlp will error out if
|
||||
# the first video has not released yet (ie: is a premier). We don't care about
|
||||
# available formats since we're just getting the source details
|
||||
opts = [:simulate, :skip_download, :ignore_no_formats_error, playlist_end: 1]
|
||||
output_template = "%(.{channel,channel_id,playlist_id,playlist_title})j"
|
||||
command_opts = [:simulate, :skip_download, :ignore_no_formats_error, playlist_end: 1] ++ addl_opts
|
||||
output_template = "%(.{channel,channel_id,playlist_id,playlist_title,filename})j"
|
||||
|
||||
with {:ok, output} <- backend_runner().run(source_url, opts, output_template),
|
||||
with {:ok, output} <- backend_runner().run(source_url, command_opts, output_template),
|
||||
{:ok, parsed_json} <- Phoenix.json_library().decode(output) do
|
||||
{:ok, format_source_details(parsed_json)}
|
||||
else
|
||||
@@ -94,8 +94,8 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
||||
|
||||
Returns {:ok, map()} | {:error, any, ...}.
|
||||
"""
|
||||
def get_source_metadata(source_url) do
|
||||
opts = [playlist_items: 0]
|
||||
def get_source_metadata(source_url, addl_opts \\ []) do
|
||||
opts = [playlist_items: 0] ++ addl_opts
|
||||
output_template = "playlist:%()j"
|
||||
|
||||
with {:ok, output} <- backend_runner().run(source_url, opts, output_template),
|
||||
@@ -112,7 +112,11 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
||||
channel_id: response["channel_id"],
|
||||
channel_name: response["channel"],
|
||||
playlist_id: response["playlist_id"],
|
||||
playlist_name: response["playlist_title"]
|
||||
playlist_name: response["playlist_title"],
|
||||
# It's not a name, it's a path dammit!
|
||||
# This actually isn't used for the inital response - it's
|
||||
# used later to update a source's metadata
|
||||
filepath: response["filename"]
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -31,6 +31,20 @@ defmodule PinchflatWeb.CustomComponents.TextComponents do
|
||||
"""
|
||||
end
|
||||
|
||||
@doc """
|
||||
Renders a subtle link with the given href and content.
|
||||
"""
|
||||
attr :href, :string, required: true
|
||||
slot :inner_block
|
||||
|
||||
def subtle_link(assigns) do
|
||||
~H"""
|
||||
<.link href={@href} class="underline decoration-bodydark decoration-1 hover:decoration-white">
|
||||
<%= render_slot(@inner_block) %>
|
||||
</.link>
|
||||
"""
|
||||
end
|
||||
|
||||
@doc """
|
||||
Renders an icon as a link with the given href.
|
||||
"""
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<div class="flex h-screen overflow-hidden">
|
||||
<div class="relative flex flex-1 flex-col overflow-y-auto overflow-x-hidden">
|
||||
<header class="sticky top-0 z-999 flex w-full bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
|
||||
<div class="flex flex-grow items-center px-4 py-4 shadow-2 md:px-6 2xl:px-11">
|
||||
<div class="flex items-center">
|
||||
<img src={~p"/images/logo.png?cachebust=2024-02-29"} alt="Pinchflat" class="w-9 h-9" />
|
||||
<h2 class="text-xl font-bold text-white pl-2">Pinchflat</h2>
|
||||
<div class="w-65 px-4 py-2 shadow-2 md:px-6">
|
||||
<div class="flex items-center gap-2 py-2">
|
||||
<img src={~p"/images/logo.png?cachebust=2024-03-20"} alt="Pinchflat" class="w-auto" />
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
<header class="sticky top-0 z-999 flex w-full bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
|
||||
<header class="sticky top-0 z-999 flex h-20 w-full bg-white drop-shadow-1 dark:bg-boxdark dark:drop-shadow-none">
|
||||
<div class="flex flex-grow items-center justify-between lg:justify-end px-4 py-4 shadow-2 md:px-6 2xl:px-11">
|
||||
<div class="flex items-center gap-2 sm:gap-4 lg:hidden">
|
||||
<div class="flex items-center gap-2 sm:gap-4 lg:hidden w-2/6">
|
||||
<section class="pr-1">
|
||||
<img src={~p"/images/icon.png?cachebust=2024-03-20"} alt="Pinchflat" class="w-10" />
|
||||
</section>
|
||||
|
||||
<button
|
||||
class="z-99999 block rounded-sm border border-stroke bg-white p-1.5 shadow-sm dark:border-strokedark dark:bg-boxdark lg:hidden"
|
||||
class="z-99999 block mx-2 rounded-sm border border-stroke bg-white p-1.5 shadow-sm dark:border-strokedark dark:bg-boxdark lg:hidden"
|
||||
@click.stop="sidebarVisible = !sidebarVisible"
|
||||
>
|
||||
<.icon name="hero-bars-3" />
|
||||
</button>
|
||||
<a class="hidden sm:flex items-center lg:hidden" href="/">
|
||||
<img src={~p"/images/logo.png?cachebust=2024-02-29"} alt="Pinchflat" class="w-9 h-9" />
|
||||
<h2 class="text-xl font-bold text-white pl-2">Pinchflat</h2>
|
||||
</a>
|
||||
</div>
|
||||
<div class="bg-meta-4 rounded-md">
|
||||
<div class="bg-meta-4 rounded-md w-4/6 lg:w-3/6 xl:w-2/6">
|
||||
<div class="relative">
|
||||
<span class="absolute left-2 top-1/2 -translate-y-1/2 flex">
|
||||
<.icon name="hero-magnifying-glass" />
|
||||
@@ -23,7 +23,7 @@
|
||||
name="q"
|
||||
value={@params["q"]}
|
||||
placeholder="Type to search..."
|
||||
class="w-full bg-transparent pl-9 pr-4 border-0 focus:ring-0 focus:outline-none lg:w-125"
|
||||
class="w-full bg-transparent pl-9 pr-4 border-0 focus:ring-0 focus:outline-none"
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -1,24 +1,23 @@
|
||||
<aside
|
||||
x-bind:class="sidebarVisible ? 'translate-x-0' : '-translate-x-full'"
|
||||
class={[
|
||||
"-translate-x-full absolute left-0 top-0 z-9999 flex h-screen w-60 flex-col overflow-y-hidden justify-between",
|
||||
"-translate-x-full absolute left-0 top-0 z-9999 flex h-screen w-65 flex-col overflow-y-hidden justify-between",
|
||||
"bg-black duration-300 ease-linear shadow-lg sm:shadow-none dark:bg-boxdark lg:static lg:translate-x-0"
|
||||
]}
|
||||
@click.outside="sidebarVisible = false"
|
||||
>
|
||||
<section>
|
||||
<div class="flex items-center justify-between gap-2 px-6 py-5.5 lg:py-6.5">
|
||||
<div class="flex items-center justify-between gap-2 px-6 py-4">
|
||||
<a href="/" class="flex items-center">
|
||||
<img src={~p"/images/logo.png?cachebust=2024-02-29"} alt="Pinchflat" class="w-9 h-9" />
|
||||
<h2 class="text-xl font-bold text-white pl-2">Pinchflat</h2>
|
||||
<img src={~p"/images/logo.png?cachebust=2024-03-20"} alt="Pinchflat" class="w-auto" />
|
||||
</a>
|
||||
|
||||
<button class="block lg:hidden" @click.stop="sidebarVisible = !sidebarVisible">
|
||||
<button class="block mt-3 lg:hidden" @click.stop="sidebarVisible = !sidebarVisible">
|
||||
<.icon name="hero-arrow-left" class="fill-current" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="no-scrollbar flex flex-col overflow-y-auto duration-300 ease-linear">
|
||||
<nav class="mt-5 px-4 py-4 lg:mt-9 lg:px-6">
|
||||
<nav class="mt-3 px-4 py-4 lg:px-6">
|
||||
<h3 class="mb-4 ml-4 text-sm font-medium text-bodydark2">MENU</h3>
|
||||
<div class="flex flex-col justify-between">
|
||||
<ul class="mb-6 flex flex-col gap-1.5">
|
||||
@@ -31,8 +30,14 @@
|
||||
</div>
|
||||
</section>
|
||||
<section>
|
||||
<nav class="mt-5 px-4 py-4 lg:mt-9 lg:px-6">
|
||||
<nav class="px-4 py-4 lg:px-6">
|
||||
<ul class="mb-6 flex flex-col gap-1.5">
|
||||
<.sidebar_item
|
||||
icon="hero-book-open"
|
||||
text="Docs"
|
||||
target="_blank"
|
||||
href="https://github.com/kieraneglin/pinchflat/wiki"
|
||||
/>
|
||||
<.sidebar_item
|
||||
icon="hero-code-bracket"
|
||||
text="Github"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<%= assigns[:page_title] || "Pinchflat" %>
|
||||
</.live_title>
|
||||
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
|
||||
<link rel="icon" type="image/x-icon" href={~p"/favicon.ico?cachebust=2024-02-29"} />
|
||||
<link rel="icon" type="image/x-icon" href={~p"/favicon.ico?cachebust=2024-03-20"} />
|
||||
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
|
||||
</script>
|
||||
</head>
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
method="delete"
|
||||
data-confirm="Are you sure you want to delete this record and all associated files on disk? This cannot be undone."
|
||||
>
|
||||
<.button color="bg-meta-1" rounding="rounded-full">
|
||||
<.button color="bg-meta-1" rounding="rounded-lg">
|
||||
Delete Files
|
||||
</.button>
|
||||
</.link>
|
||||
|
||||
@@ -39,7 +39,8 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
||||
upload_year: nil,
|
||||
upload_yyyy_mm_dd: "the upload date in the format YYYY-MM-DD",
|
||||
source_custom_name: "the name of the sources that use this profile",
|
||||
source_collection_type: "the collection type of the sources that use this profile. Either 'channel' or 'playlist'"
|
||||
source_collection_type: "the collection type of the sources using this profile. Either 'channel' or 'playlist'",
|
||||
artist_name: "the name of the artist with fallbacks to other uploader fields"
|
||||
}
|
||||
end
|
||||
|
||||
@@ -74,6 +75,6 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
||||
end
|
||||
|
||||
defp audio_output_template do
|
||||
"/music/{{ source_custom_name }}/{{ title }}.{{ ext }}"
|
||||
"/music/{{ artist_name }}/{{ title }}.{{ ext }}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
<.link href={~p"/media_profiles"}>
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">Edit Media Profile</h2>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">
|
||||
Editing "<%= @media_profile.name %>"
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div class="rounded-sm border border-stroke bg-white px-5 pb-2.5 pt-6 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5 xl:pb-1">
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
</h2>
|
||||
<nav>
|
||||
<.link href={~p"/media_profiles/new"}>
|
||||
<.button color="bg-primary" rounding="rounded-full">
|
||||
<.button color="bg-primary" rounding="rounded-lg">
|
||||
<span class="font-bold text-xl mx-2">+</span> New <span class="hidden sm:inline pl-1">Media Profile</span>
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -16,10 +16,9 @@
|
||||
<div class="flex flex-col gap-10 min-w-max">
|
||||
<.table rows={@media_profiles} table_class="text-black dark:text-white">
|
||||
<:col :let={media_profile} label="Name">
|
||||
<.subtle_link href={~p"/media_profiles/#{media_profile.id}"}>
|
||||
<%= media_profile.name %>
|
||||
</:col>
|
||||
<:col :let={media_profile} label="Output Template">
|
||||
<code class="text-sm"><%= media_profile.output_path_template %></code>
|
||||
</.subtle_link>
|
||||
</:col>
|
||||
<:col :let={media_profile} label="Preferred Resolution">
|
||||
<%= media_profile.preferred_resolution %>
|
||||
|
||||
@@ -162,16 +162,6 @@
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section x-data="{ presets: { default: false, media_center: true, audio: false, archiving: true } }">
|
||||
<.input
|
||||
field={f[:download_nfo]}
|
||||
type="toggle"
|
||||
label="Download NFO data"
|
||||
help="Downloads NFO data alongside media file for use with Jellyfin, Kodi, etc."
|
||||
x-init="$watch('selectedPreset', p => p && (enabled = presets[p]))"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<h3 class="mt-10 text-2xl text-black dark:text-white">
|
||||
Release Format Options
|
||||
</h3>
|
||||
@@ -181,7 +171,7 @@
|
||||
field={f[:shorts_behaviour]}
|
||||
options={friendly_format_type_options()}
|
||||
type="select"
|
||||
label="Include Shorts?"
|
||||
label="Include Shorts"
|
||||
help="Experimental. Please report any issues on GitHub"
|
||||
x-init="$watch('selectedPreset', p => p && ($el.value = presets[p]))"
|
||||
/>
|
||||
@@ -192,7 +182,7 @@
|
||||
field={f[:livestream_behaviour]}
|
||||
options={friendly_format_type_options()}
|
||||
type="select"
|
||||
label="Include Livestreams?"
|
||||
label="Include Livestreams"
|
||||
help="Excludes media that comes from a past livestream"
|
||||
x-init="$watch('selectedPreset', p => p && ($el.value = presets[p]))"
|
||||
/>
|
||||
@@ -213,7 +203,42 @@
|
||||
/>
|
||||
</section>
|
||||
|
||||
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto">Save Media profile</.button>
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Media Center Options
|
||||
</h3>
|
||||
<p class="text-sm mt-2 max-w-prose">
|
||||
Everything in this section is experimental - please open a GitHub issue if you see something odd.
|
||||
<strong>
|
||||
These options only work if this Media Profile's output template is set to split media into seasons.
|
||||
</strong>
|
||||
Try the "Media Center" preset if you're not sure.
|
||||
</p>
|
||||
|
||||
<section
|
||||
phx-click={show_modal("upgrade-modal")}
|
||||
x-data="{ presets: { default: false, media_center: true, audio: false, archiving: false } }"
|
||||
>
|
||||
<.input
|
||||
field={f[:download_nfo]}
|
||||
type="toggle"
|
||||
label="Download NFO data"
|
||||
label_suffix="(pro)"
|
||||
help="Downloads NFO data alongside media file for use with Jellyfin, Kodi, etc."
|
||||
x-init="$watch('selectedPreset', p => p && (enabled = presets[p]))"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section x-data="{ presets: { default: false, media_center: true, audio: false, archiving: true } }">
|
||||
<.input
|
||||
field={f[:download_source_images]}
|
||||
type="toggle"
|
||||
label="Download Series Images"
|
||||
help="Downloads poster and banner images for use with Plex, Jellyfin, Kodi, etc. Only works for full channels (not playlists)"
|
||||
x-init="$watch('selectedPreset', p => p && (enabled = presets[p]))"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Media profile</.button>
|
||||
</section>
|
||||
|
||||
<div class="rounded-sm dark:bg-meta-4 p-4 md:p-6 mb-5">
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-2">
|
||||
Media Profile <span class="hidden sm:inline">#<%= @media_profile.id %></span>
|
||||
<%= @media_profile.name %>
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<.link href={~p"/media_profiles/#{@media_profile}/edit"}>
|
||||
<.button color="bg-primary" rounding="rounded-full">
|
||||
<.button color="bg-primary" rounding="rounded-lg">
|
||||
<.icon name="hero-pencil-square" class="mr-2" />Edit <span class="hidden sm:inline pl-1">Media Profile</span>
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -31,7 +31,7 @@
|
||||
method="delete"
|
||||
data-confirm="Are you sure you want to delete this profile and all its sources (leaving files in place)? This cannot be undone."
|
||||
>
|
||||
<.button color="bg-meta-1" rounding="rounded-full">
|
||||
<.button color="bg-meta-1" rounding="rounded-lg">
|
||||
Delete Profile and its Sources
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -41,7 +41,7 @@
|
||||
data-confirm="Are you sure you want to delete this profile, all its sources, and its files on disk? This cannot be undone."
|
||||
class="mt-5 md:mt-0"
|
||||
>
|
||||
<.button color="bg-meta-1" rounding="rounded-full">
|
||||
<.button color="bg-meta-1" rounding="rounded-lg">
|
||||
Delete Profile, Sources, and Files
|
||||
</.button>
|
||||
</.link>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<p class="text-md text-bodydark">Don't worry, you can create more Media Profiles later!</p>
|
||||
<div class="mt-8">
|
||||
<.link href={~p"/media_profiles/new"}>
|
||||
<.button color="bg-primary" rounding="rounded-full" disabled={@media_profiles_exist}>
|
||||
<.button color="bg-primary" rounding="rounded-lg" disabled={@media_profiles_exist}>
|
||||
<span class="font-bold mx-2">+</span> New Media Profile
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -25,7 +25,7 @@
|
||||
</p>
|
||||
<div class="mt-8">
|
||||
<.link href={~p"/sources/new"}>
|
||||
<.button color="bg-primary" rounding="rounded-full" disabled={not @media_profiles_exist}>
|
||||
<.button color="bg-primary" rounding="rounded-lg" disabled={not @media_profiles_exist}>
|
||||
<span class="font-bold mx-2">+</span> New Source
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -40,7 +40,7 @@
|
||||
<p class="text-md text-bodydark">Feel free to add more Media Profiles or Sources in the meantime!</p>
|
||||
<div class="mt-8">
|
||||
<.link href={~p"/?onboarding=0"}>
|
||||
<.button color="bg-primary" rounding="rounded-full" disabled={not @sources_exist}>
|
||||
<.button color="bg-primary" rounding="rounded-lg" disabled={not @sources_exist}>
|
||||
Let's Go <span class="font-bold mx-2">🚀</span>
|
||||
</.button>
|
||||
</.link>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="mb-6 flex gap-3 flex-row items-center justify-between">
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white">
|
||||
<span class="hidden sm:inline">Search </span>Results for "<%= StringUtils.truncate(@search_term, 50) %>"
|
||||
Results for "<%= StringUtils.truncate(@search_term, 50) %>"
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<%= if match?([_|_], @search_results) do %>
|
||||
<.table rows={@search_results} table_class="text-black dark:text-white">
|
||||
<:col :let={result} label="Title">
|
||||
<%= StringUtils.truncate(result.title, 40) %>
|
||||
<%= result.title %>
|
||||
</:col>
|
||||
<:col :let={result} label="Excerpt">
|
||||
<.highlight_search_terms text={result.matching_search_term} />
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
<.link href={~p"/sources"}>
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">Edit Source</h2>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">
|
||||
Editing "<%= @source.custom_name %>"
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<div class="rounded-sm border border-stroke bg-white px-5 pb-2.5 pt-6 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5 xl:pb-1">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white">Sources</h2>
|
||||
<nav>
|
||||
<.link href={~p"/sources/new"}>
|
||||
<.button color="bg-primary" rounding="rounded-full">
|
||||
<.button color="bg-primary" rounding="rounded-lg">
|
||||
<span class="font-bold mx-2">+</span> New <span class="hidden sm:inline pl-1">Source</span>
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -14,19 +14,18 @@
|
||||
<div class="flex flex-col gap-10 min-w-max">
|
||||
<.table rows={@sources} table_class="text-black dark:text-white">
|
||||
<:col :let={source} label="Name">
|
||||
<.subtle_link href={~p"/sources/#{source.id}"}>
|
||||
<%= source.custom_name || source.collection_name %>
|
||||
</.subtle_link>
|
||||
</:col>
|
||||
<:col :let={source} label="Type"><%= source.collection_type %></:col>
|
||||
<:col :let={source} label="Should Download?">
|
||||
<.icon name={if source.download_media, do: "hero-check", else: "hero-x-mark"} />
|
||||
</:col>
|
||||
<:col :let={source} label="Media Profile">
|
||||
<.link
|
||||
href={~p"/media_profiles/#{source.media_profile_id}"}
|
||||
class="hover:text-secondary duration-200 ease-in-out"
|
||||
>
|
||||
<.subtle_link href={~p"/media_profiles/#{source.media_profile_id}"}>
|
||||
<%= source.media_profile.name %>
|
||||
</.link>
|
||||
</.subtle_link>
|
||||
</:col>
|
||||
<:col :let={source} label="" class="flex place-content-evenly">
|
||||
<.icon_link href={~p"/sources/#{source.id}"} icon="hero-eye" class="mx-1" />
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
|
||||
</.link>
|
||||
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">
|
||||
Source <span class="hidden sm:inline">#<%= @source.id %></span>
|
||||
<%= @source.custom_name %>
|
||||
</h2>
|
||||
</div>
|
||||
|
||||
<nav>
|
||||
<.link href={~p"/sources/#{@source}/edit"}>
|
||||
<.button color="bg-primary" rounding="rounded-full">
|
||||
<.button color="bg-primary" rounding="rounded-lg">
|
||||
<.icon name="hero-pencil-square" class="mr-2" /> Edit <span class="hidden sm:inline pl-1">Source</span>
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -38,7 +38,7 @@
|
||||
method="delete"
|
||||
data-confirm="Are you sure you want to delete this source (leaving files in place)? This cannot be undone."
|
||||
>
|
||||
<.button color="bg-meta-1" rounding="rounded-full">
|
||||
<.button color="bg-meta-1" rounding="rounded-lg">
|
||||
Delete Source
|
||||
</.button>
|
||||
</.link>
|
||||
@@ -48,7 +48,7 @@
|
||||
data-confirm="Are you sure you want to delete this source and it's files on disk? This cannot be undone."
|
||||
class="mt-5 md:mt-0"
|
||||
>
|
||||
<.button color="bg-meta-1" rounding="rounded-full">
|
||||
<.button color="bg-meta-1" rounding="rounded-lg">
|
||||
Delete Source and Files
|
||||
</.button>
|
||||
</.link>
|
||||
|
||||
@@ -1,11 +1,22 @@
|
||||
<.simple_form :let={f} for={@changeset} action={@action}>
|
||||
<.simple_form
|
||||
:let={f}
|
||||
for={@changeset}
|
||||
action={@action}
|
||||
x-data="{ advancedMode: !!JSON.parse(localStorage.getItem('advancedMode')) }"
|
||||
x-init="$watch('advancedMode', value => localStorage.setItem('advancedMode', JSON.stringify(value)))"
|
||||
>
|
||||
<.error :if={@changeset.action}>
|
||||
Oops, something went wrong! Please check the errors below.
|
||||
</.error>
|
||||
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
<section class="flex justify-between items-center mt-8">
|
||||
<h3 class=" text-2xl text-black dark:text-white">
|
||||
General Options
|
||||
</h3>
|
||||
<span class="cursor-pointer hover:underline" x-on:click="advancedMode = !advancedMode">
|
||||
Editing Mode: <span x-text="advancedMode ? 'Advanced' : 'Basic'"></span>
|
||||
</span>
|
||||
</section>
|
||||
|
||||
<.input
|
||||
field={f[:custom_name]}
|
||||
@@ -41,7 +52,7 @@
|
||||
<.input
|
||||
field={f[:fast_index]}
|
||||
type="toggle"
|
||||
label="Use Fast Indexing?"
|
||||
label="Use Fast Indexing"
|
||||
label_suffix="(pro)"
|
||||
help="Experimental. Ignores 'Index Frequency'. Recommended for large channels that upload frequently. See below for more info"
|
||||
/>
|
||||
@@ -54,7 +65,7 @@
|
||||
<.input
|
||||
field={f[:download_media]}
|
||||
type="toggle"
|
||||
label="Download Media?"
|
||||
label="Download Media"
|
||||
help="Unchecking still indexes media but it won't be downloaded until you enable this option"
|
||||
/>
|
||||
|
||||
@@ -69,7 +80,24 @@
|
||||
help="Only download media uploaded after this date. Leave blank to download all media. Must be in YYYY-MM-DD format"
|
||||
/>
|
||||
|
||||
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto">Save Source</.button>
|
||||
<section x-show="advancedMode">
|
||||
<h3 class="mt-8 text-2xl text-black dark:text-white">
|
||||
Advanced Options
|
||||
</h3>
|
||||
<p class="text-sm mt-2">
|
||||
Tread carefully
|
||||
</p>
|
||||
|
||||
<.input
|
||||
field={f[:title_filter_regex]}
|
||||
type="text"
|
||||
label="Title Filter Regex"
|
||||
placeholder="(?i)^How to Bike$"
|
||||
help="A PCRE-compatible regex. Only media with titles that match this regex will be downloaded. Look up 'SQLean Regex docs' for more"
|
||||
/>
|
||||
</section>
|
||||
|
||||
<.button class="my-10 sm:mb-7.5 w-full sm:w-auto" rounding="rounded-lg">Save Source</.button>
|
||||
|
||||
<div class="rounded-sm dark:bg-meta-4 p-4 md:p-6 mb-5">
|
||||
<.fast_indexing_help />
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule Pinchflat.MixProject do
|
||||
def project do
|
||||
[
|
||||
app: :pinchflat,
|
||||
version: "0.1.0-alpha.5",
|
||||
version: "0.1.2",
|
||||
elixir: "~> 1.16",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
start_permanent: Mix.env() == :prod,
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule Pinchflat.Repo.Migrations.AddNfoPathToSources do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:sources) do
|
||||
add :nfo_filepath, :string
|
||||
add :series_directory, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
defmodule Pinchflat.Repo.Migrations.AddSourcePhotosFields do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:sources) do
|
||||
add :fanart_filepath, :string
|
||||
add :poster_filepath, :string
|
||||
add :banner_filepath, :string
|
||||
end
|
||||
|
||||
alter table(:media_profiles) do
|
||||
add :download_source_images, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
defmodule Pinchflat.Repo.Migrations.AddTitleRegexToSource do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:sources) do
|
||||
add :title_filter_regex, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
defmodule Pinchflat.Repo.Migrations.RemoveUniqueIndexFromSources do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
drop unique_index(:sources, [:collection_id, :media_profile_id])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
defmodule Pinchflat.Repo.Migrations.AddImageAttrsToSourceMetadata do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:source_metadata) do
|
||||
add :fanart_filepath, :string
|
||||
add :poster_filepath, :string
|
||||
add :banner_filepath, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 164 KiB |
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
cd -P -- "$(dirname -- "$0")"
|
||||
exec ./pinchflat eval Pinchflat.Release.check_file_permissions
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/bin/sh
|
||||
/app/bin/check_file_permissions
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Filesystem error. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
/app/bin/migrate
|
||||
|
||||
cd -P -- "$(dirname -- "$0")"
|
||||
|
||||
@@ -39,6 +39,7 @@ RUN mix local.hex --force && \
|
||||
|
||||
# set build ENV
|
||||
ENV MIX_ENV="prod"
|
||||
ENV ERL_FLAGS="+JPperf true"
|
||||
|
||||
# install mix dependencies
|
||||
COPY mix.exs mix.lock ./
|
||||
@@ -76,7 +77,7 @@ FROM ${RUNNER_IMAGE}
|
||||
|
||||
RUN apt-get update -y
|
||||
RUN apt-get install -y libstdc++6 openssl libncurses5 locales ca-certificates \
|
||||
ffmpeg curl git openssh-client
|
||||
ffmpeg curl git openssh-client nano
|
||||
RUN apt-get clean && rm -f /var/lib/apt/lists/*_*
|
||||
|
||||
# Download and update YT-DLP
|
||||
@@ -100,7 +101,6 @@ RUN chown nobody /config /downloads
|
||||
|
||||
# set runner ENV
|
||||
ENV MIX_ENV="prod"
|
||||
ENV CONFIG_PATH="/config"
|
||||
ENV PORT=8945
|
||||
ENV RUN_CONTEXT="selfhosted"
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
defmodule Pinchflat.Boot.DataBackfillWorkerTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
import Pinchflat.MediaFixtures
|
||||
|
||||
alias Pinchflat.Boot.DataBackfillWorker
|
||||
alias Pinchflat.JobFixtures.TestJobWorker
|
||||
|
||||
@@ -45,26 +43,4 @@ defmodule Pinchflat.Boot.DataBackfillWorkerTest do
|
||||
assert_enqueued(worker: DataBackfillWorker, scheduled_at: now_plus(60, :minutes))
|
||||
end
|
||||
end
|
||||
|
||||
describe "perform/1 when testing backfill_shorts_data" do
|
||||
test "sets short_form_content to true for media items with shorts in the URL" do
|
||||
media_item = media_item_with_attachments(%{original_url: "https://example.com/shorts/123"})
|
||||
|
||||
refute media_item.short_form_content
|
||||
|
||||
perform_job(DataBackfillWorker, %{})
|
||||
|
||||
assert Repo.reload!(media_item).short_form_content
|
||||
end
|
||||
|
||||
test "does not set short_form_content to true for media items without shorts in the URL" do
|
||||
media_item = media_item_with_attachments(%{original_url: "https://example.com/longs/123"})
|
||||
|
||||
refute media_item.short_form_content
|
||||
|
||||
perform_job(DataBackfillWorker, %{})
|
||||
|
||||
refute Repo.reload!(media_item).short_form_content
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
||||
use Pinchflat.DataCase
|
||||
import Pinchflat.MediaFixtures
|
||||
import Pinchflat.ProfilesFixtures
|
||||
import Pinchflat.SourcesFixtures
|
||||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Downloading.DownloadOptionBuilder
|
||||
@@ -222,6 +222,14 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "build_output_path_for/1" do
|
||||
test "builds an output path for a source", %{media_item: media_item} do
|
||||
path = DownloadOptionBuilder.build_output_path_for(media_item.source)
|
||||
|
||||
assert path == "/tmp/test/media/%(title)S.%(ext)s"
|
||||
end
|
||||
end
|
||||
|
||||
defp update_media_profile_attribute(media_item_with_preloads, attrs) do
|
||||
media_item_with_preloads.source.media_profile
|
||||
|> Profiles.change_media_profile(attrs)
|
||||
|
||||
@@ -58,7 +58,7 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||
|
||||
describe "download_for_media_item/3 when testing media_item attributes" do
|
||||
setup do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
{:ok, render_metadata(:media_metadata)}
|
||||
end)
|
||||
|
||||
@@ -73,7 +73,7 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||
|
||||
test "it extracts the title", %{media_item: media_item} do
|
||||
assert {:ok, updated_media_item} = MediaDownloader.download_for_media_item(media_item)
|
||||
assert updated_media_item.title == "Trying to Wheelie Without the Rear Brake"
|
||||
assert updated_media_item.title == "Pinchflat Example Video"
|
||||
end
|
||||
|
||||
test "it extracts the description", %{media_item: media_item} do
|
||||
@@ -94,15 +94,44 @@ defmodule Pinchflat.Downloading.MediaDownloaderTest do
|
||||
end
|
||||
|
||||
test "it extracts the thumbnail_filepath", %{media_item: media_item} do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
metadata = render_parsed_metadata(:media_metadata)
|
||||
|
||||
thumbnail_filepath =
|
||||
metadata["thumbnails"]
|
||||
|> Enum.reverse()
|
||||
|> Enum.find_value(fn attrs -> attrs["filepath"] end)
|
||||
|> String.split(~r{\.}, include_captures: true)
|
||||
|> List.insert_at(-3, "-thumb")
|
||||
|> Enum.join()
|
||||
|
||||
:ok = File.cp(thumbnail_filepath_fixture(), thumbnail_filepath)
|
||||
|
||||
{:ok, Phoenix.json_library().encode!(metadata)}
|
||||
end)
|
||||
|
||||
assert media_item.thumbnail_filepath == nil
|
||||
assert {:ok, updated_media_item} = MediaDownloader.download_for_media_item(media_item)
|
||||
assert String.ends_with?(updated_media_item.thumbnail_filepath, ".webp")
|
||||
|
||||
File.rm(updated_media_item.thumbnail_filepath)
|
||||
end
|
||||
|
||||
test "it extracts the metadata_filepath", %{media_item: media_item} do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
metadata = render_parsed_metadata(:media_metadata)
|
||||
|
||||
infojson_filepath = metadata["infojson_filename"]
|
||||
:ok = File.cp(infojson_filepath_fixture(), infojson_filepath)
|
||||
|
||||
{:ok, Phoenix.json_library().encode!(metadata)}
|
||||
end)
|
||||
|
||||
assert media_item.metadata_filepath == nil
|
||||
assert {:ok, updated_media_item} = MediaDownloader.download_for_media_item(media_item)
|
||||
assert String.ends_with?(updated_media_item.metadata_filepath, ".info.json")
|
||||
|
||||
File.rm(updated_media_item.metadata_filepath)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -34,6 +34,29 @@ defmodule Pinchflat.Filesystem.FilesystemHelpersTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "write_p/3" do
|
||||
test "writes content to a file" do
|
||||
filepath = FilesystemHelpers.generate_metadata_tmpfile(:json)
|
||||
content = "{}"
|
||||
|
||||
assert :ok = FilesystemHelpers.write_p(filepath, content)
|
||||
assert File.read!(filepath) == content
|
||||
|
||||
File.rm!(filepath)
|
||||
end
|
||||
|
||||
test "creates directories as needed" do
|
||||
tmpfile_directory = Application.get_env(:pinchflat, :tmpfile_directory)
|
||||
filepath = Path.join([tmpfile_directory, "foo", "bar", "file.json"])
|
||||
content = "{}"
|
||||
|
||||
assert :ok = FilesystemHelpers.write_p(filepath, content)
|
||||
assert File.read!(filepath) == content
|
||||
|
||||
File.rm!(filepath)
|
||||
end
|
||||
end
|
||||
|
||||
describe "write_p!/3" do
|
||||
test "writes content to a file" do
|
||||
filepath = FilesystemHelpers.generate_metadata_tmpfile(:json)
|
||||
@@ -107,4 +130,37 @@ defmodule Pinchflat.Filesystem.FilesystemHelpersTest do
|
||||
assert {:error, _} = FilesystemHelpers.delete_file_and_remove_empty_directories(filepath)
|
||||
end
|
||||
end
|
||||
|
||||
describe "cp_p!/2" do
|
||||
test "copies a file from source to destination" do
|
||||
source = "#{tmpfile_directory()}/source.json"
|
||||
FilesystemHelpers.write_p!(source, "TEST")
|
||||
destination = "#{tmpfile_directory()}/destination.json"
|
||||
|
||||
refute File.exists?(destination)
|
||||
FilesystemHelpers.cp_p!(source, destination)
|
||||
assert File.exists?(destination)
|
||||
assert File.read!(destination) == "TEST"
|
||||
|
||||
File.rm!(source)
|
||||
File.rm!(destination)
|
||||
end
|
||||
|
||||
test "creates directories as needed" do
|
||||
source = "#{tmpfile_directory()}/source.json"
|
||||
FilesystemHelpers.write_p!(source, "TEST")
|
||||
destination = "#{tmpfile_directory()}/foo/bar/destination.json"
|
||||
|
||||
refute File.exists?(destination)
|
||||
FilesystemHelpers.cp_p!(source, destination)
|
||||
assert File.exists?(destination)
|
||||
|
||||
File.rm!(source)
|
||||
File.rm!(destination)
|
||||
end
|
||||
end
|
||||
|
||||
defp tmpfile_directory do
|
||||
Application.get_env(:pinchflat, :tmpfile_directory)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -239,6 +239,26 @@ defmodule Pinchflat.MediaTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_pending_media_items_for/1 when testing title regex" do
|
||||
test "returns only media items that match the title regex" do
|
||||
source = source_fixture(%{title_filter_regex: "(?i)^FOO$"})
|
||||
|
||||
matching_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "foo"})
|
||||
_non_matching_media_item = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "bar"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [matching_media_item]
|
||||
end
|
||||
|
||||
test "does not apply a regex if none is specified" do
|
||||
source = source_fixture(%{title_filter_regex: nil})
|
||||
|
||||
media_item_one = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "foo"})
|
||||
media_item_two = media_item_fixture(%{source_id: source.id, media_filepath: nil, title: "bar"})
|
||||
|
||||
assert Media.list_pending_media_items_for(source) == [media_item_one, media_item_two]
|
||||
end
|
||||
end
|
||||
|
||||
describe "list_downloaded_media_items_for/1" do
|
||||
test "returns only media items with a media_filepath" do
|
||||
source = source_fixture()
|
||||
|
||||
@@ -92,4 +92,62 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
|
||||
assert Helpers.parse_upload_date(upload_date) == ~D[2021-01-01]
|
||||
end
|
||||
end
|
||||
|
||||
describe "series_directory_from_media_filepath/1" do
|
||||
test "returns base series directory if filepaths are setup as expected" do
|
||||
good_filepaths = [
|
||||
"/media/season1/episode.mp4",
|
||||
"/media/season 1/episode.mp4",
|
||||
"/media/season.1/episode.mp4",
|
||||
"/media/season_1/episode.mp4",
|
||||
"/media/season-1/episode.mp4",
|
||||
"/media/SEASON 1/episode.mp4",
|
||||
"/media/SEASON.1/episode.mp4",
|
||||
"/media/s1/episode.mp4",
|
||||
"/media/s.1/episode.mp4",
|
||||
"/media/s_1/episode.mp4",
|
||||
"/media/s-1/episode.mp4",
|
||||
"/media/s 1/episode.mp4",
|
||||
"/media/S1/episode.mp4",
|
||||
"/media/S.1/episode.mp4"
|
||||
]
|
||||
|
||||
for filepath <- good_filepaths do
|
||||
assert {:ok, "/media"} = Helpers.series_directory_from_media_filepath(filepath)
|
||||
end
|
||||
end
|
||||
|
||||
test "returns an error if the season filepath can't be determined" do
|
||||
bad_filepaths = [
|
||||
"/media/1/episode.mp4",
|
||||
"/media/(s1)/episode.mp4",
|
||||
"/media/episode.mp4",
|
||||
"/media/s1e1/episode.mp4",
|
||||
"/media/s1 e1/episode.mp4",
|
||||
"/media/s1 (something else)/episode.mp4",
|
||||
"/media/season1e1/episode.mp4",
|
||||
"/media/season1 e1/episode.mp4",
|
||||
"/media/seasoning1/episode.mp4",
|
||||
"/media/season/episode.mp4",
|
||||
"/media/series1/episode.mp4",
|
||||
"/media/s/episode.mp4",
|
||||
"/media/foo",
|
||||
"/media/bar/"
|
||||
]
|
||||
|
||||
for filepath <- bad_filepaths do
|
||||
assert {:error, :indeterminable} = Helpers.series_directory_from_media_filepath(filepath)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "metadata_directory_for/1" do
|
||||
test "returns the metadata directory for the given record", %{media_item: media_item} do
|
||||
base_metadata_directory = Application.get_env(:pinchflat, :metadata_directory)
|
||||
|
||||
metadata_directory = Helpers.metadata_directory_for(media_item)
|
||||
|
||||
assert metadata_directory == Path.join([base_metadata_directory, "media_items", "#{media_item.id}"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
defmodule Pinchflat.Metadata.MetadataParserTest do
|
||||
use Pinchflat.DataCase
|
||||
import Pinchflat.MediaFixtures
|
||||
|
||||
alias Pinchflat.Metadata.MetadataParser, as: Parser
|
||||
|
||||
@@ -11,7 +12,7 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
|
||||
test "it extracts the media filepath", %{metadata: metadata} do
|
||||
result = Parser.parse_for_media_item(metadata)
|
||||
|
||||
assert String.contains?(result.media_filepath, "bwRHIkYqYJo")
|
||||
assert String.contains?(result.media_filepath, "Pinchflat Example Video-ABC123")
|
||||
assert String.ends_with?(result.media_filepath, ".mkv")
|
||||
end
|
||||
|
||||
@@ -88,6 +89,22 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
|
||||
end
|
||||
|
||||
describe "parse_for_media_item/1 when testing thumbnail metadata" do
|
||||
setup %{metadata: metadata} do
|
||||
thumbnail_filepath =
|
||||
metadata["thumbnails"]
|
||||
|> Enum.reverse()
|
||||
|> Enum.find_value(fn attrs -> attrs["filepath"] end)
|
||||
|> String.split(~r{\.}, include_captures: true)
|
||||
|> List.insert_at(-3, "-thumb")
|
||||
|> Enum.join()
|
||||
|
||||
:ok = File.cp(thumbnail_filepath_fixture(), thumbnail_filepath)
|
||||
|
||||
on_exit(fn -> File.rm(thumbnail_filepath) end)
|
||||
|
||||
{:ok, filepath: thumbnail_filepath}
|
||||
end
|
||||
|
||||
test "extracts the thumbnail filepath", %{metadata: metadata} do
|
||||
result = Parser.parse_for_media_item(metadata)
|
||||
|
||||
@@ -103,6 +120,14 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
|
||||
assert String.contains?(result.thumbnail_filepath, "-thumb.webp")
|
||||
end
|
||||
|
||||
test "doesn't include thumbnail if the file doesn't exist on-disk", %{metadata: metadata, filepath: filepath} do
|
||||
File.rm(filepath)
|
||||
|
||||
result = Parser.parse_for_media_item(metadata)
|
||||
|
||||
assert result.thumbnail_filepath == nil
|
||||
end
|
||||
|
||||
test "doesn't freak out if the media has no thumbnails", %{metadata: metadata} do
|
||||
metadata = Map.put(metadata, "thumbnails", %{})
|
||||
|
||||
@@ -121,12 +146,29 @@ defmodule Pinchflat.Metadata.MetadataParserTest do
|
||||
end
|
||||
|
||||
describe "parse_for_media_item/1 when testing infojson metadata" do
|
||||
setup %{metadata: metadata} do
|
||||
infojson_filepath = metadata["infojson_filename"]
|
||||
:ok = File.cp(infojson_filepath_fixture(), infojson_filepath)
|
||||
|
||||
on_exit(fn -> File.rm(infojson_filepath) end)
|
||||
|
||||
{:ok, filepath: infojson_filepath}
|
||||
end
|
||||
|
||||
test "extracts the metadata filepath", %{metadata: metadata} do
|
||||
result = Parser.parse_for_media_item(metadata)
|
||||
|
||||
assert String.ends_with?(result.metadata_filepath, ".info.json")
|
||||
end
|
||||
|
||||
test "doesn't include metadata if the file doesn't exist on-disk", %{metadata: metadata, filepath: filepath} do
|
||||
File.rm(filepath)
|
||||
|
||||
result = Parser.parse_for_media_item(metadata)
|
||||
|
||||
assert result.metadata_filepath == nil
|
||||
end
|
||||
|
||||
test "doesn't freak out if the media has no infojson", %{metadata: metadata} do
|
||||
metadata = Map.put(metadata, "infojson_filename", nil)
|
||||
|
||||
|
||||
@@ -2,37 +2,49 @@ defmodule Pinchflat.Metadata.NfoBuilderTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
alias Pinchflat.Metadata.NfoBuilder
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
setup do
|
||||
{:ok, %{metadata: render_parsed_metadata(:media_metadata)}}
|
||||
filepath = FilesystemHelpers.generate_metadata_tmpfile(:json)
|
||||
|
||||
on_exit(fn -> File.rm!(filepath) end)
|
||||
|
||||
{:ok,
|
||||
%{
|
||||
metadata: render_parsed_metadata(:media_metadata),
|
||||
filepath: filepath
|
||||
}}
|
||||
end
|
||||
|
||||
describe "build_and_store_for_media_item/1" do
|
||||
test "returns the filepath", %{metadata: metadata} do
|
||||
result = NfoBuilder.build_and_store_for_media_item(metadata)
|
||||
describe "build_and_store_for_media_item/2" do
|
||||
test "returns the filepath", %{metadata: metadata, filepath: filepath} do
|
||||
result = NfoBuilder.build_and_store_for_media_item(filepath, metadata)
|
||||
|
||||
assert File.exists?(result)
|
||||
|
||||
File.rm!(result)
|
||||
end
|
||||
|
||||
test "builds filepath based on media location", %{metadata: metadata} do
|
||||
result = NfoBuilder.build_and_store_for_media_item(metadata)
|
||||
|
||||
assert String.contains?(result, Path.rootname(metadata["filepath"]))
|
||||
assert String.ends_with?(result, ".nfo")
|
||||
|
||||
File.rm!(result)
|
||||
end
|
||||
|
||||
test "builds an NFO file", %{metadata: metadata} do
|
||||
result = NfoBuilder.build_and_store_for_media_item(metadata)
|
||||
test "builds an NFO file", %{metadata: metadata, filepath: filepath} do
|
||||
result = NfoBuilder.build_and_store_for_media_item(filepath, metadata)
|
||||
nfo = File.read!(result)
|
||||
|
||||
assert String.contains?(nfo, ~S(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>))
|
||||
assert String.contains?(nfo, "<title>#{metadata["title"]}</title>")
|
||||
end
|
||||
end
|
||||
|
||||
File.rm!(result)
|
||||
describe "build_and_store_for_source/2" do
|
||||
test "returns the filepath", %{metadata: metadata, filepath: filepath} do
|
||||
result = NfoBuilder.build_and_store_for_source(filepath, metadata)
|
||||
|
||||
assert File.exists?(result)
|
||||
end
|
||||
|
||||
test "builds an NFO file", %{metadata: metadata, filepath: filepath} do
|
||||
result = NfoBuilder.build_and_store_for_source(filepath, metadata)
|
||||
nfo = File.read!(result)
|
||||
|
||||
assert String.contains?(nfo, ~S(<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>))
|
||||
assert String.contains?(nfo, "<title>#{metadata["title"]}</title>")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
defmodule Pinchflat.Metadata.SourceImageParserTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
alias Pinchflat.Metadata.SourceImageParser
|
||||
|
||||
@base_dir Application.compile_env(:pinchflat, :tmpfile_directory)
|
||||
|
||||
describe "store_source_images/2" do
|
||||
test "returns a map of image types and locations" do
|
||||
metadata = render_parsed_metadata(:channel_source_metadata)
|
||||
|
||||
expected = %{
|
||||
banner_filepath: "#{@base_dir}/banner.jpg",
|
||||
fanart_filepath: "#{@base_dir}/fanart.jpg",
|
||||
poster_filepath: "#{@base_dir}/poster.jpg"
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == expected
|
||||
end
|
||||
|
||||
test "returns the avatar_uncropped as the poster" do
|
||||
metadata = %{
|
||||
"thumbnails" => [
|
||||
%{"id" => "avatar_uncropped", "filepath" => "/app/test/support/files/channel_photos/a.0.jpg"}
|
||||
]
|
||||
}
|
||||
|
||||
expected = %{
|
||||
poster_filepath: "#{@base_dir}/poster.jpg"
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == expected
|
||||
end
|
||||
|
||||
test "returns the banner_uncropped as the fanart" do
|
||||
metadata = %{
|
||||
"thumbnails" => [
|
||||
%{"id" => "banner_uncropped", "filepath" => "/app/test/support/files/channel_photos/a.0.jpg"}
|
||||
]
|
||||
}
|
||||
|
||||
expected = %{
|
||||
fanart_filepath: "#{@base_dir}/fanart.jpg"
|
||||
}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == expected
|
||||
end
|
||||
|
||||
test "doesn't return a banner if no suitable images are found" do
|
||||
metadata = %{
|
||||
"thumbnails" => [
|
||||
%{
|
||||
"id" => "1",
|
||||
"filepath" => "foo.jpg",
|
||||
"width" => 100,
|
||||
"height" => 100
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
expected = %{}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == expected
|
||||
end
|
||||
|
||||
test "doesn't blow up if empty metadata is passed" do
|
||||
metadata = %{}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == %{}
|
||||
end
|
||||
|
||||
test "doesn't blow up if no thumbnails are passed" do
|
||||
metadata = %{"thumbnails" => []}
|
||||
|
||||
assert SourceImageParser.store_source_images(@base_dir, metadata) == %{}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,10 +2,15 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
use Pinchflat.DataCase
|
||||
import Mox
|
||||
import Pinchflat.SourcesFixtures
|
||||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Sources
|
||||
alias Pinchflat.Metadata.MetadataFileHelpers
|
||||
alias Pinchflat.Metadata.SourceMetadataStorageWorker
|
||||
|
||||
@source_details_ot "%(.{channel,channel_id,playlist_id,playlist_title,filename})j"
|
||||
@metadata_ot "playlist:%()j"
|
||||
|
||||
setup :verify_on_exit!
|
||||
|
||||
describe "kickoff_with_task/1" do
|
||||
@@ -27,11 +32,33 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
end
|
||||
|
||||
describe "perform/1" do
|
||||
test "won't call itself in an infinite loop" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot -> {:ok, source_details_return_fixture()}
|
||||
_url, _opts, ot when ot == @metadata_ot -> {:ok, "{}"}
|
||||
end)
|
||||
|
||||
source = source_fixture()
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
|
||||
assert [] = all_enqueued(worker: SourceMetadataStorageWorker)
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(SourceMetadataStorageWorker, %{id: 0})
|
||||
end
|
||||
end
|
||||
|
||||
describe "perform/1 when testing metadata storage" do
|
||||
test "sets metadata location for source" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "{}"} end)
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot -> {:ok, source_details_return_fixture()}
|
||||
_url, _opts, ot when ot == @metadata_ot -> {:ok, "{}"}
|
||||
end)
|
||||
|
||||
source = Repo.preload(source_fixture(), :metadata)
|
||||
|
||||
refute source.metadata
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.preload(Repo.reload(source), :metadata)
|
||||
|
||||
@@ -43,7 +70,11 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
test "fetches and stores returned metadata for source" do
|
||||
source = source_fixture()
|
||||
file_contents = Phoenix.json_library().encode!(%{"title" => "test"})
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, file_contents} end)
|
||||
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot -> {:ok, source_details_return_fixture()}
|
||||
_url, _opts, ot when ot == @metadata_ot -> {:ok, file_contents}
|
||||
end)
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.preload(Repo.reload(source), :metadata)
|
||||
@@ -52,31 +83,215 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
assert metadata == %{"title" => "test"}
|
||||
end
|
||||
|
||||
test "won't call itself in an infinite loop" do
|
||||
stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "{}"} end)
|
||||
test "sets metadata image location for source" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot -> {:ok, source_details_return_fixture()}
|
||||
_url, _opts, ot when ot == @metadata_ot -> {:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
source = source_fixture()
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.preload(Repo.reload(source), :metadata)
|
||||
|
||||
assert source.metadata.fanart_filepath
|
||||
assert source.metadata.poster_filepath
|
||||
assert source.metadata.banner_filepath
|
||||
|
||||
Sources.delete_source(source, delete_files: true)
|
||||
end
|
||||
|
||||
test "stores metadata images for source" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot -> {:ok, source_details_return_fixture()}
|
||||
_url, _opts, ot when ot == @metadata_ot -> {:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
source = source_fixture()
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.preload(Repo.reload(source), :metadata)
|
||||
|
||||
assert [_] = all_enqueued(worker: SourceMetadataStorageWorker)
|
||||
assert File.exists?(source.metadata.fanart_filepath)
|
||||
assert File.exists?(source.metadata.poster_filepath)
|
||||
assert File.exists?(source.metadata.banner_filepath)
|
||||
|
||||
Sources.delete_source(source, delete_files: true)
|
||||
end
|
||||
end
|
||||
|
||||
test "doesn't prevent over source jobs from running" do
|
||||
stub(YtDlpRunnerMock, :run, fn _url, _opts, _ot -> {:ok, "{}"} end)
|
||||
source_1 = source_fixture()
|
||||
source_2 = source_fixture()
|
||||
describe "perform/1 when testing source image downloading" do
|
||||
test "downloads and stores source images" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "Season 1", "bar.mp4"])
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source_1.id})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source_1.id})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source_2.id})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source_2.id})
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
assert [_, _] = all_enqueued(worker: SourceMetadataStorageWorker)
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_source_images: true})
|
||||
source = source_fixture(media_profile_id: profile.id)
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
assert source.fanart_filepath
|
||||
assert source.poster_filepath
|
||||
assert source.banner_filepath
|
||||
|
||||
assert File.exists?(source.fanart_filepath)
|
||||
assert File.exists?(source.poster_filepath)
|
||||
assert File.exists?(source.banner_filepath)
|
||||
|
||||
Sources.delete_source(source, delete_files: true)
|
||||
end
|
||||
|
||||
test "does not blow up if the record doesn't exist" do
|
||||
assert :ok = perform_job(SourceMetadataStorageWorker, %{id: 0})
|
||||
test "does not store source images if the profile is not set to" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "Season 1", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_source_images: false})
|
||||
source = source_fixture(media_profile_id: profile.id)
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
refute source.fanart_filepath
|
||||
refute source.poster_filepath
|
||||
refute source.banner_filepath
|
||||
end
|
||||
|
||||
test "does not store source images if the series directory cannot be determined" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "foo", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, render_metadata(:channel_source_metadata)}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_source_images: true})
|
||||
source = source_fixture(media_profile_id: profile.id)
|
||||
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
refute source.fanart_filepath
|
||||
refute source.poster_filepath
|
||||
refute source.banner_filepath
|
||||
end
|
||||
end
|
||||
|
||||
describe "perform/1 when determining the series_directory" do
|
||||
test "sets the series directory based on the returned media filepath" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "Season 1", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, "{}"}
|
||||
end)
|
||||
|
||||
source = source_fixture(%{series_directory: nil})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
assert source.series_directory
|
||||
end
|
||||
|
||||
test "does not set the series directory if it cannot be determined" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "foo", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, "{}"}
|
||||
end)
|
||||
|
||||
source = source_fixture(%{series_directory: nil})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
refute source.series_directory
|
||||
end
|
||||
end
|
||||
|
||||
describe "perform/1 when storing the series NFO" do
|
||||
test "stores the NFO if specified" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "Season 1", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, "{}"}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_nfo: true})
|
||||
source = source_fixture(%{nfo_filepath: nil, media_profile_id: profile.id})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
assert source.nfo_filepath
|
||||
assert source.nfo_filepath == Path.join([source.series_directory, "tvshow.nfo"])
|
||||
assert File.exists?(source.nfo_filepath)
|
||||
|
||||
File.rm!(source.nfo_filepath)
|
||||
end
|
||||
|
||||
test "does not store the NFO if not specified" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "Season 1", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, "{}"}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_nfo: false})
|
||||
source = source_fixture(%{nfo_filepath: nil, media_profile_id: profile.id})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
refute source.nfo_filepath
|
||||
end
|
||||
|
||||
test "does not store the NFO if the series directory cannot be determined" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
_url, _opts, ot when ot == @source_details_ot ->
|
||||
filename = Path.join([Application.get_env(:pinchflat, :media_directory), "foo", "bar.mp4"])
|
||||
|
||||
{:ok, source_details_return_fixture(%{filename: filename})}
|
||||
|
||||
_url, _opts, ot when ot == @metadata_ot ->
|
||||
{:ok, "{}"}
|
||||
end)
|
||||
|
||||
profile = media_profile_fixture(%{download_nfo: true})
|
||||
source = source_fixture(%{nfo_filepath: nil, media_profile_id: profile.id})
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.reload(source)
|
||||
|
||||
refute source.nfo_filepath
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||