Auto update yt-dlp
This commit is contained in:
parent
1d75df37cf
commit
548e7effb7
19
main.go
19
main.go
@ -176,14 +176,29 @@ func main() {
|
||||
|
||||
fmt.Println("telegram connection up")
|
||||
|
||||
ytdlpVersionCheckStr, _ := ytdlpVersionCheckGetStr(ctx)
|
||||
ytdlpVersionCheckStr, updateNeeded, _ := ytdlpVersionCheckGetStr(ctx)
|
||||
if updateNeeded {
|
||||
goutubedl.Path, err = ytdlpDownloadLatest(ctx)
|
||||
if err != nil {
|
||||
panic(fmt.Sprint("error: ", err))
|
||||
}
|
||||
ytdlpVersionCheckStr, _, _ = ytdlpVersionCheckGetStr(ctx)
|
||||
}
|
||||
sendTextToAdmins(ctx, "🤖 Bot started, "+ytdlpVersionCheckStr)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(24 * time.Hour)
|
||||
if s, updateNeededOrError := ytdlpVersionCheckGetStr(ctx); updateNeededOrError {
|
||||
s, updateNeeded, gotError := ytdlpVersionCheckGetStr(ctx)
|
||||
if gotError {
|
||||
sendTextToAdmins(ctx, s)
|
||||
} else if updateNeeded {
|
||||
goutubedl.Path, err = ytdlpDownloadLatest(ctx)
|
||||
if err != nil {
|
||||
panic(fmt.Sprint("error: ", err))
|
||||
}
|
||||
ytdlpVersionCheckStr, _, _ = ytdlpVersionCheckGetStr(ctx)
|
||||
sendTextToAdmins(ctx, "🤖 Bot updated, "+ytdlpVersionCheckStr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@ -120,19 +120,19 @@ func ytdlpVersionCheck(ctx context.Context) (latestVersion, currentVersion strin
|
||||
return
|
||||
}
|
||||
|
||||
func ytdlpVersionCheckGetStr(ctx context.Context) (res string, updateNeededOrError bool) {
|
||||
func ytdlpVersionCheckGetStr(ctx context.Context) (res string, updateNeeded, gotError bool) {
|
||||
verCheckCtx, verCheckCtxCancel := context.WithTimeout(ctx, ytdlpVersionCheckTimeout)
|
||||
defer verCheckCtxCancel()
|
||||
|
||||
var latestVersion, currentVersion string
|
||||
var err error
|
||||
if latestVersion, currentVersion, err = ytdlpVersionCheck(verCheckCtx); err != nil {
|
||||
return errorStr + ": " + err.Error(), true
|
||||
return errorStr + ": " + err.Error(), false, true
|
||||
}
|
||||
|
||||
updateNeededOrError = currentVersion != latestVersion
|
||||
updateNeeded = currentVersion != latestVersion
|
||||
res = "yt-dlp version: " + currentVersion
|
||||
if updateNeededOrError {
|
||||
if updateNeeded {
|
||||
res = "📢 " + res + " 📢 Update needed! Latest version is " + latestVersion + " 📢"
|
||||
} else {
|
||||
res += " (up to date)"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user