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

47 lines
1.7 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)
2016-02-14 21:02:55 +01:00
local URL = matches[1]
2015-05-24 18:23:30 +02:00
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
if string.match(msg.text, "#mp4") then
2015-11-22 14:40:34 +01:00
text = run_bash('youtube-dl -o "tmp/%(title)s.%(ext)s" '..URL)
video = string.match(text, 'Merging formats into "tmp/(.*)"')
2015-11-18 20:12:06 +01:00
if not video then
file = string.match(text, '%[download%] (.*) has already been downloaded')
else
file = 'tmp/'..video
2015-11-18 20:12:06 +01:00
end
2016-07-07 21:24:02 +02:00
send_document(get_receiver(msg), file, ok_cb, false)
end
2015-11-12 17:42:03 +01:00
if string.match(msg.text, "#mp3") then
2015-11-18 20:12:06 +01:00
text = run_bash('youtube-dl -o "tmp/%(title)s.%(ext)s" --extract-audio --audio-format mp3 '..URL)
2016-06-11 22:01:53 +02:00
audio = string.match(text, '%[ffmpeg%] Destination: tmp/(.*).mp3')
2015-11-18 20:12:06 +01:00
file = 'tmp/'..audio..'.mp3'
2015-11-12 17:42:03 +01:00
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", "")
2015-11-22 14:40:34 +01:00
message = string.gsub(message, ".mkv", "")
message = string.gsub(message, ".flv", "")
2016-07-07 21:24:02 +02:00
message = string.gsub(message, ".webm", "")
2015-11-12 17:42:03 +01:00
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",
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-_%.%?%.:/%+=&]+)$"},
2015-05-24 18:23:30 +02:00
run = run
}
--by Akamaru [https://ponywave.de]