Снижен размер чанка до 512Б при проверке канала

This commit is contained in:
2025-10-02 01:16:40 +08:00
parent edd18e92ed
commit fbc1870ce7

View File

@@ -166,20 +166,22 @@ func CheckPlaylists(lists []playlist.Playlist) (int, int) {
}
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")
if !app.Config.Cache.IsActive {
return
}
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 проверяет каналы и возвращает их же с результатами проверки
@@ -223,9 +225,8 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
return
}
//TODO user-agent
req.Header.Set("User-Agent", "Mozilla/5.0 WINK/1.31.1 (AndroidTV/9) HlsWinkPlayer")
req.Header.Add("Range", "bytes=0-1023") // 1 Kb, but sometimes servers ignore it
req.Header.Set("Range", "bytes=0-511") // 512 B, but sometimes servers ignore it
resp, err := httpClient.Do(req)
tvChannel.CheckedAt = time.Now().Unix()
if err != nil {
@@ -237,7 +238,7 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
tvChannel.Status = resp.StatusCode
tvChannel.IsOnline = tvChannel.Status < http.StatusBadRequest
tvChannel.ContentType = resp.Header.Get("Content-Type")
chunk := io.LimitReader(resp.Body, 1024) // just for sure
chunk := io.LimitReader(resp.Body, 512) // just for sure
bodyBytes, _ := io.ReadAll(chunk)
bodyString := string(bodyBytes)
_ = resp.Body.Close()