Skip to content

Commit

Permalink
feat: 🎸 download youtube video
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaddeusJiang committed Jul 22, 2024
1 parent a862a13 commit ecef83f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/aier_bot/file_downloader.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
defmodule AierBot.FileDownloader do
use Tesla

# youtube video download url: "https://olly.imput.net/api/stream?id=WpsLJCeQ24MBD_xM_3uwu&exp=1721625834931&sig=4UvjCvFD57jU7yrLdwmzRmfsPgPb8KhFIE1DwmnOj14&sec=C1Hty_eEXvswFhzdrDfDZ4cmkSUDgex1aV6mzDSK0dc&iv=ozku3rLJzeV_rVRSzWVlFw"
def download("https://olly.imput.net/api/stream" <> _ = url) do
IO.inspect(url, label: "Download URL")

case get(url) do
{:ok, %Tesla.Env{status: 200, body: body}} ->
file_name = gen_desc_filename() <> ".mp4"
File.write("./.local/storage/#{file_name}", body)
{:ok, file_name, body}

{:ok, %Tesla.Env{status: status}} ->
IO.puts("Failed to download file. Status: #{status}")
{:error, "Failed to download file"}

{:error, reason} ->
IO.puts("Failed to download file. Reason: #{inspect(reason)}")
{:error, "Failed to download file"}
end
end

def download(url) do
IO.inspect(url, label: "Download URL")

# TODO: support youtube video download,
case get(url) do
{:ok, %Tesla.Env{status: 200, body: body, headers: headers}} ->
ext =
Expand Down

0 comments on commit ecef83f

Please sign in to comment.