Compare commits

..

No commits in common. "ef6828531b67b5e3d1bd3fb9e15bcdf63ab444be" and "23a884339d2d504044927507ed41f388409e34cb" have entirely different histories.

3 changed files with 3 additions and 38 deletions

View file

@ -21,15 +21,6 @@ defmodule HahaYes.Commands.Download do
User: h3h3 download https://www.youtube.com/watch?v=ryS7TS_J7KA User: h3h3 download https://www.youtube.com/watch?v=ryS7TS_J7KA
Bot: <video file> Bot: <video file>
User: h3h3 download https://cdn.discordapp.com/attachments/790701936394633216/1295042668929355816/1295042650113704087.mp4?ex=670d35f9&is=670be479&hm=bf61358b9b6f8c94a14be4e7e3650799ef733331e84d87254b71a098646c4bc2&
Bot: <video file>
User: h3h3 download invalid
Bot: `[generic] Extracting URL: invalid
ERROR: [generic] 'invalid' is not a valid URL. Set --default-search "ytsearch" (or run yt-dlp "ytsearch:invalid" ) to search YouTube`
""" """
def execute(msg, _ws_state, args) do def execute(msg, _ws_state, args) do
url = Enum.at(args, 0) url = Enum.at(args, 0)

View file

@ -1,26 +1,4 @@
defmodule HahaYes.Utility do defmodule HahaYes.Utility do
@moduledoc """
Various utilities to be reused in commands
"""
@doc """
Download utility with the format at 480p by default.
## Example
```
iex> HahaYes.Utility.download("https://x.com/i/status/1844841048603783249", "#{System.tmp_dir}/test")
{:ok, /tmp}/test.mp4
```
```
iex> HahaYes.Utility.download("invalid", "#{System.tmp_dir}/test")
{:error, "[generic] Extracting URL: invalid\\nERROR: [generic] 'invalid' is not a valid URL. Set --default-search "ytsearch" (or run yt-dlp "ytsearch:invalid" ) to search YouTube"}
```
"""
def download(url, output, format \\ "bestvideo[height<=?480]+bestaudio/best") do def download(url, output, format \\ "bestvideo[height<=?480]+bestaudio/best") do
opt = ["-f", format, url, "-o", "#{output}.%(ext)s", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"]; opt = ["-f", format, url, "-o", "#{output}.%(ext)s", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];

View file

@ -1,12 +1,8 @@
defmodule HahaYesTest do defmodule HahaYesTest do
use ExUnit.Case use ExUnit.Case
doctest HahaYes.Utility doctest HahaYes
@tag :tmp_dir test "greets the world" do
assert HahaYes.hello() == :world
test "download utils", %{tmp_dir: tmp_dir} do
assert HahaYes.Utility.download("https://x.com/i/status/1844841048603783249", "#{tmp_dir}/test") == {:ok, "#{tmp_dir}/test.mp4"}
assert HahaYes.Utility.download("invalid", "#{tmp_dir}/test") == {:error, "[generic] Extracting URL: invalid\nERROR: [generic] 'invalid' is not a valid URL. Set --default-search \"ytsearch\" (or run yt-dlp \"ytsearch:invalid\" ) to search YouTube\n"}
end end
end end