2022-05-31 15:00:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#################################################
|
|
|
|
#
|
|
|
|
# IPTV Playlist check tool
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# ./check-pls.sh local/pls.m3u
|
|
|
|
# ./check-pls.sh https://example.com/pls.m3u
|
|
|
|
#
|
2022-06-08 00:57:53 +00:00
|
|
|
# 1st argument is playlist file name or URL.
|
|
|
|
# If it is an URL it will be saved in /tmp and
|
|
|
|
# checked as local file.
|
2022-05-31 15:00:08 +00:00
|
|
|
#
|
2022-06-08 00:57:53 +00:00
|
|
|
# Both *.m3u and *.m3u8 are supported.
|
2022-05-31 15:00:08 +00:00
|
|
|
#
|
2022-06-09 03:51:25 +00:00
|
|
|
# Anthony Axenov (c) 2022
|
|
|
|
# The MIT License:
|
|
|
|
# https://github.com/anthonyaxenov/iptv/blob/master/LICENSE
|
|
|
|
#
|
2022-05-31 15:00:08 +00:00
|
|
|
#################################################
|
|
|
|
|
|
|
|
awk '
|
|
|
|
BEGIN {
|
|
|
|
total_count=0
|
|
|
|
success_count=0
|
|
|
|
fail_count=0
|
2022-06-05 07:17:04 +00:00
|
|
|
print "\033[20m\033[97mPlaylist:\033[0m " ARGV[1]
|
2022-05-31 15:00:08 +00:00
|
|
|
if (ARGV[1] ~ /^http(s)?:\/\/.*/) {
|
|
|
|
parts_count = split(ARGV[1], parts, "/")
|
|
|
|
file_name = parts[parts_count]
|
|
|
|
code = system("wget " ARGV[1] " -qO /tmp/" file_name " > /dev/null")
|
|
|
|
if (code == 0) {
|
|
|
|
print "Saved in /tmp/" file_name
|
|
|
|
} else {
|
|
|
|
print "ERROR: cannot download playlist: " ARGV[1]
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
ARGV[1] = "/tmp/" file_name
|
|
|
|
}
|
|
|
|
print ""
|
2022-10-22 08:53:31 +00:00
|
|
|
print "\033[20m\033[97mNote 1:\033[0m operation may take some time, press CTRL+C to stop."
|
|
|
|
print "\033[20m\033[97mNote 2:\033[0m results may be inaccurate, you should use proper IPTV software to re-check."
|
|
|
|
print "\033[20m\033[97mNote 3:\033[0m error codes listed here - https://everything.curl.dev/usingcurl/returns"
|
2022-05-31 15:00:08 +00:00
|
|
|
print "--------------------"
|
|
|
|
}
|
|
|
|
{
|
|
|
|
sub("\r$", "", $0) # crlf -> lf
|
2022-06-01 05:09:40 +00:00
|
|
|
if ($0 ~ /^#EXTINF:.+,/) {
|
2022-05-31 15:00:08 +00:00
|
|
|
total_count++
|
|
|
|
channel_name = substr($0, index($0, ",") + 1, length($0))
|
2022-10-23 12:43:56 +00:00
|
|
|
print "\n[" total_count "] " channel_name
|
2022-05-31 15:00:08 +00:00
|
|
|
}
|
|
|
|
if ($0 ~ /^http(s)?:\/\/.*/) {
|
2022-06-05 07:17:04 +00:00
|
|
|
url = sprintf("%c%s%c", 34, $0, 34) # 34 is "
|
|
|
|
cmd = "curl -fs --max-time 5 -w \"%{http_code}\" --max-filesize 5000 -o /dev/null " url
|
|
|
|
cmd | getline http_code
|
|
|
|
code = close(cmd)
|
|
|
|
if (http_code == "000") {
|
|
|
|
http_code = "-"
|
|
|
|
}
|
2022-05-31 15:00:08 +00:00
|
|
|
if (code == 0 || code == 63) {
|
2022-10-23 12:43:56 +00:00
|
|
|
print "\033[32mOK:\033[0m " url
|
2022-05-31 15:00:08 +00:00
|
|
|
success_count++
|
|
|
|
} else {
|
2022-10-23 12:43:56 +00:00
|
|
|
print "\033[91mERROR\033[0m " code " (" http_code "): " url
|
2022-05-31 15:00:08 +00:00
|
|
|
fail_count++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
print "--------------------"
|
2022-06-05 07:17:04 +00:00
|
|
|
print "\033[20m\033[97mPlaylist:\033[0m " ARGV[1]
|
|
|
|
print "- Success:\t\033[32m" success_count "\033[0m/" total_count
|
|
|
|
print "- Failed: \t\033[91m" fail_count "\033[0m/" total_count
|
2022-05-31 15:00:08 +00:00
|
|
|
}
|
|
|
|
' $1
|