mirror of
https://github.com/kieraneglin/pinchflat.git
synced 2026-01-23 02:24:24 +00:00
[Enhancement] Add audio track language selection to Media Profile (#487)
* Moved quality options to their own module * Added language and format selection to quality option builder * [WIP] migrating tests * Added audio_lang to media_profile table * Renamed column; added format options and tests * Adds UI for audio_track to the media profile form * Adds a version string to in-app streams to help with cache busting
This commit is contained in:
parent
bfb27427ce
commit
652fcccb4a
10 changed files with 210 additions and 66 deletions
|
|
@ -6,7 +6,6 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
|||
|
||||
alias Pinchflat.Sources
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Utils.FilesystemUtils
|
||||
alias Pinchflat.Downloading.DownloadOptionBuilder
|
||||
|
||||
|
|
@ -253,21 +252,14 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
|||
end
|
||||
|
||||
describe "build/1 when testing media quality and format options" do
|
||||
test "includes quality options" do
|
||||
resolutions = ["360", "480", "720", "1080", "2160", "4320"]
|
||||
# There are more tests inside QualityOptionBuilderTest
|
||||
# This is essenitally just testing that we implement that module correctly
|
||||
|
||||
Enum.each(resolutions, fn resolution ->
|
||||
resolution_atom = String.to_existing_atom(resolution <> "p")
|
||||
test "includes video options for video profiles", %{media_item: media_item} do
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
media_profile = media_profile_fixture(%{preferred_resolution: resolution_atom})
|
||||
source = source_fixture(%{media_profile_id: media_profile.id})
|
||||
media_item = Repo.preload(media_item_fixture(source_id: source.id), source: :media_profile)
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
assert {:format_sort, "res:#{resolution},+codec:avc:m4a"} in res
|
||||
assert {:remux_video, "mp4"} in res
|
||||
end)
|
||||
assert {:format_sort, "res:1080,+codec:avc:m4a"} in res
|
||||
assert {:remux_video, "mp4"} in res
|
||||
end
|
||||
|
||||
test "includes quality options for audio only", %{media_item: media_item} do
|
||||
|
|
@ -280,33 +272,6 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
|||
|
||||
refute {:remux_video, "mp4"} in res
|
||||
end
|
||||
|
||||
test "includes custom quality options if specified", %{media_item: media_item} do
|
||||
Settings.set(video_codec_preference: "av01")
|
||||
Settings.set(audio_codec_preference: "aac")
|
||||
|
||||
media_item = update_media_profile_attribute(media_item, %{preferred_resolution: :"1080p"})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
assert {:format_sort, "res:1080,+codec:av01:aac"} in res
|
||||
end
|
||||
|
||||
test "includes custom remux target for videos if specified", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{media_container: "mkv"})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
assert {:remux_video, "mkv"} in res
|
||||
end
|
||||
|
||||
test "includes custom format target for audio if specified", %{media_item: media_item} do
|
||||
media_item = update_media_profile_attribute(media_item, %{media_container: "flac", preferred_resolution: :audio})
|
||||
|
||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||
|
||||
assert {:audio_format, "flac"} in res
|
||||
end
|
||||
end
|
||||
|
||||
describe "build/1 when testing sponsorblock options" do
|
||||
|
|
|
|||
109
test/pinchflat/downloading/quality_option_builder_test.exs
Normal file
109
test/pinchflat/downloading/quality_option_builder_test.exs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
defmodule Pinchflat.Downloading.QualityOptionBuilderTest do
|
||||
use Pinchflat.DataCase
|
||||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Settings
|
||||
alias Pinchflat.Downloading.QualityOptionBuilder
|
||||
|
||||
describe "build/1" do
|
||||
test "includes format options if audio_track is set to original" do
|
||||
media_profile = media_profile_fixture(%{audio_track: "original"})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format, "bestvideo+bestaudio[format_note*=original]/bestvideo*+bestaudio/best"} in res
|
||||
end
|
||||
|
||||
test "includes format options if audio_track is set to default" do
|
||||
media_profile = media_profile_fixture(%{audio_track: "default"})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format, "bestvideo+bestaudio[format_note*='(default)']/bestvideo*+bestaudio/best"} in res
|
||||
end
|
||||
|
||||
test "includes format options if audio_track is set to a language code" do
|
||||
media_profile = media_profile_fixture(%{audio_track: "en"})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format, "bestvideo+bestaudio[language^=en]/bestvideo*+bestaudio/best"} in res
|
||||
end
|
||||
end
|
||||
|
||||
describe "build/1 when testing audio profiles" do
|
||||
setup do
|
||||
{:ok, media_profile: media_profile_fixture(%{preferred_resolution: :audio})}
|
||||
end
|
||||
|
||||
test "includes quality options for audio only", %{media_profile: media_profile} do
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert :extract_audio in res
|
||||
assert {:format_sort, "+acodec:m4a"} in res
|
||||
|
||||
refute {:remux_video, "mp4"} in res
|
||||
end
|
||||
|
||||
test "includes custom format target for audio if specified", %{media_profile: media_profile} do
|
||||
{:ok, media_profile} =
|
||||
Profiles.update_media_profile(media_profile, %{media_container: "flac", preferred_resolution: :audio})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:audio_format, "flac"} in res
|
||||
end
|
||||
|
||||
test "includes custom format options", %{media_profile: media_profile} do
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format, "bestaudio/best"} in res
|
||||
end
|
||||
end
|
||||
|
||||
describe "build/1 when testing non-audio profiles" do
|
||||
setup do
|
||||
{:ok, media_profile: media_profile_fixture(%{preferred_resolution: :"480p"})}
|
||||
end
|
||||
|
||||
test "includes quality options" do
|
||||
resolutions = ["360", "480", "720", "1080", "2160", "4320"]
|
||||
|
||||
Enum.each(resolutions, fn resolution ->
|
||||
resolution_atom = String.to_existing_atom(resolution <> "p")
|
||||
media_profile = media_profile_fixture(%{preferred_resolution: resolution_atom})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format_sort, "res:#{resolution},+codec:avc:m4a"} in res
|
||||
assert {:remux_video, "mp4"} in res
|
||||
end)
|
||||
end
|
||||
|
||||
test "includes custom quality options if specified", %{media_profile: media_profile} do
|
||||
Settings.set(video_codec_preference: "av01")
|
||||
Settings.set(audio_codec_preference: "aac")
|
||||
|
||||
{:ok, media_profile} = Profiles.update_media_profile(media_profile, %{preferred_resolution: :"1080p"})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format_sort, "res:1080,+codec:av01:aac"} in res
|
||||
end
|
||||
|
||||
test "includes custom remux target for videos if specified", %{media_profile: media_profile} do
|
||||
{:ok, media_profile} = Profiles.update_media_profile(media_profile, %{media_container: "mkv"})
|
||||
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:remux_video, "mkv"} in res
|
||||
end
|
||||
|
||||
test "includes custom format options", %{media_profile: media_profile} do
|
||||
assert res = QualityOptionBuilder.build(media_profile)
|
||||
|
||||
assert {:format, "bestvideo*+bestaudio/best"} in res
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue