Scans a specified IRC log directory for links to images, and dumps them all to standard output. It can optionally output in HTML format.
#!/bin/bash
# YoinkLog v1.20: Scans IRC logs for links to images. -Inky 2006
src="$2"; head="<html>\n<head>\n\t<title>Yoinklog images</title>\n</head>\n<body>\n\n"
foot="\n\n</body>\n</html>\n"; awkexp='/^h/ {print $0}'
if [ "$1" = "--html" ]; then
head="$head<pre>"; foot="</pre>$foot"
elif [ "$1" = "--list" ]; then
head="$head<ol>\n"; foot="</ol>$foot"
awkexp='/^h/ {print "\t<li><a href=\"" $0 "\">" $0 "</a></li>"}'
elif [ "$1" = "--img" ]; then
head="$head<center>\n"; foot="</center>$foot"
awkexp='/^h/ {print "<img src=\"" $0 "\" border=\"0\" />"}'
else
head=""; foot=""; src="$1"
fi
[ -z "$src" ] || [ "$1" = "--help" ] && cat <<EOF && exit
Usage: `basename $0` [OPTIONS] DIRECTORY/FILE
Prints all image URLs in DIRECTORY or FILE to standard output.
--html Basic HTML output
--list HTML list output
--img HTML images output
Report bugs to liamcooke at gmail dot com.
EOF
[ -e "$src" ] && echo -en "$head" && grep -hiroE \
'(\A|\b)https?://[A-Za-z0-9\.\:\-]+/[^ ]+\.(jpe?g|gif|png)(\b|\Z)' \
"$src" | sort | uniq | awk "$awkexp" && echo -en "$foot" && exit
echo "`basename $0`: $src does not exist" && exit
# Change log
# v1.20 [30/12/06]: Added 3 forms of HTML output & improved url detection
# v1.10 [24/12/06]: Can now interpret lines with multiple links correctly
# v1.01 [??/??/06]: Removed duplicates
# v1.00 [22/08/06]: Original