Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fc8eed8b50 | |||
| f42aab286a | |||
| bf11cd0dd9 | |||
| e051a37f0d | |||
| 64ebf756ab | |||
| 377bc617ea | |||
| a03f69a8d4 | |||
| d39ebe7ac1 | |||
| 8b5dcc15d6 | |||
| 5e58dcd879 | |||
| a9d5407071 | |||
| 37c1da8014 | |||
| 937a14985f | |||
| a6a20c111f | |||
| 2bb96edc00 | |||
| 87f07ff634 | |||
| dd60cb5419 | |||
| 610b00566b | |||
| aba15ed886 | |||
| 87da716fdf | |||
| 45f056c6e0 | |||
| 11d160008c | |||
| ba0a1ba100 | |||
| 8c51a286c9 | |||
| 46c27e4875 | |||
| b639918555 | |||
| 5596351f58 | |||
| ad150b6f16 |
@@ -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()
|
||||
|
||||
@@ -14,46 +14,131 @@
|
||||
|
||||
# Your next YouTube media manager
|
||||
|
||||
## Disclaimer
|
||||
## Table of contents:
|
||||
|
||||
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.
|
||||
- [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)
|
||||
|
||||
## EFF Donation Receipts
|
||||
## What it does
|
||||
|
||||
A portion of all donations to Pinchflat will be donated to the Electronic Frontier Foundation. [See here](https://github.com/kieraneglin/pinchflat/wiki/EFF-Donation-Receipts) for a list of donation receipts.
|
||||
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!
|
||||
|
||||
## What is Pinchflat?
|
||||
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.
|
||||
|
||||
TODO: expand on this.
|
||||
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)
|
||||
|
||||
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.
|
||||
## Features
|
||||
|
||||
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.
|
||||
- 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
|
||||
|
||||
@@ -41,16 +41,11 @@ config :pinchflat, Pinchflat.Repo,
|
||||
]
|
||||
|
||||
if config_env() == :prod do
|
||||
config_path =
|
||||
System.get_env("CONFIG_PATH") ||
|
||||
raise """
|
||||
environment variable CONFIG_PATH is missing.
|
||||
For example: /etc/pinchflat/config
|
||||
"""
|
||||
|
||||
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
|
||||
@@ -65,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,
|
||||
@@ -104,7 +102,7 @@ if config_env() == :prod do
|
||||
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
|
||||
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
|
||||
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
|
||||
ip: {0, 0, 0, 0, 0, 0, 0, 0},
|
||||
ip: {0, 0, 0, 0},
|
||||
port: String.to_integer(System.get_env("PORT") || "4000")
|
||||
],
|
||||
secret_key_base: secret_key_base
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,7 @@ defmodule Pinchflat.Filesystem.FilesystemHelpers do
|
||||
Returns :ok | raises on error
|
||||
"""
|
||||
def write_p!(filepath, content, modes \\ []) do
|
||||
filepath
|
||||
|> Path.dirname()
|
||||
|> File.mkdir_p!()
|
||||
|
||||
File.write!(filepath, content, modes)
|
||||
:ok = write_p(filepath, content, modes)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -108,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,38 @@ 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
|
||||
|
||||
# NOTE: this should not be needed, but it is due to a bug in yt-dlp.
|
||||
# Can remove once this is resolved:
|
||||
# https://github.com/yt-dlp/yt-dlp/issues/9445#issuecomment-2018724344
|
||||
defp filepath_if_exists(nil), do: nil
|
||||
|
||||
defp filepath_if_exists(filepath) do
|
||||
if File.exists?(filepath) do
|
||||
filepath
|
||||
else
|
||||
nil
|
||||
end
|
||||
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
|
||||
|
||||
@@ -32,6 +32,7 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
||||
|
||||
@doc """
|
||||
Fetches and stores various forms of metadata for a source:
|
||||
- Attributes like `description`
|
||||
- JSON metadata for internal use
|
||||
- The series directory for the source
|
||||
- The NFO file for the source (if specified)
|
||||
@@ -47,21 +48,24 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
||||
def perform(%Oban.Job{args: %{"id" => source_id}}) do
|
||||
source = Repo.preload(Sources.get_source!(source_id), [:metadata, :media_profile])
|
||||
series_directory = determine_series_directory(source)
|
||||
{source_metadata, image_filepath_attrs} = fetch_source_metadata_and_images(series_directory, source)
|
||||
|
||||
# `run_post_commit_tasks: false` prevents this from running in an infinite loop
|
||||
{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: %{
|
||||
metadata_filepath: MetadataFileHelpers.compress_and_store_metadata_for(source, source_metadata)
|
||||
}
|
||||
description: source_metadata["description"],
|
||||
metadata: Map.merge(%{metadata_filepath: source_metadata_filepath}, metadata_image_attrs)
|
||||
},
|
||||
image_filepath_attrs
|
||||
source_image_attrs
|
||||
),
|
||||
# `run_post_commit_tasks: false` prevents this from running in an infinite loop
|
||||
run_post_commit_tasks: false
|
||||
)
|
||||
|
||||
@@ -72,18 +76,19 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorker do
|
||||
end
|
||||
|
||||
defp fetch_source_metadata_and_images(series_directory, source) do
|
||||
if source.media_profile.download_source_images && series_directory do
|
||||
output_path = "#{tmp_directory()}/#{StringUtils.random_string(16)}/source_image.%(ext)S"
|
||||
opts = [:write_all_thumbnails, convert_thumbnails: "jpg", output: output_path]
|
||||
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)
|
||||
image_attrs = SourceImageParser.store_source_images(series_directory, metadata)
|
||||
metadata_image_attrs = SourceImageParser.store_source_images(metadata_directory, metadata)
|
||||
|
||||
{metadata, image_attrs}
|
||||
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
|
||||
{:ok, metadata} = MediaCollection.get_source_metadata(source.original_url, [])
|
||||
|
||||
{metadata, %{}}
|
||||
{metadata, %{}, metadata_image_attrs}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -17,6 +17,7 @@ defmodule Pinchflat.Sources.Source do
|
||||
collection_id
|
||||
collection_type
|
||||
custom_name
|
||||
description
|
||||
nfo_filepath
|
||||
poster_filepath
|
||||
fanart_filepath
|
||||
@@ -55,6 +56,7 @@ defmodule Pinchflat.Sources.Source do
|
||||
|
||||
schema "sources" do
|
||||
field :custom_name, :string
|
||||
field :description, :string
|
||||
field :collection_name, :string
|
||||
field :collection_id, :string
|
||||
field :collection_type, Ecto.Enum, values: [:channel, :playlist]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -32,6 +32,12 @@
|
||||
<section>
|
||||
<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"
|
||||
@@ -51,6 +57,11 @@
|
||||
<.icon name="hero-currency-dollar" /> Donate
|
||||
</span>
|
||||
</li>
|
||||
<li>
|
||||
<span class="group relative flex items-center gap-2.5 px-4 py-2 text-sm">
|
||||
v<%= Application.spec(:pinchflat)[:vsn] %>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</section>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -233,7 +233,7 @@
|
||||
field={f[:download_source_images]}
|
||||
type="toggle"
|
||||
label="Download Series Images"
|
||||
help="Downloads poster and banner images for use with Jellyfin, Kodi, etc. Only works for full channels (not playlists)"
|
||||
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>
|
||||
|
||||
@@ -4,7 +4,7 @@ defmodule Pinchflat.MixProject do
|
||||
def project do
|
||||
[
|
||||
app: :pinchflat,
|
||||
version: "0.1.0-alpha.7",
|
||||
version: "0.1.3",
|
||||
elixir: "~> 1.16",
|
||||
elixirc_paths: elixirc_paths(Mix.env()),
|
||||
start_permanent: Mix.env() == :prod,
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,9 @@
|
||||
defmodule Pinchflat.Repo.Migrations.AddDescriptionToSource do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:sources) do
|
||||
add :description, :string
|
||||
end
|
||||
end
|
||||
end
|
||||
|
After Width: | Height: | Size: 115 KiB |
|
After Width: | Height: | Size: 72 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 ./
|
||||
@@ -74,9 +75,11 @@ RUN mix release
|
||||
# the compiled release and other runtime necessities
|
||||
FROM ${RUNNER_IMAGE}
|
||||
|
||||
ARG PORT=8945
|
||||
|
||||
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,9 +103,9 @@ RUN chown nobody /config /downloads
|
||||
|
||||
# set runner ENV
|
||||
ENV MIX_ENV="prod"
|
||||
ENV CONFIG_PATH="/config"
|
||||
ENV PORT=8945
|
||||
ENV PORT=${PORT}
|
||||
ENV RUN_CONTEXT="selfhosted"
|
||||
EXPOSE ${PORT}
|
||||
|
||||
# Only copy the final release from the build stage
|
||||
COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/pinchflat ./
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -140,4 +140,14 @@ defmodule Pinchflat.Metadata.MetadataFileHelpersTest do
|
||||
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)
|
||||
|
||||
|
||||
@@ -50,6 +50,23 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "perform/1 when testing attribute updates" do
|
||||
test "the source description is saved" 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()
|
||||
|
||||
refute source.description
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.preload(Repo.reload(source), :metadata)
|
||||
|
||||
assert source.description == "This is a test file for Pinchflat"
|
||||
end
|
||||
end
|
||||
|
||||
describe "perform/1 when testing metadata storage" do
|
||||
test "sets metadata location for source" do
|
||||
stub(YtDlpRunnerMock, :run, fn
|
||||
@@ -59,7 +76,6 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
|
||||
source = Repo.preload(source_fixture(), :metadata)
|
||||
|
||||
refute source.metadata
|
||||
perform_job(SourceMetadataStorageWorker, %{id: source.id})
|
||||
source = Repo.preload(Repo.reload(source), :metadata)
|
||||
|
||||
@@ -83,6 +99,42 @@ defmodule Pinchflat.Metadata.SourceMetadataStorageWorkerTest do
|
||||
|
||||
assert metadata == %{"title" => "test"}
|
||||
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 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
|
||||
|
||||
describe "perform/1 when testing source image downloading" do
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
alias Pinchflat.Filesystem.FilesystemHelpers
|
||||
|
||||
alias Pinchflat.YtDlp.CommandRunner, as: Runner
|
||||
|
||||
@original_executable Application.compile_env(:pinchflat, :yt_dlp_executable)
|
||||
@@ -65,6 +67,41 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "run/4 when testing cookie options" do
|
||||
setup do
|
||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||
cookie_file = Path.join(base_dir, "cookies.txt")
|
||||
|
||||
{:ok, cookie_file: cookie_file}
|
||||
end
|
||||
|
||||
test "includes cookie options when cookies.txt exists", %{cookie_file: cookie_file} do
|
||||
FilesystemHelpers.write_p!(cookie_file, "cookie data")
|
||||
|
||||
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||
|
||||
assert String.contains?(output, "--cookies #{cookie_file}")
|
||||
end
|
||||
|
||||
test "doesn't include cookie options when cookies.txt blank", %{cookie_file: cookie_file} do
|
||||
FilesystemHelpers.write_p!(cookie_file, " \n \n ")
|
||||
|
||||
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||
|
||||
refute String.contains?(output, "--cookies")
|
||||
refute String.contains?(output, cookie_file)
|
||||
end
|
||||
|
||||
test "doesn't include cookie options when cookies.txt doesn't exist", %{cookie_file: cookie_file} do
|
||||
File.rm(cookie_file)
|
||||
|
||||
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||
|
||||
refute String.contains?(output, "--cookies")
|
||||
refute String.contains?(output, cookie_file)
|
||||
end
|
||||
end
|
||||
|
||||
defp wrap_executable(new_executable, fun) do
|
||||
Application.put_env(:pinchflat, :yt_dlp_executable, new_executable)
|
||||
fun.()
|
||||
|
||||
@@ -6,7 +6,7 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||
alias Pinchflat.YtDlp.Media
|
||||
alias Pinchflat.YtDlp.MediaCollection
|
||||
|
||||
@channel_url "https://www.youtube.com/c/TheUselessTrials"
|
||||
@channel_url "https://www.youtube.com/c/PinchflatTestChannel"
|
||||
|
||||
setup :verify_on_exit!
|
||||
|
||||
@@ -77,10 +77,10 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||
test "it returns a map with data on success" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
Phoenix.json_library().encode(%{
|
||||
channel: "TheUselessTrials",
|
||||
channel: "PinchflatTestChannel",
|
||||
channel_id: "UCQH2",
|
||||
playlist_id: "PLQH2",
|
||||
playlist_title: "TheUselessTrials - Videos"
|
||||
playlist_title: "PinchflatTestChannel - Videos"
|
||||
})
|
||||
end)
|
||||
|
||||
@@ -88,9 +88,9 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||
|
||||
assert %{
|
||||
channel_id: "UCQH2",
|
||||
channel_name: "TheUselessTrials",
|
||||
channel_name: "PinchflatTestChannel",
|
||||
playlist_id: "PLQH2",
|
||||
playlist_name: "TheUselessTrials - Videos"
|
||||
playlist_name: "PinchflatTestChannel - Videos"
|
||||
} = res
|
||||
end
|
||||
|
||||
@@ -121,12 +121,12 @@ defmodule Pinchflat.YtDlp.MediaCollectionTest do
|
||||
describe "get_source_metadata/1" do
|
||||
test "it returns a map with data on success" do
|
||||
expect(YtDlpRunnerMock, :run, fn _url, _opts, _ot ->
|
||||
Phoenix.json_library().encode(%{channel: "TheUselessTrials"})
|
||||
Phoenix.json_library().encode(%{channel: "PinchflatTestChannel"})
|
||||
end)
|
||||
|
||||
assert {:ok, res} = MediaCollection.get_source_metadata(@channel_url)
|
||||
|
||||
assert %{"channel" => "TheUselessTrials"} = res
|
||||
assert %{"channel" => "PinchflatTestChannel"} = res
|
||||
end
|
||||
|
||||
test "it passes the expected args to the backend runner" do
|
||||
|
||||
@@ -36,7 +36,7 @@ defmodule Pinchflat.YtDlp.MediaTest do
|
||||
{:ok, render_metadata(:media_metadata)}
|
||||
end)
|
||||
|
||||
assert {:ok, %{"title" => "Trying to Wheelie Without the Rear Brake"}} =
|
||||
assert {:ok, %{"title" => "Pinchflat Example Video"}} =
|
||||
Media.download(@media_url)
|
||||
end
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 9.6 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 207 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 82 KiB After Width: | Height: | Size: 824 B |
|
After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 68 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 824 B |
|
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 824 B |
@@ -1,49 +1,15 @@
|
||||
{
|
||||
"id": "TheUselessTrials",
|
||||
"channel": "TheUselessTrials",
|
||||
"channel_id": "UCEi9yL4vhQlLafWRsAgAr3w",
|
||||
"title": "TheUselessTrials",
|
||||
"id": "PinchflatTestChannel",
|
||||
"channel": "PinchflatTestChannel",
|
||||
"channel_id": "UCEABC123",
|
||||
"title": "PinchflatTestChannel",
|
||||
"availability": null,
|
||||
"channel_follower_count": 35000,
|
||||
"description": "My name is Max and I'm a Street Trials bike rider with a passion for making videos. My channel features everything from learning and experiments all the way to just plain bike action. The first video series I started is called Quick New Trick and it featured me trying to learn new bike skills as quickly as possible, to show you how you can learn them as well.\n\nHope you enjoy the videos! See you in the comments section.",
|
||||
"tags": [
|
||||
"Useless Trials",
|
||||
"TUT",
|
||||
"UT",
|
||||
"Max Fiergolla",
|
||||
"maxfiergolla",
|
||||
"Street Trial Bikes",
|
||||
"Bike Tricks",
|
||||
"How To",
|
||||
"bike trial",
|
||||
"TRIAL BIKE",
|
||||
"quick new trick",
|
||||
"bike hacks",
|
||||
"trials bike",
|
||||
"bike trials",
|
||||
"TRIALS",
|
||||
"street trial",
|
||||
"trial street",
|
||||
"trials biking",
|
||||
"bike tricks",
|
||||
"bmx tricks",
|
||||
"mtb",
|
||||
"mtb tricks",
|
||||
"danny macaskill",
|
||||
"martyn ashton",
|
||||
"macaskill",
|
||||
"bike stunts",
|
||||
"mountainbike stunts",
|
||||
"mountainbiking",
|
||||
"inspired bicycles",
|
||||
"imaginate",
|
||||
"fahrrad tricks",
|
||||
"fahrradtricks",
|
||||
"fahrrad stunts"
|
||||
],
|
||||
"description": "This is a test file for Pinchflat",
|
||||
"tags": ["test", "development"],
|
||||
"thumbnails": [
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w320-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 88,
|
||||
"width": 320,
|
||||
"preference": -10,
|
||||
@@ -52,7 +18,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.0.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w320-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 180,
|
||||
"width": 320,
|
||||
"preference": -10,
|
||||
@@ -61,7 +27,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.1.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w640-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 175,
|
||||
"width": 640,
|
||||
"preference": -10,
|
||||
@@ -70,7 +36,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.2.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w854-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 480,
|
||||
"width": 854,
|
||||
"preference": -10,
|
||||
@@ -79,7 +45,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.3.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w960-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 263,
|
||||
"width": 960,
|
||||
"preference": -10,
|
||||
@@ -88,7 +54,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.4.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1060-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 175,
|
||||
"width": 1060,
|
||||
"preference": -10,
|
||||
@@ -97,7 +63,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.5.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1138-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 188,
|
||||
"width": 1138,
|
||||
"preference": -10,
|
||||
@@ -106,7 +72,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.6.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1280-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 351,
|
||||
"width": 1280,
|
||||
"preference": -10,
|
||||
@@ -115,7 +81,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.7.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1280-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 720,
|
||||
"width": 1280,
|
||||
"preference": -10,
|
||||
@@ -124,7 +90,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.8.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1440-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 395,
|
||||
"width": 1440,
|
||||
"preference": -10,
|
||||
@@ -133,7 +99,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.9.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1707-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 283,
|
||||
"width": 1707,
|
||||
"preference": -10,
|
||||
@@ -142,7 +108,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.10.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1920-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 1080,
|
||||
"width": 1920,
|
||||
"preference": -10,
|
||||
@@ -151,7 +117,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.11.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2120-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 351,
|
||||
"width": 2120,
|
||||
"preference": -10,
|
||||
@@ -160,7 +126,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.12.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2120-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 1192,
|
||||
"width": 2120,
|
||||
"preference": -10,
|
||||
@@ -169,7 +135,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.13.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2276-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 377,
|
||||
"width": 2276,
|
||||
"preference": -10,
|
||||
@@ -178,7 +144,7 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.14.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2560-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 424,
|
||||
"width": 2560,
|
||||
"preference": -10,
|
||||
@@ -187,13 +153,13 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.15.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=s0",
|
||||
"url": "https://google.ca",
|
||||
"id": "banner_uncropped",
|
||||
"preference": -5,
|
||||
"filepath": "/app/test/support/files/channel_photos/a.banner_uncropped.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/ytc/AIdro_kw1KKWzbFmvq6u8WljTbo6QQ318WoAwnjX3AYrjA=s900-c-k-c0x00ffffff-no-rj",
|
||||
"url": "https://google.ca",
|
||||
"height": 900,
|
||||
"width": 900,
|
||||
"id": "17",
|
||||
@@ -201,24 +167,24 @@
|
||||
"filepath": "/app/test/support/files/channel_photos/a.17.jpg"
|
||||
},
|
||||
{
|
||||
"url": "https://yt3.googleusercontent.com/ytc/AIdro_kw1KKWzbFmvq6u8WljTbo6QQ318WoAwnjX3AYrjA=s0",
|
||||
"url": "https://google.ca",
|
||||
"id": "avatar_uncropped",
|
||||
"preference": 1,
|
||||
"filepath": "/app/test/support/files/channel_photos/a.avatar_uncropped.jpg"
|
||||
}
|
||||
],
|
||||
"uploader_id": "@TheUselessTrials",
|
||||
"uploader_url": "https://www.youtube.com/@TheUselessTrials",
|
||||
"uploader_id": "@PinchflatTestChannel",
|
||||
"uploader_url": "https://www.youtube.com/@PinchflatTestChannel",
|
||||
"modified_date": null,
|
||||
"view_count": null,
|
||||
"playlist_count": 2,
|
||||
"uploader": "TheUselessTrials",
|
||||
"channel_url": "https://www.youtube.com/channel/UCEi9yL4vhQlLafWRsAgAr3w",
|
||||
"uploader": "PinchflatTestChannel",
|
||||
"channel_url": "https://www.youtube.com/channel/UCEABC123",
|
||||
"_type": "playlist",
|
||||
"entries": [],
|
||||
"webpage_url": "https://www.youtube.com/c/TheUselessTrials",
|
||||
"original_url": "https://www.youtube.com/c/TheUselessTrials",
|
||||
"webpage_url_basename": "TheUselessTrials",
|
||||
"webpage_url": "https://www.youtube.com/c/PinchflatTestChannel",
|
||||
"original_url": "https://www.youtube.com/c/PinchflatTestChannel",
|
||||
"webpage_url_basename": "PinchflatTestChannel",
|
||||
"webpage_url_domain": "youtube.com",
|
||||
"extractor": "youtube:tab",
|
||||
"extractor_key": "YoutubeTab",
|
||||
@@ -227,7 +193,6 @@
|
||||
"epoch": 1710800380,
|
||||
"filename": "/app/test/support/files/channel_photos/a.NA",
|
||||
"formats_table": null,
|
||||
"thumbnails_table": "ID Width Height URL\n0 320 88 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w320-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj\n1 320 180 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w320-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj\n2 640 175 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w640-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj\n3 854 480 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w854-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj\n4 960 263 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w960-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj\n5 1060 175 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1060-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj\n6 1138 188 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1138-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj\n7 1280 351 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1280-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj\n8 1280 720 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1280-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj\n9 1440 395 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1440-fcrop64=1,32b75a57cd48a5a8-k-c0xffffffff-no-nd-rj\n10 1707 283 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1707-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj\n11 1920 1080 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w1920-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj\n12 2120 351 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2120-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj\n13 2120 1192 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2120-fcrop64=1,00000000ffffffff-k-c0xffffffff-no-nd-rj\n14 2276 377 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2276-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj\n15 2560 424 https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=w2560-fcrop64=1,00005a57ffffa5a8-k-c0xffffffff-no-nd-rj\nbanner_uncropped unknown unknown https://yt3.googleusercontent.com/_yUVmZqHvZZhNOFq2iMUPA82LylawAvYknCrwTE_9_IUQ0htiLPet2FKxE1ArvLAKf0lVsLccQ=s0\n17 900 900 https://yt3.googleusercontent.com/ytc/AIdro_kw1KKWzbFmvq6u8WljTbo6QQ318WoAwnjX3AYrjA=s900-c-k-c0x00ffffff-no-rj\navatar_uncropped unknown unknown https://yt3.googleusercontent.com/ytc/AIdro_kw1KKWzbFmvq6u8WljTbo6QQ318WoAwnjX3AYrjA=s0",
|
||||
"subtitles_table": null,
|
||||
"automatic_captions_table": null,
|
||||
"duration_string": null,
|
||||
|
||||
|
After Width: | Height: | Size: 824 B |
@@ -52,14 +52,7 @@ defmodule Pinchflat.MediaFixtures do
|
||||
"#{:rand.uniform(1_000_000)}_media.mkv"
|
||||
])
|
||||
|
||||
fixture_media_filepath =
|
||||
Path.join([
|
||||
File.cwd!(),
|
||||
"test",
|
||||
"support",
|
||||
"files",
|
||||
"media.mkv"
|
||||
])
|
||||
fixture_media_filepath = media_filepath_fixture()
|
||||
|
||||
:ok = File.mkdir_p(Path.dirname(stored_media_filepath))
|
||||
:ok = File.cp(fixture_media_filepath, stored_media_filepath)
|
||||
@@ -82,4 +75,34 @@ defmodule Pinchflat.MediaFixtures do
|
||||
|
||||
Phoenix.json_library().encode!(media_attributes)
|
||||
end
|
||||
|
||||
def media_filepath_fixture do
|
||||
Path.join([
|
||||
File.cwd!(),
|
||||
"test",
|
||||
"support",
|
||||
"files",
|
||||
"media.mkv"
|
||||
])
|
||||
end
|
||||
|
||||
def thumbnail_filepath_fixture do
|
||||
Path.join([
|
||||
File.cwd!(),
|
||||
"test",
|
||||
"support",
|
||||
"files",
|
||||
"thumbnail.jpg"
|
||||
])
|
||||
end
|
||||
|
||||
def infojson_filepath_fixture do
|
||||
Path.join([
|
||||
File.cwd!(),
|
||||
"test",
|
||||
"support",
|
||||
"files",
|
||||
"example.info.json"
|
||||
])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,9 +11,11 @@ Faker.start()
|
||||
ExUnit.after_suite(fn _ ->
|
||||
File.rm_rf!(Application.get_env(:pinchflat, :media_directory))
|
||||
File.rm_rf!(Application.get_env(:pinchflat, :metadata_directory))
|
||||
File.rm_rf!(Application.get_env(:pinchflat, :extras_directory))
|
||||
File.rm_rf!(Application.get_env(:pinchflat, :tmpfile_directory))
|
||||
|
||||
File.mkdir_p!(Application.get_env(:pinchflat, :media_directory))
|
||||
File.mkdir_p!(Application.get_env(:pinchflat, :metadata_directory))
|
||||
File.mkdir_p!(Application.get_env(:pinchflat, :extras_directory))
|
||||
File.mkdir_p!(Application.get_env(:pinchflat, :tmpfile_directory))
|
||||
end)
|
||||
|
||||