Commit ae619f40 authored by Jonny Schäfer's avatar Jonny Schäfer
Browse files

add capability to use scripts in ~/.config/tubus/scripts as custom player

parent 317abd88
......@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"sync"
"path/filepath"
)
// maps user input to events
......@@ -385,6 +386,15 @@ func logicSetPlayer(player string) {
func logicPlay(player string, id int) {
video := logicVarVideos[id]
cmd := append(strings.Split(player, " "), "https://www.youtube.com/watch?v="+video.url)
script := filepath.Join(storeDefaultScripts, cmd[0])
exists, err := storeFileExists(script)
errorCare(err)
if exists {
cmd[0] = script
player = "$" + player // visual indicator for user script
}
exe := exec.Command(cmd[0], cmd[1:]...)
if err := exe.Start(); err != nil {
cliStatusError(fmt.Sprint("playback error: ", err))
......
......@@ -10,6 +10,7 @@ import (
var (
storeDefaultPlayer = "" // Contains path created by init()
storeDefaultSubscriptions = "" // Contains path created by init()
storeDefaultScripts = "" // Contains path created by init()
)
// init checks if the configuration directory exist and creates
......@@ -22,10 +23,12 @@ func init() {
home := user.HomeDir
conf := filepath.Join(home, ".config/tubus")
exists, err := storeFileExists(conf)
storeDefaultScripts = filepath.Join(conf, "scripts")
exists, err := storeFileExists(storeDefaultScripts)
errorCare(err)
if !exists {
errorCare(storeCreateDirectory(conf))
errorCare(storeCreateDirectory(storeDefaultScripts))
}
storeDefaultSubscriptions = filepath.Join(conf, "subscriptions")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment