summaryrefslogtreecommitdiff
path: root/rhimport
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-07-21 20:23:17 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-07-21 20:23:17 (GMT)
commit928b513a2b2be04babb9d2348ea5e28e1cb8bd7e (patch)
tree8ccc6ba8fe1d6c5a094383d827e0a7c22482d784 /rhimport
parent4841d6979ace3e6a4a468d9114d86e86dc00a8e3 (diff)
reading CBA Api right before every call to youtube-dl
Diffstat (limited to 'rhimport')
-rw-r--r--rhimport/core.go24
-rw-r--r--rhimport/fetcher.go5
2 files changed, 17 insertions, 12 deletions
diff --git a/rhimport/core.go b/rhimport/core.go
index ec184bb..9780485 100644
--- a/rhimport/core.go
+++ b/rhimport/core.go
@@ -52,10 +52,9 @@ const (
)
var (
- bool2str = map[bool]string{false: "0", true: "1"}
- rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags)
- rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags)
- cba_api_key = ""
+ bool2str = map[bool]string{false: "0", true: "1"}
+ rhl = log.New(os.Stderr, "[rhimport]\t", log.LstdFlags)
+ rhdl = log.New(ioutil.Discard, "[rhimport-dbg]\t", log.LstdFlags)
)
func init() {
@@ -63,13 +62,6 @@ func init() {
rhdl.SetOutput(os.Stderr)
}
- key_file, err := os.Open(CBA_API_KEY_FILE)
- if err == nil {
- defer key_file.Close()
- data, _ := bufio.NewReader(key_file).ReadString('\n')
- cba_api_key = strings.TrimSpace(string(data))
- }
-
curl.GlobalInit(curl.GLOBAL_ALL)
fetcherInit()
}
@@ -124,6 +116,16 @@ func (p *FilePolicy) FromString(str string) error {
return nil
}
+func getCBAApiKey() string {
+ key_file, err := os.Open(CBA_API_KEY_FILE)
+ if err == nil {
+ defer key_file.Close()
+ data, _ := bufio.NewReader(key_file).ReadString('\n')
+ return strings.TrimSpace(string(data))
+ }
+ return ""
+}
+
type Context struct {
conf *Config
db *rddb.DBChan
diff --git a/rhimport/fetcher.go b/rhimport/fetcher.go
index 2264f30..0a72342 100644
--- a/rhimport/fetcher.go
+++ b/rhimport/fetcher.go
@@ -136,7 +136,9 @@ func checkYoutubeDL(ctx *Context, res *Result, uri *url.URL) *YoutubeDLInfo {
var stderr, stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
- cmd.Env = append(os.Environ(), "CBA_API_KEY="+cba_api_key)
+ if cba_api_key := getCBAApiKey(); cba_api_key != "" {
+ cmd.Env = append(os.Environ(), "CBA_API_KEY="+cba_api_key)
+ }
done := make(chan *YoutubeDLInfo)
go func() {
@@ -209,6 +211,7 @@ func fetchFileCurl(ctx *Context, res *Result, uri *url.URL) (err error) {
} else {
cbdata.remotename = info.Title + "." + info.Ext
}
+ cbdata.remotename = strings.NewReplacer("/", "_").Replace(cbdata.remotename)
switch strings.ToLower(info.Extractor) {
case "generic":