From 2412b570be0edaff236e18d862ace1b7fa25440d Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Sat, 10 May 2025 11:54:55 +0800 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BA=D1=8D=D1=88=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=84=D1=84=D0=BB=D0=B0=D0=B9?= =?UTF-8?q?=D0=BD=20=D0=BF=D0=BB=D0=B5=D0=B9=D0=BB=D0=B8=D1=81=D1=82=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/checker/checker.go | 35 +++++++++++++++++++---------------- app/playlist/playlist.go | 2 ++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/checker/checker.go b/app/checker/checker.go index c216056..9ef8e42 100644 --- a/app/checker/checker.go +++ b/app/checker/checker.go @@ -146,6 +146,7 @@ func CheckPlaylists(lists []playlist.Playlist) (int, int) { if err != nil { log.Printf("Cannot read playlist [%s]: %s\n", pls.Url, err) offlineCount++ + cachePlaylist(pls) continue } @@ -156,28 +157,30 @@ func CheckPlaylists(lists []playlist.Playlist) (int, int) { log.Printf("Parsed, checking channels (%d)...\n", len(pls.Channels)) pls = CheckChannels(pls) - lists[idx] = pls - - if app.Config.Cache.IsActive { - jsonBytes, err := json.Marshal(pls) - if err != nil { - log.Printf("Error while saving playlist to cache: %s", err) - } - - ttl := time.Duration(app.Config.Cache.Ttl) * time.Second - written := app.Cache.Set(ctx, pls.Code, string(jsonBytes), ttl) - if written.Err() != nil { - log.Printf("Error while saving playlist to cache: %s", err) - } - - log.Println("Cached sucessfully") - } + cachePlaylist(pls) } return onlineCount, offlineCount } +func cachePlaylist(pls playlist.Playlist) { + if app.Config.Cache.IsActive { + jsonBytes, err := json.Marshal(pls) + if err != nil { + log.Printf("Error while saving playlist to cache: %s", err) + } + + ttl := time.Duration(app.Config.Cache.Ttl) * time.Second + written := app.Cache.Set(ctx, pls.Code, string(jsonBytes), ttl) + if written.Err() != nil { + log.Printf("Error while saving playlist to cache: %s", err) + } + + log.Println("Cached sucessfully") + } +} + // CheckChannels проверяет каналы и возвращает их же с результатами проверки func CheckChannels(pls playlist.Playlist) playlist.Playlist { type errorData struct { diff --git a/app/playlist/playlist.go b/app/playlist/playlist.go index d9e3eef..10662c5 100644 --- a/app/playlist/playlist.go +++ b/app/playlist/playlist.go @@ -123,6 +123,7 @@ func parseName(line string) string { func (pls *Playlist) Download() error { content, err := utils.Fetch(pls.Url) if err != nil { + pls.Content = err.Error() return err } @@ -134,6 +135,7 @@ func (pls *Playlist) Download() error { func (pls *Playlist) ReadFromFs() error { content, err := os.ReadFile(pls.Url) if err != nil { + pls.Content = err.Error() return err }