Iptv Check
Iptv Check
/bin/bash
path=$(pwd)
sname=$0
wfile="$path/${WFILE:-oklist.m3u}"
#setup colors
blue='\e[0;36m'
green='\033[92m'
red='\e[1;31m'
yellow='\e[0;33m'
orange='\e[38;5;166m'
normal='\e[0m'
finish() {
#restore regular text color, then exit to shell prompt
echo -e "$normal"
exit "$1"
}
logo() {
echo -e "$green" "$VERSION"
echo -e "$yellow" "-------------------------------------"
echo -e "$blue" "http://gitlab.com/peterpt"
echo -e "$yellow" "-------------------------------------"
echo
echo -e "$green""Testing your Internet Download Speed"
echo -e "$yellow""This test can take up to 1 minute"
${speedtest} --no-upload |tee "$path/temp/speed" >/dev/null 2>&1
echo
echo -e "$green""Checking Results"
if [[ ! -f "$path/temp/speed" ]]; then
echo
echo -e "$red""Unable to find speedtest results"
finish 1
else
nets=$(grep "Download:" < "$path/temp/speed" |awk '{print $2}')
dec=$(echo "$nets" |grep ".")
if [[ -z "$dec" ]]; then
netspeed="$nets"
else
netspeed=${nets/\.*/}
fi
if [[ -z "$netspeed" ]]; then
echo -e "$red""No output results were generated by the test"
echo -e "$yellow""Make sure you are connected to the web"
finish 1
fi
bts="120"
if [[ "$netspeed" -le "10" ]]; then # 10Mbit/s
tout="4"
elif [[ "$netspeed" -le "30" ]]; then # 30 Mbit/s
tout="3"
elif [[ "$netspeed" -le "60" ]]; then # 60 Mbit/s
tout="2"
elif [[ "$netspeed" -ge "100" ]]; then # 100 Mbit/s
tout="1"
fi
tout=$((tout+LATENCY_SEC))
print_speed_result "$netspeed" "$tout"
fi
}
function writefile() {
# checks if tool already created previously an m3u file
#searchs for that specific url in original file and get line number
gturlline=$(grep -n "${chkf}"<"$path/temp/1" |tr ":" "\n" |sed -n 1p)
# This variable will get the line number before the previous url (this is to get
channel name)
defline=$((gturlline-1))
stdata=$(sed -n "${defline}p"< "$path/temp/1")
if [[ -f "$wfile" ]]; then
echo -en "${stdata}\n${chkf}\n\n" >>"$wfile"
else
echo -en "#EXTM3U\n\n${stdata}\n${chkf}\n\n" >"$wfile"
fi
}
# Function that will download for specific time the test stream
function teststream() {
wrn="0"
# Checks if tool already created a previous m3u file
if [[ -f "$wfile" ]]; then
exts="1"
else
exts="0"
fi
# dos2unix
sed -i 's/\r//' "$path/temp/1"
#Write all the http links only to a new file so they can be checked ahead
echo "$glnk" |tr " " "\n" >"$path/temp/2"
# Counts how many lines exist in the file with links to be checked
grep "^http" "$path/temp/2" >"$path/temp/3"
rm -rf "$path/temp/2" >/dev/null 2>&1
mv "$path/temp/3" "$path/temp/2" >/dev/null 2>&1
# removes any previous temp pid files and stream captures from previous run
rm -rf "$path/temp/stream" >/dev/null 2>&1
rm -rf "$path/temp/pid.tmp" >/dev/null 2>&1
echo
echo -e "$red""Press CTRL+C To Stop or Abort IPTV list check"
echo
# 4 seconds is the time that wget will download the stream befores gets
killed
sleep "$tout"
# In case stream file is less than value in bts (default is 100 bytes)
then it is not valid
if [[ "$stsz" -le "$bts" ]]; then
echo -e "$green""Link:$yellow $i$green of :$yellow$lnknmb$green is$red
OFF (${stype}, ${chkf})"
else
echo -e "$green""Link:$yellow $i$green of :$yellow$lnknmb$green
is$green ON"
#file have more than value in bts (default is 100 bytes) , then it is a
valid stream , goto write file fuction
writefile
fi
fi
;;
*)
;;
esac
rm -rf "$path/temp/stream" >/dev/null 2>&1
rm -rf "$path/temp/pid.tmp" >/dev/null 2>&1
warn
done
# Case user m3u file is remote (http) then run this function
function remotef() {
# will download the remote m3u file to temp folder and will check its size
wget "${file}" -O "$path/temp/1" >/dev/null 2>&1
flsz=$(wc -c "$path/temp/1" |awk '{print $1}')
if [[ "$flsz" -le "10" ]]; then
echo "filesize is $flsz"
echo -e "$yellow" "The remote link is down or the file size of it"
echo -e "$yellow" " is too small to be an m3u iptv list file"
echo
finish 0
fi
teststream
}
if [[ -z $1 ]] ;then
echo -e "$green" "$VERSION"
echo -e "$yellow" "-------------------------------------"
echo -e "$blue" "http://gitlab.com/peterpt"
echo -e "$yellow" "-------------------------------------"
echo
echo -e "$orange" "Example for remote list to check :"
echo -e "$green" "$0 http://someurl/somelist.m3u"
echo
echo -e "$orange" "Example for local list to check :"
echo -e "$green" "$0 /root/mylist.m3u"
echo
echo -e "$yellow" "-------------------------------------"
echo
finish 1
fi
# If a null file name is not found then executes the script again deflecting wget
errors to dev/null
if [[ ! -f $path/null ]]; then
echo "0" >"$path/null"
exec "$sname" "$1" 2>/dev/null
# finish 1
fi
# here it means that script already was loaded and restarted , so delete the null
file for the next start
rm -rf "$path/null" >/dev/null 2>&1
logo
file="$1"
#check if user input is a remote or local file by searching for http word in the
user input variable
echo "$file" |grep "http" >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
remotef
else
localf
fi
finish 0