Refactored windows_filenames to be a global flag; added tests
This commit is contained in:
parent
9fc42abe62
commit
36f576ca93
5 changed files with 16 additions and 7 deletions
|
|
@ -44,7 +44,6 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilder do
|
||||||
defp default_options do
|
defp default_options do
|
||||||
[
|
[
|
||||||
:no_progress,
|
:no_progress,
|
||||||
:windows_filenames,
|
|
||||||
# Add force-overwrites to make sure redownloading works
|
# Add force-overwrites to make sure redownloading works
|
||||||
:force_overwrites,
|
:force_overwrites,
|
||||||
# This makes the date metadata conform to what jellyfin expects
|
# This makes the date metadata conform to what jellyfin expects
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,9 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
|
|
||||||
output_filepath = generate_output_filepath(addl_opts)
|
output_filepath = generate_output_filepath(addl_opts)
|
||||||
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
print_to_file_opts = [{:print_to_file, output_template}, output_filepath]
|
||||||
external_file_opts = build_external_file_options()
|
user_configured_opts = cookie_file_options() ++ global_options()
|
||||||
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
# These must stay in exactly this order, hence why I'm giving it its own variable.
|
||||||
all_opts = command_opts ++ print_to_file_opts ++ external_file_opts
|
all_opts = command_opts ++ print_to_file_opts ++ user_configured_opts
|
||||||
|
|
||||||
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
formatted_command_opts = [url] ++ CliUtils.parse_options(all_opts)
|
||||||
Logger.info("[yt-dlp] called with: #{Enum.join(formatted_command_opts, " ")}")
|
Logger.info("[yt-dlp] called with: #{Enum.join(formatted_command_opts, " ")}")
|
||||||
|
|
||||||
|
|
@ -58,6 +57,7 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
def version do
|
def version do
|
||||||
command = backend_executable()
|
command = backend_executable()
|
||||||
|
|
||||||
|
# TODO: fix to use CliUtils.wrap_cmd (and look at apprise too)
|
||||||
case System.cmd(command, ["--version"]) do
|
case System.cmd(command, ["--version"]) do
|
||||||
{output, 0} ->
|
{output, 0} ->
|
||||||
{:ok, String.trim(output)}
|
{:ok, String.trim(output)}
|
||||||
|
|
@ -74,7 +74,11 @@ defmodule Pinchflat.YtDlp.CommandRunner do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp build_external_file_options do
|
defp global_options do
|
||||||
|
[:windows_filenames]
|
||||||
|
end
|
||||||
|
|
||||||
|
defp cookie_file_options do
|
||||||
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
base_dir = Application.get_env(:pinchflat, :extras_directory)
|
||||||
filename_options_map = %{cookies: "cookies.txt"}
|
filename_options_map = %{cookies: "cookies.txt"}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,6 @@ defmodule Pinchflat.YtDlp.MediaCollection do
|
||||||
# the first video has not released yet (ie: is a premier). We don't care about
|
# the first video has not released yet (ie: is a premier). We don't care about
|
||||||
# available formats since we're just getting the source details
|
# available formats since we're just getting the source details
|
||||||
default_opts = [
|
default_opts = [
|
||||||
:windows_filenames,
|
|
||||||
:simulate,
|
:simulate,
|
||||||
:skip_download,
|
:skip_download,
|
||||||
:ignore_no_formats_error,
|
:ignore_no_formats_error,
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ defmodule Pinchflat.Downloading.DownloadOptionBuilderTest do
|
||||||
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
assert {:ok, res} = DownloadOptionBuilder.build(media_item)
|
||||||
|
|
||||||
assert :no_progress in res
|
assert :no_progress in res
|
||||||
assert :windows_filenames in res
|
|
||||||
assert :force_overwrites in res
|
assert :force_overwrites in res
|
||||||
assert {:parse_metadata, "%(upload_date>%Y-%m-%d)s:(?P<meta_date>.+)"} in res
|
assert {:parse_metadata, "%(upload_date>%Y-%m-%d)s:(?P<meta_date>.+)"} in res
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,14 @@ defmodule Pinchflat.YtDlp.CommandRunnerTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "run/4 when testing global options" do
|
||||||
|
test "creates windows-safe filenames" do
|
||||||
|
assert {:ok, output} = Runner.run(@media_url, [], "")
|
||||||
|
|
||||||
|
assert String.contains?(output, "--windows-filenames")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "version/0" do
|
describe "version/0" do
|
||||||
test "adds the version arg" do
|
test "adds the version arg" do
|
||||||
assert {:ok, output} = Runner.version()
|
assert {:ok, output} = Runner.version()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue