Оптимизация проверки каналов (#5)
- теперь проверяется только первый 1 Кб контента - скорректирована проверка mpd-контента
This commit is contained in:
@@ -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, "<SegmentTemplate")
|
||||
strings.Contains(bodyString, "<MPD ") ||
|
||||
strings.Contains(bodyString, "<SegmentTemplate ") ||
|
||||
strings.Contains(bodyString, "<AdaptationSet ")
|
||||
|
||||
if tvChannel.Status >= 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)
|
||||
|
||||
Reference in New Issue
Block a user