forked from scakemyer/quasar
-
Notifications
You must be signed in to change notification settings - Fork 44
/
url.go
43 lines (35 loc) · 892 Bytes
/
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
package util
import (
"fmt"
"net/url"
"os"
"strings"
)
// TrailerURL returns trailer url, constructed for Kodi
func TrailerURL(u string) (ret string) {
if len(u) == 0 {
return
}
if strings.Contains(u, "?v=") {
ret = fmt.Sprintf("plugin://plugin.video.youtube/play/?video_id=%s", strings.Split(u, "?v=")[1])
} else {
ret = fmt.Sprintf("plugin://plugin.video.youtube/play/?video_id=%s", u)
}
return
}
// DecodeFileURL decodes file path from url
func DecodeFileURL(u string) (ret string) {
us := strings.Split(u, string("/"))
for i, v := range us {
us[i], _ = url.PathUnescape(v)
}
return strings.Join(us, string(os.PathSeparator))
}
// EncodeFileURL encode file path into proper url
func EncodeFileURL(u string) (ret string) {
us := strings.Split(u, string(os.PathSeparator))
for i, v := range us {
us[i] = url.PathEscape(v)
}
return strings.Join(us, "/")
}