-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathregistry.go
More file actions
45 lines (41 loc) · 925 Bytes
/
registry.go
File metadata and controls
45 lines (41 loc) · 925 Bytes
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
package main
import (
"errors"
"net/url"
"os/exec"
"strings"
)
type IndexFn func(f File, ch chan File)
func Index(f File, ch chan File) {
var fn IndexFn
u := f.Url
switch {
case u.Scheme == "dav", u.Scheme == "davs":
fn = Dav
case strings.HasSuffix(u.Host, "zdf.de"):
fn = Zdf
case strings.HasSuffix(u.Host, "tumblr.com"):
fn = Tumblr
default:
c := exec.Command("/usr/bin/env", "youtube-dl", "--extractor-descriptions")
output, err := c.CombinedOutput()
if err != nil {
err = errors.New(err.Error() + " (trying without youtube-dl support)")
}
for _, line := range strings.Split(string(output), "\n") {
if strings.Contains(u.Host, strings.ToLower(line)) {
fn = YoutubeDl
}
}
}
if fn == nil {
err := errors.New("No Indexer found for: " + f.Url.String())
f.SendErr(ch, &err)
} else {
fn(f, ch)
}
}
func replaceHost(u *url.URL, h string) url.URL {
u.Host = h
return *u
}