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
2015-12-19 15:17:45 +01:00

46 lines
1.7 KiB
Lua

-- Requires: sudo apt-get install youtube-dl
-- See https://github.com/rg3/youtube-dl/blob/master/README.md#options
function run(msg, matches)
URL = matches[1]
local receiver = get_receiver(msg)
if string.match(msg.text, '"') then
return 'Vergiss es'
end
if string.match(msg.text, "/mp4") then
text = run_bash('youtube-dl -o "tmp/%(title)s.%(ext)s" '..URL)
video = string.match(text, 'Merging formats into "tmp/(.*)"')
if not video then
file = string.match(text, '%[download%] (.*) has already been downloaded')
else
file = 'tmp/'..video
end
send_video(get_receiver(msg), file, ok_cb, false)
end
if string.match(msg.text, "/mp3") then
text = run_bash('youtube-dl -o "tmp/%(title)s.%(ext)s" --extract-audio --audio-format mp3 '..URL)
audio = string.match(text, '%[avconv%] Destination: tmp/(.*).mp3')
file = 'tmp/'..audio..'.mp3'
send_audio(get_receiver(msg), file, ok_cb, false)
end
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", "")
message = string.gsub(message, ".mkv", "")
message = string.gsub(message, ".flv", "")
return message
end
return {
description = "Downloadet und sendet ein Video von verschiedenen Seiten mit youtube-dl",
usage = {"/mp4 [Link] (Um Video zu laden)","/mp3 [Link] (Um Audio zu laden)","Unterstützte Seiten: PonyWave.de/a/youtubedl"},
patterns = {"^/mp4 (https?://[%w-_%.%?%.:/%+=&]+)$","^/mp3 (https?://[%w-_%.%?%.:/%+=&]+)$"},
run = run
}
--by Akamaru [https://ponywave.de]