Skip to content

Commit

Permalink
fix parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ubaldus committed Jul 2, 2024
1 parent 75b262b commit dcfcf92
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
6 changes: 0 additions & 6 deletions cmd/tv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package main

import (
"os"
"tv/internal/core"
"tv/internal/sys"
"tv/internal/web"
Expand Down Expand Up @@ -37,11 +36,6 @@ func main() {
if err := web.Router(); err != nil {
log.Fatal(err)
}
if _, err := os.Stat(sys.Options.MediaPath); os.IsNotExist(err) {
if err := os.MkdirAll(sys.Options.MediaPath, 0755); err != nil {
log.Fatal("Cannot create media folder", err)
}
}
go core.Start()
if err := tibulaWeb.Start(); err != nil {
log.Fatal("Cannot start the web service: ", err)
Expand Down
8 changes: 3 additions & 5 deletions internal/core/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ import (
"github.com/eja/tibula/log"
)

const channelsBatch = 100

func checkChannels() (err error) {
db := tibula.Session()
if err = db.Open(sys.Options.DbType, sys.Options.DbName, sys.Options.DbUser, sys.Options.DbPass, sys.Options.DbHost, sys.Options.DbPort); err != nil {
return
}
for {
timeLastCheck := time.Now().Add(-time.Duration(sys.Options.CheckInterval) * time.Second).Format("2006-01-02 15:04:05")
timeLastCheck := time.Now().Add(-time.Duration(sys.Options.TvCheckInterval) * time.Second).Format("2006-01-02 15:04:05")
timeLastWorking := time.Now().Add(-30 * 24 * time.Hour).Format("2006-01-02 15:04:05")
rows, err := db.Rows(`SELECT * FROM tvChannels WHERE
(checkLast < ? OR checkLast IS NULL OR checkLast = "") AND
Expand All @@ -36,7 +34,7 @@ func checkChannels() (err error) {
name != ""
ORDER BY power DESC, checkLast ASC
LIMIT ?
`, timeLastCheck, timeLastWorking, timeLastWorking, channelsBatch)
`, timeLastCheck, timeLastWorking, timeLastWorking, sys.Options.TvCheckBatch)
if err != nil {
return err
}
Expand All @@ -46,7 +44,7 @@ func checkChannels() (err error) {
var videoSize string
status := 0
ABR := 0
framePath := filepath.Join(sys.Options.MediaPath, row["name"]+".png")
framePath := filepath.Join(sys.Options.TvMediaPath, row["name"]+".png")

cors, subtitles, err := checkPlaylist(row["sourceUrl"])
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
const tag = "[tv] [core]"

func Start() (err error) {
if _, err = os.Stat(sys.Options.MediaPath); err != nil {
err = os.MkdirAll(sys.Options.MediaPath, os.ModePerm)
if _, err = os.Stat(sys.Options.TvMediaPath); err != nil {
err = os.MkdirAll(sys.Options.TvMediaPath, os.ModePerm)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/sys/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
var Options typeConfigSys

func Configure() error {
flag.StringVar(&Options.MediaPath, "media-path", "/opt/eja/tv/media", "Media folder path")
flag.IntVar(&Options.CheckInterval, "check-interval", 3600, "Channels check interval")
flag.StringVar(&Options.TvMediaPath, "tv-media-path", "/opt/eja/tv/media", "Media folder path")
flag.IntVar(&Options.TvCheckInterval, "tv-check-interval", 3600, "Channels check interval")
flag.IntVar(&Options.TvCheckBatch, "tv-check-batch", 10, "Channels check batch")

if err := sys.Configure(); err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions internal/sys/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

type typeConfigSys struct {
sys.TypeConfig
MediaPath string `json:"media_path,omitempty"`
CheckInterval int `json:"check_interval,omitempty"`
TvMediaPath string `json:"tv_media_path,omitempty"`
TvCheckInterval int `json:"tv_check_interval,omitempty"`
TvCheckBatch int `json:"tv_check_batch,omitempty"`
}

var String = sys.String
Expand Down
2 changes: 1 addition & 1 deletion internal/sys/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
package sys

const Name = "tv"
const Version = "8.7.1"
const Version = "8.7.2"
8 changes: 6 additions & 2 deletions internal/sys/wizard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ func Wizard() error {
return err
}

Options.MediaPath = sys.WizardPrompt("Media folder path")
Options.TvMediaPath = sys.WizardPrompt("Media folder path")
checkInterval := sys.WizardPrompt("Channels check interval")
if checkInterval != "" {
Options.CheckInterval = int(Number(checkInterval))
Options.TvCheckInterval = int(Number(checkInterval))
}
checkBatch := sys.WizardPrompt("Channels check batch size")
if checkBatch != "" {
Options.TvCheckBatch = int(Number(checkBatch))
}

tibula.Assets = dbAssets
Expand Down

0 comments on commit dcfcf92

Please sign in to comment.