Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ youtube: # youtube configuration, optional
- {id: UCuIE7-5QzeAR6EdZXwDRwuQ, name: "Дилетант", type: "channel", lang: "ru-ru", "keep": 10}
- {id: PLZVQqcKxEn_6YaOniJmxATjODSVUbbMkd, name: "Точка", type: "playlist", lang: "ru-ru", filter: {include: "ТОЧКА", exclude: "STAR'цы Live"}}
ytdlp_update:
interval: 24h # update interval for yt-dlp. If not set, yt-dlp will not be updated
interval: 24h # update interval for yt-dlp. If not set, only force_on_startup can trigger an update
command: "pip3 install --break-system-packages -U yt-dlp" # update yt-dlp command
force_on_startup: true # force yt-dlp update on startup, before the first channel processing. Default: false

Expand Down
25 changes: 19 additions & 6 deletions app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,18 +129,15 @@ func main() {
}
ytSvc.YtDlpUpdCommand = conf.YouTube.YtDlpUpdate.Command
ytSvc.YtDlpUpdOnStart = conf.YouTube.YtDlpUpdate.ForceOnStartup
if conf.YouTube.YtDlpUpdate.Interval > 0 {
log.Printf("[INFO] yt-dlp updater enabled, interval %s", conf.YouTube.YtDlpUpdate.Interval)
ytSvc.YtDlpUpdDuration = conf.YouTube.YtDlpUpdate.Interval
} else {
log.Printf("[INFO] yt-dlp periodic updater is disabled")
}
ytSvc.YtDlpUpdDuration = conf.YouTube.YtDlpUpdate.Interval

go func() {
if conf.YouTube.DisableUpdates {
log.Printf("[INFO] youtube updates are disabled")
return
}
log.Printf("[INFO] yt-dlp updater: %s", ytdlpUpdateStatus(conf.YouTube.YtDlpUpdate.Command,
conf.YouTube.YtDlpUpdate.Interval, conf.YouTube.YtDlpUpdate.ForceOnStartup))
if err := ytSvc.Do(context.TODO()); err != nil {
log.Printf("[ERROR] youtube processor failed: %v", err)
}
Expand All @@ -163,6 +160,22 @@ func main() {
server.Run(context.Background(), opts.Port)
}

// ytdlpUpdateStatus describes the configured update triggers.
func ytdlpUpdateStatus(cmd string, interval time.Duration, onStartup bool) string {
if cmd == "" {
return "disabled, no command set"
}
switch {
case onStartup && interval > 0:
return fmt.Sprintf("on startup and every %s", interval)
case onStartup:
return "on startup only, no interval set"
case interval > 0:
return fmt.Sprintf("every %s", interval)
}
return "never, command set but force_on_startup is false and no interval given"
}

func makeBoltDB(dbFile string) (*bolt.DB, error) {
log.Printf("[INFO] bolt (persistent) store, %s", dbFile)
if dbFile == "" {
Expand Down
23 changes: 23 additions & 0 deletions app/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)
Expand All @@ -21,3 +22,25 @@ func TestMakeTwitter(t *testing.T) {
assert.Equal(t, "c", client.AccessToken)
assert.Equal(t, "d", client.AccessSecret)
}

func TestYtdlpUpdateStatus(t *testing.T) {
tbl := []struct {
name string
cmd string
interval time.Duration
onStartup bool
want string
}{
{"no command", "", time.Hour, true, "disabled, no command set"},
{"startup and interval", "pip -U yt-dlp", 24 * time.Hour, true, "on startup and every 24h0m0s"},
{"startup only", "pip -U yt-dlp", 0, true, "on startup only, no interval set"},
{"interval only", "pip -U yt-dlp", 24 * time.Hour, false, "every 24h0m0s"},
{"command never runs", "pip -U yt-dlp", 0, false, "never, command set but force_on_startup is false and no interval given"},
}

for _, tt := range tbl {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.want, ytdlpUpdateStatus(tt.cmd, tt.interval, tt.onStartup))
})
}
}
Loading