3 Commits

Author SHA1 Message Date
c2ff027223 Версия 1.0.1
All checks were successful
release / release (push) Successful in 1m42s
2025-05-10 11:56:44 +08:00
13723a2dc5 Инициализация attributes плейлиста (#3) 2025-05-10 11:55:26 +08:00
2412b570be Исправлено кэширование оффлайн плейлистов 2025-05-10 11:54:55 +08:00
3 changed files with 23 additions and 17 deletions

View File

@@ -13,7 +13,7 @@ import (
"github.com/redis/go-redis/v9"
)
const VERSION = "1.0.0"
const VERSION = "1.0.1"
// Arguments описывает аргументы командной строки
type Arguments struct {

View File

@@ -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 {

View File

@@ -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
}
@@ -144,6 +146,7 @@ func (pls *Playlist) ReadFromFs() error {
// Parse разбирает плейлист
func (pls *Playlist) Parse() Playlist {
isChannel := false
pls.Attributes = make(map[string]string)
pls.Channels = make(map[string]Channel)
pls.Groups = make(map[string]Group)