[WIP] Added basic video download method

This commit is contained in:
Kieran Eglin 2024-01-20 20:34:29 -08:00
parent a4f5024d8f
commit f6fd0775d9
No known key found for this signature in database
GPG key ID: 193984967FCF432D
4 changed files with 42 additions and 2 deletions

View file

@ -12,7 +12,9 @@ config :pinchflat,
generators: [timestamp_type: :utc_datetime], generators: [timestamp_type: :utc_datetime],
# Specifying backend data here makes mocking and local testing SUPER easy # Specifying backend data here makes mocking and local testing SUPER easy
yt_dlp_executable: System.find_executable("yt-dlp"), yt_dlp_executable: System.find_executable("yt-dlp"),
yt_dlp_runner: Pinchflat.Downloader.Backends.YtDlp.CommandRunner yt_dlp_runner: Pinchflat.Downloader.Backends.YtDlp.CommandRunner,
# TODO: figure this out
media_directory: :not_implemented
# Configures the endpoint # Configures the endpoint
config :pinchflat, PinchflatWeb.Endpoint, config :pinchflat, PinchflatWeb.Endpoint,

View file

@ -1,5 +1,8 @@
import Config import Config
config :pinchflat,
media_directory: Path.join([System.tmp_dir!(), "yt-dlp"])
# Configure your database # Configure your database
config :pinchflat, Pinchflat.Repo, config :pinchflat, Pinchflat.Repo,
username: System.get_env("POSTGRES_USER"), username: System.get_env("POSTGRES_USER"),

View file

@ -2,7 +2,8 @@ import Config
config :pinchflat, config :pinchflat,
# Specifying backend data here makes mocking and local testing SUPER easy # Specifying backend data here makes mocking and local testing SUPER easy
yt_dlp_executable: Path.join([File.cwd!(), "/test/support/scripts/yt-dlp-mocks/repeater.sh"]) yt_dlp_executable: Path.join([File.cwd!(), "/test/support/scripts/yt-dlp-mocks/repeater.sh"]),
media_directory: Path.join([System.tmp_dir!(), "yt-dlp"])
# Configure your database # Configure your database
# #

View file

@ -0,0 +1,34 @@
defmodule Pinchflat.Downloader.Backends.YtDlp.Video do
@moduledoc """
Contains utilities for working with singular videos
"""
@doc """
Downloads a single video (and possible metadata) to the tmp directory.
Videos are downloaded in the following format:
`tmp/yt-dlp/<video_id>/<video_id>.<ext>`
The video will be moved to its final destination... elsewhere
# TODO: update these docs when I figure out a module to move videos
# NOTE: maybe instead of moving it to the tempdir, I can just download it
to the final destination by using the `output` option. The
parser could be updated to generate a value for the output option.
This way, advanced users can just the yt-dlp output syntax and
newer users can use the easier liquid-like syntax.
"""
def download(url, command_opts \\ []) do
default_output_path = Path.join([base_directory(), "%(id)s", "%(id)s.%(ext)s"])
default_opts = [output: default_output_path]
opts = Keyword.merge(default_opts, command_opts)
backend_runner().run(url, opts)
end
defp base_directory do
Application.get_env(:pinchflat, :media_directory)
end
defp backend_runner do
Application.get_env(:pinchflat, :yt_dlp_runner)
end
end