Added yt thumbnails

This commit is contained in:
Javier 2014-10-11 13:54:43 +02:00
parent b2951061b7
commit 89c25cc426

View File

@ -16,6 +16,8 @@ function on_msg_receive (msg)
else
if is_image_url(msg.text) then
send_image_from_url (msg)
elseif is_youtube_url(msg.text) then
send_youtube_thumbnail(msg.text)
else
if is_file_url(msg.text) then
send_file_from_url(msg)
@ -67,6 +69,20 @@ function is_image_url(text)
return false
end
function is_youtube_url(text)
-- http://stackoverflow.com/questions/19377262/regex-for-youtube-url
not_full_yt_url = string.match(text, "youtube.com/watch%?v=([A-Za-z0-9-]*)") == nil
not_short_yt_url = string.match(text, "youtu.be/([A-Za-z0-9-]*)") == nil
yt = full_yt_url or short_yt_url
return yt
end
function send_youtube_thumbnail(msg)
yt_thumbnail = "http://img.youtube.com/vi/".. string.match(msg.text, "([A-Za-z0-9-]*)").."/hqdefault.jpg"
file = download_to_file(yt_thumbnail)
send_photo(get_receiver(msg), file, ok_cb, false)
end
function is_file_url(text)
last = string.get_last_word(text)
extension = string.get_extension_from_filename(last)