This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/youtube_dl.lua

40 lines
1.5 KiB
Lua
Raw Normal View History

2015-11-12 17:42:03 +01:00
-- Requires: sudo apt-get install youtube-dl
-- See https://github.com/rg3/youtube-dl/blob/master/README.md#options
2015-05-24 18:23:30 +02:00
function run(msg, matches)
URL = matches[1]
local receiver = get_receiver(msg)
2015-11-12 17:42:03 +01:00
if string.match(msg.text, '"') then
return 'Vergiss es'
2015-08-01 13:28:23 +02:00
end
2015-11-12 17:42:03 +01:00
2015-08-01 13:28:23 +02:00
if string.match(msg.text, "/mp4") then
2015-11-12 17:42:03 +01:00
text = run_bash('youtube-dl -o "tmp/%(title)s.%(ext)s" --no-continue '..URL)
video = string.match(text,"Destination: (.*).mp4")
file = video..'.mp4'
send_video(get_receiver(msg), file, ok_cb, false)
end
2015-11-12 17:42:03 +01:00
2015-08-01 13:28:23 +02:00
if string.match(msg.text, "/mp3") then
2015-11-12 17:42:03 +01:00
text = run_bash("youtube-dl --extract-audio --audio-format mp3 " .. URL)
audio = string.match(text,"Destination: (.*).m4a")
file = audio..'.mp3'
send_audio(get_receiver(msg), file, ok_cb, false)
2015-08-01 13:28:23 +02:00
end
2015-11-12 17:42:03 +01:00
print('Sende: '..file)
message = '"'..file..'" wurde gedownloadet und wird jetzt gesendet! \nDas kann je nach Video sehr lang dauern! \nAlso habt Geduld!'
message = string.gsub(message, "tmp/", "")
message = string.gsub(message, ".mp3", "")
message = string.gsub(message, ".mp4", "")
return message
2015-05-24 18:23:30 +02:00
end
return {
2015-06-06 22:15:31 +02:00
description = "Downloadet und sendet ein Video von verschiedenen Seiten mit youtube-dl",
2015-08-01 13:28:23 +02:00
usage = {"/mp4 [Link] (Um Video zu laden)","/mp3 [Link] (Um Audio zu laden)","Unterstützte Seiten: https://ponywave.de/a/youtubedl"},
patterns = {"^/mp4 (https?://[%w-_%.%?%.:/%+=&]+)$","^/mp3 (https?://[%w-_%.%?%.:/%+=&]+)$"},
2015-05-24 18:23:30 +02:00
run = run
}
--by Akamaru [https://ponywave.de]