Last active
February 24, 2016 20:25
-
-
Save coderofsalvation/b1313d287c1f0a7e6cdf to your computer and use it in GitHub Desktop.
m3uchecker checks for broken iptv links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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