Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
ac062aa1ba
|
|||
|
bcd45e34bf
|
|||
|
b3ee981bd1
|
|||
|
182b9a92ce
|
|||
|
fbc1870ce7
|
|||
|
edd18e92ed
|
|||
|
dc61d47b66
|
|||
|
10c3b8f5c1
|
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
Консольная программа для проверки IPTV-плейлистов в формате m3u или m3u8.
|
Консольная программа для проверки IPTV-плейлистов в формате m3u или m3u8.
|
||||||
|
|
||||||
> **Веб-сайт:** [iptv.axenov.dev](https://iptv.axenov.dev)
|
> **Веб-сайт:** [m3u.su](https://m3u.su)
|
||||||
> **Зеркало:** [m3u.su](https://m3u.su)
|
|
||||||
> Исходный код: [git.axenov.dev/IPTV/iptvc](https://git.axenov.dev/IPTV/iptvc)
|
> Исходный код: [git.axenov.dev/IPTV/iptvc](https://git.axenov.dev/IPTV/iptvc)
|
||||||
> Telegram-канал: [@iptv_aggregator](https://t.me/iptv_aggregator)
|
> Telegram-канал: [@iptv_aggregator](https://t.me/iptv_aggregator)
|
||||||
> Обсуждение: [@iptv_aggregator_chat](https://t.me/iptv_aggregator_chat)
|
> Обсуждение: [@iptv_aggregator_chat](https://t.me/iptv_aggregator_chat)
|
||||||
|
|||||||
@@ -10,10 +10,11 @@ import (
|
|||||||
"axenov/iptv-checker/app/cache"
|
"axenov/iptv-checker/app/cache"
|
||||||
"axenov/iptv-checker/app/config"
|
"axenov/iptv-checker/app/config"
|
||||||
"axenov/iptv-checker/app/logger"
|
"axenov/iptv-checker/app/logger"
|
||||||
|
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
const VERSION = "1.0.4"
|
const VERSION = "1.0.5"
|
||||||
|
|
||||||
// Arguments описывает аргументы командной строки
|
// Arguments описывает аргументы командной строки
|
||||||
type Arguments struct {
|
type Arguments struct {
|
||||||
|
|||||||
14
app/cache/cache.go
vendored
14
app/cache/cache.go
vendored
@@ -10,28 +10,30 @@ import (
|
|||||||
"axenov/iptv-checker/app/config"
|
"axenov/iptv-checker/app/config"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/redis/go-redis/v9"
|
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/redis/go-redis/v9"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Init(cfg *config.CacheConfig) *redis.Client {
|
func Init(cfg *config.CacheConfig) *redis.Client {
|
||||||
redis := redis.NewClient(&redis.Options{
|
redisUrl := fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port)))
|
||||||
Addr: fmt.Sprintf("%s:%s", cfg.Host, strconv.Itoa(int(cfg.Port))),
|
redisClient := redis.NewClient(&redis.Options{
|
||||||
|
Addr: redisUrl,
|
||||||
DB: int(cfg.Db),
|
DB: int(cfg.Db),
|
||||||
PoolSize: 1000,
|
PoolSize: 1000,
|
||||||
ReadTimeout: -1,
|
ReadTimeout: -1,
|
||||||
WriteTimeout: -1,
|
WriteTimeout: -1,
|
||||||
})
|
})
|
||||||
client := redis.Conn()
|
client := redisClient.Conn()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err := client.Ping(ctx).Err()
|
err := client.Ping(ctx).Err()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Println("Connected to cache DB")
|
log.Println("Connected to cache DB:", redisUrl)
|
||||||
cfg.IsActive = true
|
cfg.IsActive = true
|
||||||
} else {
|
} else {
|
||||||
log.Println("Error while connecting to cache DB, program may work not as expected:", err)
|
log.Println("Error while connecting to cache DB, program may work not as expected:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return redis
|
return redisClient
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -166,20 +165,22 @@ 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 {
|
||||||
jsonBytes, err := json.Marshal(pls)
|
return
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 проверяет каналы и возвращает их же с результатами проверки
|
// CheckChannels проверяет каналы и возвращает их же с результатами проверки
|
||||||
@@ -223,9 +224,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 +237,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()
|
||||||
@@ -248,11 +248,12 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
|
|||||||
|
|
||||||
isContentCorrect := isContentBinary ||
|
isContentCorrect := isContentBinary ||
|
||||||
strings.Contains(bodyString, "#EXTM3U") ||
|
strings.Contains(bodyString, "#EXTM3U") ||
|
||||||
|
strings.Contains(bodyString, "#EXT-X-") ||
|
||||||
strings.Contains(bodyString, "<MPD ") ||
|
strings.Contains(bodyString, "<MPD ") ||
|
||||||
strings.Contains(bodyString, "<SegmentTemplate ") ||
|
strings.Contains(bodyString, "<SegmentTemplate ") ||
|
||||||
strings.Contains(bodyString, "<AdaptationSet ")
|
strings.Contains(bodyString, "<AdaptationSet ")
|
||||||
|
|
||||||
if tvChannel.Status >= http.StatusBadRequest || !isContentCorrect {
|
if tvChannel.Status >= http.StatusBadRequest && !isContentCorrect {
|
||||||
tvChannel.Error = bodyString
|
tvChannel.Error = bodyString
|
||||||
chOffline <- tvChannel
|
chOffline <- tvChannel
|
||||||
return
|
return
|
||||||
@@ -321,27 +322,22 @@ func CheckChannels(pls playlist.Playlist) playlist.Playlist {
|
|||||||
|
|
||||||
// calcParameters вычисляет оптимальное количество горутин и таймаут запроса
|
// calcParameters вычисляет оптимальное количество горутин и таймаут запроса
|
||||||
func calcParameters(count int) (time.Duration, int) {
|
func calcParameters(count int) (time.Duration, int) {
|
||||||
percentage := float32(runtime.NumCPU()) / 10
|
routines := count
|
||||||
for percentage >= 1 {
|
if routines > 3000 {
|
||||||
percentage *= 0.5
|
routines = 3000
|
||||||
}
|
|
||||||
|
|
||||||
routines := int(float32(count) * percentage)
|
|
||||||
if routines > 1500 {
|
|
||||||
routines = 1500
|
|
||||||
}
|
}
|
||||||
if routines < 1 {
|
if routines < 1 {
|
||||||
routines = 1
|
routines = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
var digits int
|
var digits = 1
|
||||||
x := count
|
x := count
|
||||||
for x >= 10 {
|
for x >= 10 {
|
||||||
digits++
|
digits++
|
||||||
x /= 10
|
x /= 10
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout := int(math.Ceil(math.Pow(10, float64(digits)) / float64(count) * 15))
|
timeout := 10 - int(math.Ceil(float64(digits)*1.5))
|
||||||
if timeout > 10 {
|
if timeout > 10 {
|
||||||
timeout = 10
|
timeout = 10
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,9 @@ func Fetch(url string) ([]byte, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req.Header.Set(
|
req.Header.Set("User-Agent", "Mozilla/5.0 WINK/1.31.1 (AndroidTV/9) HlsWinkPlayer")
|
||||||
"User-Agent",
|
|
||||||
"Mozilla/5.0 WINK/1.31.1 (AndroidTV/9) HlsWinkPlayer",
|
|
||||||
)
|
|
||||||
|
|
||||||
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
|
||||||
httpClient := http.Client{Timeout: 5 * time.Second}
|
httpClient := http.Client{Timeout: 10 * time.Second}
|
||||||
resp, err := httpClient.Do(req)
|
resp, err := httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -11,9 +11,10 @@ import (
|
|||||||
"axenov/iptv-checker/app/checker"
|
"axenov/iptv-checker/app/checker"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// checkCmd represents the file command
|
// checkCmd represents the file command
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ import (
|
|||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "iptvc",
|
Use: "iptvc",
|
||||||
Short: "Simple utility to check iptv playlists. Part of iptv.axenov.dev project.",
|
Short: "Simple utility to check iptv playlists. Part of m3u.su project.",
|
||||||
Long: `Simple utility to check iptv playlists. Part of iptv.axenov.dev project.
|
Long: `Simple utility to check iptv playlists. Part of m3u.su project.
|
||||||
Copyright (c) 2025, Антон Аксенов, MIT license.`,
|
Copyright (c) 2025, Антон Аксенов, MIT license.`,
|
||||||
// Uncomment the following line if your bare application
|
// Uncomment the following line if your bare application
|
||||||
// has an action associated with it:
|
// has an action associated with it:
|
||||||
|
|||||||
Reference in New Issue
Block a user