Allow subtitle downloading (#11)

* Added subtitle options to media profile model

* Updated media profile form

* Adds subtitle-based options in options builder

* Updates metadata parser to include subtitles

* Adds subtitle_filepaths to media_item

* renamed video_filepath to media_filepath

* Added more fields to media profile show page
This commit is contained in:
Kieran authored and GitHub committed 2024-01-31 10:55:02 -08:00
1 parent a5e7c48f70
commit d25e65f822
19 files changed
+5139 -872

No files matched your search

+17 -2
View File
@@ -8,9 +8,24 @@ defmodule Pinchflat.Profiles.MediaProfile do
alias Pinchflat.MediaSource.Channel
@allowed_fields ~w(
name
output_path_template
download_subs
download_auto_subs
embed_subs
sub_langs
)a
@required_fields ~w(name output_path_template)a
schema "media_profiles" do
field :name, :string
field :output_path_template, :string
field :download_subs, :boolean, default: true
field :download_auto_subs, :boolean, default: true
field :embed_subs, :boolean, default: true
field :sub_langs, :string, default: "en"
has_many :channels, Channel
@@ -20,8 +35,8 @@ defmodule Pinchflat.Profiles.MediaProfile do
@doc false
def changeset(media_profile, attrs) do
media_profile
|> cast(attrs, [:name, :output_path_template])
|> validate_required([:name, :output_path_template])
|> cast(attrs, @allowed_fields)
|> validate_required(@required_fields)
|> unique_constraint(:name)
end
end
@@ -15,22 +15,62 @@ defmodule Pinchflat.Profiles.Options.YtDlp.OptionBuilder do
these options
"""
def build(%MediaProfile{} = media_profile) do
{:ok, output_path} = OutputPathBuilder.build(media_profile.output_path_template)
# NOTE: I'll be hardcoding most things for now (esp. options to help me test) -
# add more configuration later as I build out the models. Walk before you can run!
# NOTE: Looks like you can put different media types in different directories.
# see: https://github.com/yt-dlp/yt-dlp#output-template
{:ok,
[
:embed_metadata,
:embed_thumbnail,
:embed_subs,
:no_progress,
sub_langs: "en.*",
output: Path.join(base_directory(), output_path)
]}
built_options =
default_options() ++
subtitle_options(media_profile) ++
output_options(media_profile)
{:ok, built_options}
end
# This will be updated a lot as I add new options to profiles
defp default_options do
[
:embed_metadata,
:embed_thumbnail,
:no_progress
]
end
defp subtitle_options(media_profile) do
mapped_struct = Map.from_struct(media_profile)
Enum.reduce(mapped_struct, [], fn attr, acc ->
case {attr, media_profile} do
{{:download_subs, true}, _} ->
# Force SRT for now - MAY provide as an option in the future
acc ++ [:write_subs, convert_subs: "srt"]
{{:download_auto_subs, true}, %{download_subs: true}} ->
acc ++ [:write_auto_subs]
{{:embed_subs, true}, _} ->
acc ++ [:embed_subs]
{{:sub_langs, sub_langs}, %{download_subs: true}} ->
acc ++ [sub_langs: sub_langs]
{{:sub_langs, sub_langs}, %{embed_subs: true}} ->
acc ++ [sub_langs: sub_langs]
_ ->
acc
end
end)
end
defp output_options(media_profile) do
{:ok, output_path} = OutputPathBuilder.build(media_profile.output_path_template)
[
output: Path.join(base_directory(), output_path)
]
end
defp base_directory do