Skip to content

Commit

Permalink
CLI and Concurrency (#29)
Browse files Browse the repository at this point in the history
* Fix: ArteTV provider #13  #18

- Adaptation to the new Arte web sites and APIS
- Refactoring of ARTTV provider:
- Better handling of collections
- Fix for episode naming
- Fix for overwriting episodes with no names

* AtrTV delete dead code

* Improvement: download from command line
Close: #26

* Remove debug message

* ARTETV simplify video stream selection
Select best resultion for preferred audio version

* Add "VO" to preferred version

* Refactor ARTETV for returning channel of show

* Refactoring FRANCETV for returning a channel of shows

* Refactoring GULLI provider for using channels
  • Loading branch information
simulot committed Sep 11, 2019
1 parent d79d8c6 commit 7f047e6
Show file tree
Hide file tree
Showing 20 changed files with 762 additions and 2,158 deletions.
64 changes: 43 additions & 21 deletions cmd/aspiratv/config.go
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"
"time"

Expand All @@ -20,8 +22,34 @@ type Config struct {
ConfigFile string // Name of configuration file
WatchList []*providers.MatchRequest // Slice of show matchers
Headless bool // When true, no progression bar
ConcurrentTasks int // Number of concurrent downloadss
ConcurrentTasks int // Number of concurrent downloads
Providers map[string]ProviderConfig
Provider string // Provider for dowload command
Destination string // Destination folder for dowload command

}

func (a *app) Initialize() {
a.ReadConfig(a.Config.ConfigFile)

// Check ans normalize configuration file
a.Config.Check()

// Check ffmpeg presence
var cmd *exec.Cmd
if runtime.GOOS == "windows" {
cmd = exec.Command("where", "ffmpeg")
} else {
cmd = exec.Command("which", "ffmpeg")
}
b, err := cmd.Output()
if err != nil {
log.Fatal("Missing ffmpeg on your system, it's required to download video files.")
}
a.ffmpeg = strings.Trim(strings.Trim(string(b), "\r\n"), "\n")
if a.Config.Debug {
log.Printf("FFMPEG path: %q", a.ffmpeg)
}
}

type ProviderConfig struct {
Expand Down Expand Up @@ -77,38 +105,32 @@ func WriteConfig() {
}

// ReadConfig read the JSON configuration file
func ReadConfig(configFile string) (*Config, error) {
func (a *app) ReadConfig(configFile string) error {
f, err := os.Open(configFile)
if err != nil {
return nil, fmt.Errorf("Can't open configuration file: %v", err)
return fmt.Errorf("Can't open configuration file: %v", err)
}
defer f.Close()
conf := &Config{}
d := json.NewDecoder(f)
err = d.Decode(conf)
err = d.Decode(&a.Config)
if err != nil {
return nil, fmt.Errorf("Can't decode configuration file: %v", err)
return fmt.Errorf("Can't decode configuration file: %v", err)
}
return conf, nil
return nil
}

// ReadConfigOrDie create a stub of config.json when it is missing from disk
func ReadConfigOrDie(cli *Config) *Config {
conf, err := ReadConfig(cli.ConfigFile)
if err != nil {
log.Fatalf("Fatal: %v", err)
}
// Set flags comming from CLI
conf.Debug = cli.Debug
conf.Force = cli.Force
conf.ConfigFile = cli.ConfigFile
conf.Headless = cli.Headless
conf.ConcurrentTasks = cli.ConcurrentTasks
return conf
}
// // ReadConfigOrDie create a stub of config.json when it is missing from disk
// func ReadConfigOrDie(conf *Config) {
// err := ReadConfig(conf.ConfigFile, conf)
// if err != nil {
// log.Fatalf("Fatal: %v", err)
// }

// }

// Check the configuration or die
func (c *Config) Check() {

// Expand paths
for d, p := range c.Destinations {
c.Destinations[d] = os.ExpandEnv(p)
Expand Down
62 changes: 25 additions & 37 deletions cmd/aspiratv/config.json 100755 → 100644
@@ -1,37 +1,25 @@
{
"PullInterval": "7h30m",
"Destinations": {
"Documentaires": "${HOME}/Videos/Documentaires",
"Jeunesse": "${HOME}/Videos/Jeunesse",
"Courts": "${HOME}/Videos/Courts"
},
"Providers": {
"artetv": {
"Enabled": false
},
"gulli":{
"Enabled": false,
"Settings":{
"PreferedFormat": ".m38u"
}
},
"francetv":{
"Enabled": true
}
},
"WatchList": [
{
"Show": "Si j'étais un animal",
"Title": "",
"Pitch": "",
"Provider": "francetv",
"Destination": "Jeunesse"
},
{
"Show": "Oggy et les cafards",
"Pitch": "",
"Provider": "gulli",
"Destination": "Jeunesse"
}
]
}
{
"PullInterval": "7h",
"Destinations": {
"Documentaires": "${HOME}/Videos/Documentaires",
"Jeunesse": "${HOME}/Videos/Jeunesse",
"Courts": "${HOME}/Videos/Courts"
},
"Providers": {
"francetv": {
"enabled": true
},
"gulli": {
"enabled": false
}
},
"WatchList": [
{
"Show": "Lapins crétins",
"Title": "",
"Pitch": "",
"Provider": "francetv",
"Destination": "Jeunesse"
}
]
}

0 comments on commit 7f047e6

Please sign in to comment.