Compare commits
2 commits
23a884339d
...
ef6828531b
Author | SHA1 | Date | |
---|---|---|---|
ef6828531b | |||
4c8d48c575 |
3 changed files with 38 additions and 3 deletions
|
@ -21,6 +21,15 @@ 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)
|
||||||
|
|
|
@ -1,4 +1,26 @@
|
||||||
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"];
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
defmodule HahaYesTest do
|
defmodule HahaYesTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
doctest HahaYes
|
doctest HahaYes.Utility
|
||||||
|
|
||||||
test "greets the world" do
|
@tag :tmp_dir
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue