Discord_Elixir_test/lib/HahaCommands/download.ex

38 lines
1 KiB
Elixir
Raw Normal View History

2024-10-12 17:05:40 +02:00
defmodule HahaYes.Commands.Download do
2024-10-12 14:38:08 +02:00
@moduledoc """
2024-10-12 17:13:33 +02:00
Download command
2024-10-12 14:38:08 +02:00
"""
alias Nostrum.Api
@doc """
2024-10-12 17:39:23 +02:00
Download the video sent by the user with yt-dlp.
2024-10-12 14:38:08 +02:00
## Parameters
- url: String that represents the URL to download a video from.
## Examples
2024-10-12 17:39:23 +02:00
User: h3h3 download https://x.com/i/status/1845119662402511072
2024-10-12 14:38:08 +02:00
Bot: <video file>
User: h3h3 download https://www.youtube.com/watch?v=ryS7TS_J7KA
Bot: <video file>
"""
2024-10-12 17:05:40 +02:00
def execute(msg) do
2024-10-12 17:33:09 +02:00
{:ok, loading} = Api.create_message(msg.channel_id, "Downloading...")
2024-10-12 14:38:08 +02:00
arg = String.replace(msg.content, "h3h3 download ", "")
2024-10-12 17:38:34 +02:00
opt = ["-f", "bestvideo[height<=?480]+bestaudio/best", arg, "-o", "#{System.tmp_dir}/#{msg.id}.%(ext)si", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];
2024-10-12 14:38:08 +02:00
System.cmd("yt-dlp", opt)
2024-10-12 17:33:09 +02:00
Api.delete_message(loading.channel_id, loading.id)
Api.delete_message(msg)
2024-10-12 17:38:34 +02:00
Api.create_message(msg.channel_id, files: [Enum.at(Path.wildcard("#{System.tmp_dir}/#{msg.id}.*"), 0)])
2024-10-12 14:38:08 +02:00
end
end