From 928b513a2b2be04babb9d2348ea5e28e1cb8bd7e Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Thu, 21 Jul 2016 22:23:17 +0200 Subject: reading CBA Api right before every call to youtube-dl 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": -- cgit v0.10.2