renamed yt functions

This commit is contained in:
yago 2014-10-11 16:38:02 +02:00
parent 6201dd66dc
commit a285e45b07
2 changed files with 10 additions and 17 deletions

View File

@ -16,7 +16,7 @@ function on_msg_receive (msg)
else else
if is_image_url(msg.text) then if is_image_url(msg.text) then
send_image_from_url (msg) send_image_from_url (msg)
elseif is_youtube_url(msg.text) then elseif get_youtube_code(msg.text) then
send_youtube_thumbnail(msg) send_youtube_thumbnail(msg)
else else
if is_file_url(msg.text) then if is_file_url(msg.text) then
@ -69,28 +69,21 @@ function is_image_url(text)
return false return false
end end
function is_youtube_url(text) function get_youtube_code( text )
-- http://stackoverflow.com/questions/19377262/regex-for-youtube-url local yt_normal = string.match(text, "youtube.com/watch%?v=([A-Za-z0-9-]+)")
if string.match(text, "youtube.com/watch%?v=([A-Za-z0-9-]+)") then if yt_normal then
return true return yt_normal
end end
if string.match(text, "youtu.be/([A-Za-z0-9-]+)") then yt_short = string.match(text, "youtu.be/([A-Za-z0-9-]+)")
return true if yt_short then
return yt_short
end end
return false return false
end end
function send_youtube_thumbnail(msg) function send_youtube_thumbnail(msg)
local yt_normal = string.match(msg.text, "youtube.com/watch%?v=([A-Za-z0-9-]+)") yt_code = get_youtube_code(msg.text)
if yt_normal then
yt_code = yt_normal
end
yt_short = string.match(msg.text, "youtu.be/([A-Za-z0-9-]+)")
if yt_short then
yt_code = yt_short
end
yt_thumbnail = "http://img.youtube.com/vi/".. yt_code .."/hqdefault.jpg" yt_thumbnail = "http://img.youtube.com/vi/".. yt_code .."/hqdefault.jpg"
print (yt_thumbnail)
file = download_to_file(yt_thumbnail) file = download_to_file(yt_thumbnail)
send_photo(get_receiver(msg), file, ok_cb, false) send_photo(get_receiver(msg), file, ok_cb, false)
end end

2
tg

@ -1 +1 @@
Subproject commit 54f6743db74461e6a3394f577671a273a37e01a1 Subproject commit 7a9764f24ac745eb03a72e2ddb69c8574f6a8c2f