From e98d923ce539f5b6d354d95ca70b7c54b5af537c Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Fri, 16 May 2025 23:09:27 +0800 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BA=D0=B0=D0=BD=D0=B0=D0=BB=D0=BE=D0=B2=20(#5?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - теперь проверяется только первый 1 Кб контента - скорректирована проверка mpd-контента --- .gitignore | 1 + app/checker/checker.go | 16 +++++++--------- app/playlist/playlist.go | 1 - 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 962f4f8..e995921 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ output/ *.m3u8 *.json *.ini +iptvc !/**/*.gitkeep diff --git a/app/checker/checker.go b/app/checker/checker.go index 60a5801..2f17774 100644 --- a/app/checker/checker.go +++ b/app/checker/checker.go @@ -217,7 +217,6 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist { http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} req, err := http.NewRequest("GET", tvChannel.URL, nil) - tvChannel.CheckedAt = time.Now().Unix() if err != nil { data := errorData{tvChannel: tvChannel, err: err} chError <- data @@ -226,7 +225,9 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist { //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 resp, err := httpClient.Do(req) + tvChannel.CheckedAt = time.Now().Unix() if err != nil { data := errorData{tvChannel: tvChannel, err: err} chError <- data @@ -236,7 +237,8 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist { tvChannel.Status = resp.StatusCode tvChannel.IsOnline = tvChannel.Status < http.StatusBadRequest tvChannel.ContentType = resp.Header.Get("Content-Type") - bodyBytes, _ := io.ReadAll(resp.Body) + chunk := io.LimitReader(resp.Body, 1024) // just for sure + bodyBytes, _ := io.ReadAll(chunk) bodyString := string(bodyBytes) _ = resp.Body.Close() contentType := http.DetectContentType(bodyBytes) @@ -246,7 +248,9 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist { isContentCorrect := isContentBinary || strings.Contains(bodyString, "#EXTM3U") || - strings.Contains(bodyString, "= http.StatusBadRequest || !isContentCorrect { tvChannel.Error = bodyString @@ -254,12 +258,6 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist { return } - if isContentBinary { - tvChannel.Content = "binary" - } else { - tvChannel.Content = bodyString - } - chOnline <- tvChannel return }(tvChannel) diff --git a/app/playlist/playlist.go b/app/playlist/playlist.go index c9d54ae..ea67516 100644 --- a/app/playlist/playlist.go +++ b/app/playlist/playlist.go @@ -32,7 +32,6 @@ type Channel struct { Status int `json:"status"` // Код статуса HTTP IsOnline bool `json:"isOnline"` // Признак доступности канала (при Status < 400) Error string `json:"error"` // Текст ошибки (при Status >= 400) - Content string `json:"content"` // Тело ответа (формат m3u, либо маскированные бинарные данные, либо пусто) ContentType string `json:"contentType"` // MIME-тип тела ответа Tags []string `json:"tags"` // Список тегов канала CheckedAt int64 `json:"checkedAt"` // Время проверки в формате UNIX timestamp