summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Gerus <rgerus@dpd.com.pl>2015-12-22 11:00:12 +0100
committerRobert Gerus <rgerus@dpd.com.pl>2015-12-22 11:00:12 +0100
commit8f4345e7d02464edefddf6bd058194ee5602504b (patch)
treef6a7f567de258e42fa7a5cbc659ff4f4a473ddec
parent42e4ecddfa1bb43e6e8efb14c5bde8f6db8b8220 (diff)
downloadgorepost-8f4345e7d02464edefddf6bd058194ee5602504b.tar.gz
gorepost-8f4345e7d02464edefddf6bd058194ee5602504b.tar.bz2
gorepost-8f4345e7d02464edefddf6bd058194ee5602504b.tar.xz
gorepost-8f4345e7d02464edefddf6bd058194ee5602504b.zip
WIP
-rw-r--r--bot/urltitle.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/bot/urltitle.go b/bot/urltitle.go
index 8b2fe13..917c39c 100644
--- a/bot/urltitle.go
+++ b/bot/urltitle.go
@@ -19,6 +19,30 @@ var trimTitle *regexp.Regexp
var trimLink *regexp.Regexp
var enc = charmap.ISO8859_2
+func youtube(l string) string {
+ // get data from
+ // https://www.youtube.com/oembed?format=json&url=http://www.youtube.com/watch?v=dQw4w9WgXcQ
+ return "placeholder"
+}
+
+func youtubeLong(l string) string {
+ pattern := regexp.MustCompile(`/watch[?]v[=](?P<vid>[a-zA-Z0-9-_]+)`)
+ res := []byte{}
+ for _, s := range pattern.FindAllSubmatchIndex([]byte(l), -1) {
+ res = pattern.ExpandString(res, "$cmd", l, s)
+ }
+ return youtube(string(res))
+}
+
+func youtubeShort(l string) string {
+ pattern := regexp.MustCompile(`youtu.be/(?P<vid>[a-zA-Z0-9-_]+)`)
+ res := []byte{}
+ for _, s := range pattern.FindAllSubmatchIndex([]byte(l), -1) {
+ res = pattern.ExpandString(res, "$cmd", l, s)
+ }
+ return youtube(string(res))
+}
+
func genericURLTitle(l string) string {
title, err := httpGetXpath(l, "//head/title")
if err == errElementNotFound {
@@ -43,6 +67,14 @@ var customDataFetchers = []struct {
fetcher func(l string) string
}{
{
+ re: regexp.MustCompile("//(www.)?youtube.com)/"),
+ fetcher: youtubeLong,
+ },
+ {
+ re: regexp.MustCompile("//youtu.be/"),
+ fetcher: youtubeShort,
+ },
+ {
re: regexp.MustCompile(".*"),
fetcher: genericURLTitle,
},