This commit is contained in:
Loïc Bersier 2024-10-13 17:41:55 +02:00
parent 23a884339d
commit 4c8d48c575
2 changed files with 31 additions and 0 deletions

View file

@ -21,6 +21,15 @@ defmodule HahaYes.Commands.Download do
User: h3h3 download https://www.youtube.com/watch?v=ryS7TS_J7KA
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
url = Enum.at(args, 0)

View file

@ -1,4 +1,26 @@
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
opt = ["-f", format, url, "-o", "#{output}.%(ext)s", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];