Adds subtitle-based options in options builder
This commit is contained in:
parent
f0aab2c8ca
commit
2c20e3a87a
3 changed files with 144 additions and 11 deletions
14
.iex.exs
Normal file
14
.iex.exs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
alias Pinchflat.Repo
|
||||||
|
|
||||||
|
alias Pinchflat.Tasks.Task
|
||||||
|
alias Pinchflat.Media.MediaItem
|
||||||
|
alias Pinchflat.Media.MediaMetadata
|
||||||
|
alias Pinchflat.MediaSource.Channel
|
||||||
|
alias Pinchflat.Profiles.MediaProfile
|
||||||
|
|
||||||
|
alias Pinchflat.Tasks
|
||||||
|
alias Pinchflat.Media
|
||||||
|
alias Pinchflat.Profiles
|
||||||
|
alias Pinchflat.MediaSource
|
||||||
|
|
||||||
|
alias Pinchflat.MediaClient.{ChannelDetails, VideoDownloader}
|
||||||
|
|
@ -15,22 +15,62 @@ defmodule Pinchflat.Profiles.Options.YtDlp.OptionBuilder do
|
||||||
these options
|
these options
|
||||||
"""
|
"""
|
||||||
def build(%MediaProfile{} = media_profile) do
|
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) -
|
# 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!
|
# 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.
|
# NOTE: Looks like you can put different media types in different directories.
|
||||||
# see: https://github.com/yt-dlp/yt-dlp#output-template
|
# see: https://github.com/yt-dlp/yt-dlp#output-template
|
||||||
{:ok,
|
|
||||||
[
|
built_options =
|
||||||
:embed_metadata,
|
default_options() ++
|
||||||
:embed_thumbnail,
|
subtitle_options(media_profile) ++
|
||||||
:embed_subs,
|
output_options(media_profile)
|
||||||
:no_progress,
|
|
||||||
sub_langs: "en.*",
|
{:ok, built_options}
|
||||||
output: Path.join(base_directory(), output_path)
|
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
|
end
|
||||||
|
|
||||||
defp base_directory do
|
defp base_directory do
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,83 @@ defmodule Pinchflat.Profiles.Options.YtDlp.OptionBuilderTest do
|
||||||
assert {:output, "/tmp/videos/%(title)S.%(ext)s"} in res
|
assert {:output, "/tmp/videos/%(title)S.%(ext)s"} in res
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "build/1 when testing subtitle options" do
|
||||||
|
test "includes :write_subs option when specified" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | download_subs: true}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert :write_subs in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "forces SRT format when download_subs is true" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | download_subs: true}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:convert_subs, "srt"} in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes :write_auto_subs option when specified" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | download_subs: true, download_auto_subs: true}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert :write_auto_subs in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "doesn't include :write_auto_subs option when download_subs is false" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | download_subs: false, download_auto_subs: true}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
refute :write_auto_subs in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes :embed_subs option when specified" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | embed_subs: true}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert :embed_subs in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes sub_langs option when download_subs is true" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | download_subs: true, sub_langs: "en"}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:sub_langs, "en"} in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "includes sub_langs option when embed_subs is true" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | embed_subs: true, sub_langs: "en"}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
assert {:sub_langs, "en"} in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "doesn't include sub_langs option when neither downloading nor embedding" do
|
||||||
|
media_profile = %MediaProfile{
|
||||||
|
@media_profile
|
||||||
|
| embed_subs: false,
|
||||||
|
download_subs: false,
|
||||||
|
sub_langs: "en"
|
||||||
|
}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
refute {:sub_langs, "en"} in res
|
||||||
|
end
|
||||||
|
|
||||||
|
test "other struct attributes are ignored" do
|
||||||
|
media_profile = %MediaProfile{@media_profile | id: -1}
|
||||||
|
|
||||||
|
assert {:ok, res} = OptionBuilder.build(media_profile)
|
||||||
|
|
||||||
|
refute {:id, -1} in res
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue