Remove getYouTubeId from util.go.
This bit of code has long been moved to the YouTube parser package.develop
parent
f97c872b2e
commit
0eb16f9975
32
util.go
32
util.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
@ -28,34 +27,3 @@ func stripIrcFormatting(text string) string {
|
|||
text = rxIrcColor.ReplaceAllLiteralString(text, "")
|
||||
return text
|
||||
}
|
||||
|
||||
func getYouTubeId(uri *url.URL) string {
|
||||
u := &(*uri)
|
||||
u.Scheme = strings.ToLower(u.Scheme)
|
||||
u.Host = strings.ToLower(u.Host)
|
||||
|
||||
// Must be an HTTP URL
|
||||
if u.Scheme != "http" && u.Scheme != "https" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Remove www. prefix from hostname
|
||||
if strings.HasPrefix(u.Host, "www.") {
|
||||
u.Host = u.Host[4:]
|
||||
}
|
||||
|
||||
switch strings.ToLower(u.Host) {
|
||||
case "youtu.be":
|
||||
// http://youtu.be/{id}
|
||||
if s, err := url.QueryUnescape(strings.TrimLeft(u.Path, "/")); err == nil {
|
||||
return s
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
case "youtube.com":
|
||||
// http://youtube.com/watch?v={id}
|
||||
return u.Query().Get("v")
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue