summaryrefslogtreecommitdiff
path: root/modules/3-youtube.rkt
diff options
context:
space:
mode:
authortilpner2018-04-17 23:13:23 +0200
committertilpner2018-04-17 23:13:23 +0200
commit5e05e5e7e5c363131d6fb3e2f11e761c1f69c222 (patch)
tree25ee061b145a324bd71be1e6bdabb09b9c815b52 /modules/3-youtube.rkt
downloadmeep-5e05e5e7e5c363131d6fb3e2f11e761c1f69c222.tar.gz
meep-5e05e5e7e5c363131d6fb3e2f11e761c1f69c222.tar.xz
meep-5e05e5e7e5c363131d6fb3e2f11e761c1f69c222.zip
Initial commit
Diffstat (limited to 'modules/3-youtube.rkt')
-rw-r--r--modules/3-youtube.rkt26
1 files changed, 26 insertions, 0 deletions
diff --git a/modules/3-youtube.rkt b/modules/3-youtube.rkt
new file mode 100644
index 0000000..835bee9
--- /dev/null
+++ b/modules/3-youtube.rkt
@@ -0,0 +1,26 @@
+#lang racket/base
+(require irc/bot racket/string net/url net/uri-codec json)
+(provide (all-defined-out))
+
+(define (youtube-query url)
+ (call/input-url
+ (string->url (format "https://noembed.com/embed?url=~a"
+ (uri-encode (url->string url))))
+ get-pure-port read-json))
+
+; catch youtube.com and youtu.be
+(define (extract-youtube-url s)
+ (define (is-yt-url u)
+ (and (url-host u)
+ (string-contains? (url-host u) "youtu")))
+
+ (let* ([urls (map string->url (string-split s))])
+ (findf is-yt-url urls)))
+
+(on (and (command-is 'PRIVMSG)
+ (context-is "#code"))
+ (let ([url (extract-youtube-url (suffix))])
+ (when url
+ (let* ([response (youtube-query url)]
+ [title (hash-ref response 'title)])
+ (reply (format "\"~a\"" title))))))