Compare commits
2 commits
79ebe9b1e1
...
23a884339d
Author | SHA1 | Date | |
---|---|---|---|
23a884339d | |||
80e0f53e85 |
3 changed files with 33 additions and 23 deletions
|
@ -26,12 +26,7 @@ defmodule HahaYes.Commands.Download do
|
||||||
url = Enum.at(args, 0)
|
url = Enum.at(args, 0)
|
||||||
{:ok, loading} = Api.create_message(msg.channel_id, "Downloading...")
|
{:ok, loading} = Api.create_message(msg.channel_id, "Downloading...")
|
||||||
|
|
||||||
|
with {:ok, output} <- HahaYes.Utility.download(url, "#{System.tmp_dir}/#{msg.id}") do
|
||||||
opt = ["-f", "bestvideo[height<=?480]+bestaudio/best", url, "-o", "#{System.tmp_dir}/#{msg.id}.%(ext)si", "--force-overwrites", "--playlist-reverse", "--no-playlist", "--remux-video=mp4/webm/mov", "--no-warnings"];
|
|
||||||
|
|
||||||
System.cmd("yt-dlp", opt)
|
|
||||||
|
|
||||||
output = Enum.at(Path.wildcard("#{System.tmp_dir}/#{msg.id}.*"), 0)
|
|
||||||
{:ok, file} = File.stat(output)
|
{:ok, file} = File.stat(output)
|
||||||
file_size =
|
file_size =
|
||||||
file.size / 1000000.0
|
file.size / 1000000.0
|
||||||
|
@ -52,5 +47,8 @@ defmodule HahaYes.Commands.Download do
|
||||||
|> put_footer("You can get the original video by clicking on the \"Downloaded by #{msg.author.username}\" message!")
|
|> put_footer("You can get the original video by clicking on the \"Downloaded by #{msg.author.username}\" message!")
|
||||||
Api.create_message(msg.channel_id, files: [output], embeds: [embed])
|
Api.create_message(msg.channel_id, files: [output], embeds: [embed])
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
{:error, error} -> Api.create_message(msg.channel_id, "`#{error}`")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,7 +21,7 @@ defmodule HahaYes.Events.MessagesConsumer do
|
||||||
|> Enum.at(0)
|
|> Enum.at(0)
|
||||||
|> String.downcase()
|
|> String.downcase()
|
||||||
|> String.capitalize()
|
|> String.capitalize()
|
||||||
|> then(& Module.concat(HahaYes.Commands, &1).execute(msg, ws_state, String.split(String.replace(String.downcase(msg.content), "#{prefix}#{String.downcase(&1)} ", ""))))
|
|> then(& Module.safe_concat(HahaYes.Commands, &1).execute(msg, ws_state, String.split(String.replace(String.downcase(msg.content), "#{prefix}#{String.downcase(&1)} ", ""))))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
12
lib/haha_yes/utils.ex
Normal file
12
lib/haha_yes/utils.ex
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
defmodule HahaYes.Utility 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"];
|
||||||
|
|
||||||
|
{error_output, status} = System.cmd("yt-dlp", opt, [stderr_to_stdout: true])
|
||||||
|
if status !== 0 do
|
||||||
|
{:error, error_output}
|
||||||
|
else
|
||||||
|
{:ok, Enum.at(Path.wildcard("#{output}.*"), 0)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue