-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-platform-url.go
46 lines (40 loc) · 1.02 KB
/
video-platform-url.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package videoPlatformURL
import (
"net/url"
"strings"
)
var (
facebookVideoURL = "https://www.facebook.com/plugins/video.php?href="
)
//FindURL Create a well formated URL for different providers
func FindURL(str string, provider string) string {
var url string
switch provider {
case "dailymotion":
url = "http://www.dailymotion.com/video/" + string(str)
case "youtube":
url = "https://www.youtube.com/watch?v=" + string(str)
case "proxy":
url = analyzeDomain(str)
case "digiteka":
// if it's an URL
if strings.Contains(str, "://") {
url = string(str)
} else {
url = "https://www.ultimedia.com/deliver/generic/iframe/mdtk/01836272/src/" + string(str)
}
default:
url = string(str)
}
return url
}
func analyzeDomain(str string) string {
if len(str) > len(facebookVideoURL) && str[0:len(facebookVideoURL)] == facebookVideoURL {
videoURL, err := url.QueryUnescape(str[len(facebookVideoURL):len(str)])
if err != nil {
return str[len(facebookVideoURL):len(str)]
}
return videoURL
}
return str
}