From c9258d254719a2615ad2950595dc8df2717ac26c Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sat, 1 Aug 2015 13:28:23 +0200 Subject: [PATCH] youtube_dl improved --- plugins/pluginsold/helpold.lua | 70 ++++++++++++++++++++++++ plugins/{ => pluginsold}/youtube_mp3.lua | 0 plugins/youtube_dl.lua | 14 +++-- 3 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 plugins/pluginsold/helpold.lua rename plugins/{ => pluginsold}/youtube_mp3.lua (100%) diff --git a/plugins/pluginsold/helpold.lua b/plugins/pluginsold/helpold.lua new file mode 100644 index 0000000..ff18984 --- /dev/null +++ b/plugins/pluginsold/helpold.lua @@ -0,0 +1,70 @@ +do + +-- Returns true if is not empty +local function has_usage_data(dict) + if (dict.usage == nil or dict.usage == '') then + return false + end + return true +end + +-- Get commands for that plugin +local function plugin_help(name) + local plugin = plugins[name] + if not plugin then return nil end + + local text = "" + if (type(plugin.usage) == "table") then + for ku,usage in pairs(plugin.usage) do + text = text..usage..'\n' + end + text = text..'\n' + elseif has_usage_data(plugin) then -- Is not empty + text = text..plugin.usage..'\n\n' + end + return text +end + +-- !help command +local function telegram_help() + local text = "Plugin Liste: \n\n" + -- Plugins names + for name in pairs(plugins) do + text = text..name..'\n' + end + text = text..'\n'..'Benutze "/hilfe [Plugin Name]" für mehr Informationen' + text = text..'\n'..'Oder "/hilfe all" um alles zu sehen.' + return text +end + +-- !help all command +local function help_all() + local ret = "" + for name in pairs(plugins) do + ret = ret .. plugin_help(name) + end + return ret +end + +local function run(msg, matches) + if matches[1] == "/hilfe" then + return telegram_help() + elseif matches[1] == "/hilfe all" then + return help_all() + else + local text = plugin_help(matches[1]) + if not text then + text = telegram_help() + end + return text + end +end + +return { + description = "Zeigt die Plugins und Befehle", + usage = {"/hilfe","/hilfe all","/hilfe [Plugin]"}, + patterns = {"^/hilfe$","^/hilfe all","^/hilfe (.+)"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/youtube_mp3.lua b/plugins/pluginsold/youtube_mp3.lua similarity index 100% rename from plugins/youtube_mp3.lua rename to plugins/pluginsold/youtube_mp3.lua diff --git a/plugins/youtube_dl.lua b/plugins/youtube_dl.lua index 4874374..bfae7e3 100644 --- a/plugins/youtube_dl.lua +++ b/plugins/youtube_dl.lua @@ -5,17 +5,23 @@ function run(msg, matches) local receiver = get_receiver(msg) if string.match(msg.text, '"') then return 'Vergiss es' - else + end + if string.match(msg.text, "/mp4") then text = run_bash("youtube-dl -o tmp/video.mp4 --no-continue " .. URL) send_video(get_receiver(msg), "tmp/video.mp4", ok_cb, false) - return URL .. ' wurde gedownloadet und wird jetzt gesendet! \nDas kann je nach Video sehr lang dauern! \nAlso habt Geduld!' end + if string.match(msg.text, "/mp3") then + text = run_bash("youtube-dl -o tmp/sound.mp3 --audio-format mp3 --no-continue " .. URL) + send_audio(get_receiver(msg), "tmp/sound.mp3", ok_cb, false) + end + print(text) + return URL .. ' wurde gedownloadet und wird jetzt gesendet! \nDas kann je nach Video sehr lang dauern! \nAlso habt Geduld!' end return { description = "Downloadet und sendet ein Video von verschiedenen Seiten mit youtube-dl", - usage = {"/dl [Link]"}, - patterns = {"^/dl (https?://[%w-_%.%?%.:/%+=&]+)$"}, + 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-_%.%?%.:/%+=&]+)$"}, run = run } --by Akamaru [https://ponywave.de] \ No newline at end of file