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

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

View File

@@ -166,7 +166,10 @@ func CheckPlaylists(lists []playlist.Playlist) (int, int) {
} }
func cachePlaylist(pls playlist.Playlist) { func cachePlaylist(pls playlist.Playlist) {
if app.Config.Cache.IsActive { if !app.Config.Cache.IsActive {
return
}
jsonBytes, err := json.Marshal(pls) jsonBytes, err := json.Marshal(pls)
if err != nil { if err != nil {
log.Printf("Error while saving playlist to cache: %s", err) log.Printf("Error while saving playlist to cache: %s", err)
@@ -179,7 +182,6 @@ func cachePlaylist(pls playlist.Playlist) {
} }
log.Println("Cached sucessfully") log.Println("Cached sucessfully")
}
} }
// CheckChannels проверяет каналы и возвращает их же с результатами проверки // CheckChannels проверяет каналы и возвращает их же с результатами проверки
@@ -223,9 +225,8 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
return return
} }
//TODO user-agent
req.Header.Set("User-Agent", "Mozilla/5.0 WINK/1.31.1 (AndroidTV/9) HlsWinkPlayer") 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) resp, err := httpClient.Do(req)
tvChannel.CheckedAt = time.Now().Unix() tvChannel.CheckedAt = time.Now().Unix()
if err != nil { if err != nil {
@@ -237,7 +238,7 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
tvChannel.Status = resp.StatusCode tvChannel.Status = resp.StatusCode
tvChannel.IsOnline = tvChannel.Status < http.StatusBadRequest tvChannel.IsOnline = tvChannel.Status < http.StatusBadRequest
tvChannel.ContentType = resp.Header.Get("Content-Type") 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) bodyBytes, _ := io.ReadAll(chunk)
bodyString := string(bodyBytes) bodyString := string(bodyBytes)
_ = resp.Body.Close() _ = resp.Body.Close()