diff --git a/common/link.go b/common/link.go index 04d9782..68f810c 100644 --- a/common/link.go +++ b/common/link.go @@ -47,8 +47,8 @@ var re_validLink = *regexp.MustCompile(`[a-zA-Z0-9:._\+]{1,256}\.[a-zA-Z0-9()]{1 func (l *Link) validateLink() error { url := l.Url + url = cleanupLink(url) if re_validLink.MatchString(url) { - url = stripRefFromLink(url) if len(url) <= 8 { // lets be stupid when the link is too short @@ -68,11 +68,19 @@ func (l *Link) validateLink() error { return fmt.Errorf("Invalid link: %v", l.Url) } -func stripRefFromLink(link string) string { +var replacements = map[string]string{ + "m.imdb.com": "imdb.com", +} + +func cleanupLink(link string) string { idx := strings.Index(link, "/?") if idx != -1 { - return link[:idx] + link = link[:idx] } + for from, to := range replacements { + link = strings.Replace(link, from, to, 1) + } + return link }