Skip to content

Commit

Permalink
[Enhancement] Support auto-generated subs when embedding subs in medi…
Browse files Browse the repository at this point in the history
…a file (#324)

* Allowed using auto subs when embedding

* Updated profile form
  • Loading branch information
kieraneglin authored Jul 17, 2024
1 parent d423e44 commit 029981b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/pinchflat/downloading/download_option_builder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
{{:download_auto_subs, true}, %{download_subs: true}} ->
acc ++ [:write_auto_subs]

{{:download_auto_subs, true}, %{embed_subs: true}} ->
acc ++ [:write_auto_subs]

{{:embed_subs, true}, %{preferred_resolution: pr}} when pr != :audio ->
acc ++ [:embed_subs]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@
/>
</section>

<section x-data="{ presets: { default: false, media_center: false, audio: false, archiving: false } }">
<section x-data="{ presets: { default: true, media_center: true, audio: false, archiving: true } }">
<.input
field={f[:download_auto_subs]}
field={f[:embed_subs]}
type="toggle"
label="Download Autogenerated Subtitles"
help="Prefers normal subs but will download autogenerated if needed. Requires 'Download Subtitles' to be enabled"
label="Embed Subtitles"
help="Downloads and embeds subtitles in the media file itself, if supported. Uneffected by 'Download Subtitles'"
x-init="$watch('selectedPreset', p => p && (enabled = presets[p]))"
/>
</section>

<section x-data="{ presets: { default: true, media_center: true, audio: false, archiving: true } }">
<section x-data="{ presets: { default: false, media_center: false, audio: false, archiving: false } }">
<.input
field={f[:embed_subs]}
field={f[:download_auto_subs]}
type="toggle"
label="Embed Subtitles"
help="Downloads and embeds subtitles in the media file itself, if supported. Uneffected by 'Download Subtitles' (recommended)"
label="Use Autogenerated Subtitles"
help="Prefers normal subs with 'Download Subtitles' or 'Embed Subtitles' but will use autogenerated subs if needed."
x-init="$watch('selectedPreset', p => p && (enabled = presets[p]))"
/>
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@
<ul class="list-disc list-inside mb-4 ml-2 md:ml-5 max-w-prose">
<li :for={{k, v} <- media_center_custom_output_template_options()} class="mt-1">
<.inline_code>{{ <%= k %> }}</.inline_code>
<span :if={v}>- <%= raw(v) %></span>
<span :if={v}>- <%= html_escape({:safe, v}) %></span>
</li>
</ul>
<h3 class="text-lg font-bold mb-2">Other Custom Aliases</h3>
<ul class="list-disc list-inside mb-4 ml-2 md:ml-5 max-w-prose">
<li :for={{k, v} <- other_custom_output_template_options()} class="mt-1">
<.inline_code>{{ <%= k %> }}</.inline_code>
<span :if={v}>- <%= raw(v) %></span>
<span :if={v}>- <%= html_escape({:safe, v}) %></span>
</li>
</ul>
<h3 class="text-lg font-bold mb-2">Common Options</h3>
Expand Down
18 changes: 13 additions & 5 deletions test/pinchflat/downloading/download_option_builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
end

test "includes :write_auto_subs option when specified", %{media_item: media_item} do
media_item = update_media_profile_attribute(media_item, %{download_subs: true, download_auto_subs: true})
media_item_1 = update_media_profile_attribute(media_item, %{download_subs: true, download_auto_subs: true})
media_item_2 = update_media_profile_attribute(media_item, %{embed_subs: true, download_auto_subs: true})

assert {:ok, res} = DownloadOptionBuilder.build(media_item)
assert {:ok, res_1} = DownloadOptionBuilder.build(media_item_1)
assert {:ok, res_2} = DownloadOptionBuilder.build(media_item_2)

assert :write_auto_subs in res
assert :write_auto_subs in res_1
assert :write_auto_subs in res_2
end

test "doesn't include :write_auto_subs option when download_subs is false", %{media_item: media_item} do
media_item = update_media_profile_attribute(media_item, %{download_subs: false, download_auto_subs: true})
test "doesn't include :write_auto_subs option when download_subs and embed_subs is false", %{media_item: media_item} do
media_item =
update_media_profile_attribute(media_item, %{
download_subs: false,
embed_subs: false,
download_auto_subs: true
})

assert {:ok, res} = DownloadOptionBuilder.build(media_item)

Expand Down

0 comments on commit 029981b

Please sign in to comment.