Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active February 24, 2016 20:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderofsalvation/b1313d287c1f0a7e6cdf to your computer and use it in GitHub Desktop.
Save coderofsalvation/b1313d287c1f0a7e6cdf to your computer and use it in GitHub Desktop.
m3uchecker checks for broken iptv links
#
# generated by powscript (https://github.com/coderofsalvation/powscript)
#
empty ()
{
[[ "${#1}" == 0 ]] && return 0 || return 1
}
map ()
{
local arr="$1";
shift;
local func="$1";
shift;
eval "for i in \"\${!$arr[@]}\"; do $func \"\$@\" \"\$i\" \"\${$arr[\$i]}\"; done"
}
pipemap ()
{
func="$1";
shift;
cat - | while read -r line; do
$func "$@" "$line";
done
}
#
# application code
#
#!/usr/bin/env powscript
shift
lastinfo=""
if empty "$1"; then
printf "%s\n\n%s" "Usage: m3ucheck <file.m3u>" "filters out broken links"
exit
fi
process_line(){
if [[ "$1" =~ ^(#) ]]; then
lastinfo="$1"
else
testlink "$1"
fi
}
testlink(){
if curl --connect-timeout 2 --silent --head --fail "$1" &>/dev/null; then
echo "$lastinfo"
echo "$1"
fi
}
cat "$1" | pipemap process_line
#!/usr/bin/env powscript
shift
lastinfo=""
if empty $1
printf "%s\n\n%s" "Usage: m3ucheck <file.m3u>" "filters out broken links" && exit
process_line()
if $1 match ^(#)
lastinfo=$1
else
testlink $1
testlink()
if curl --connect-timeout 2 --silent --head --fail $1 &>/dev/null
echo $lastinfo
echo $1
cat $1 | pipemap process_line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment