#!/bin/bash
PFAD=$(dirname "$(readlink -f "$0")")
function beenden {
rm -f $COOKIEFILE
rm -f landingpage.txt
rm -f searchresults.txt
umount /scripts/housofusenet/mount
exit $1
}
USERAGENT='User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0'
COOKIEFILE="/tmp/hou-cookie.txt"
curl -s -H "${USERAGENT}" 'https://house-of-usenet.com/member.php?action=login' --cookie-jar ${COOKIEFILE} -o ${PFAD}/landingpage.txt
POSTKEY=$(grep -m 1 '//g' | sed 's/-//g' |awk '{$1=$1};1')
if [ "$FILMKURZ" == "" ] ; then
echo "Name zu kurz, leerer String: ${FILM}"
continue
fi
FILMHTML=$(echo $FILMKURZ | sed -f ${PFAD}/url_escape.sed)
SEARCHURL=${SEARCHPREFIX}${FILMHTML}${SEARCHPOSTFIX}
echo "Aktueller Film: $FILM"
echo $SEARCHURL
curl -s -L -H "${USERAGENT}" -b ${COOKIEFILE} "${SEARCHURL}" -o ${PFAD}/searchresults.txt
grep "keine Ergebnisse gefunden" ${PFAD}/searchresults.txt > /dev/null
if [ $? -eq 0 ] ; then
echo "Nichts gefunden"
continue
fi
grep "kürzer als erlaubt" ${PFAD}/searchresults.txt > /dev/null
if [ $? -eq 0 ] ; then
echo "Suchbegriff zu kurz"
continue
fi
grep "showthread.php" ${PFAD}/searchresults.txt | grep "subject_old" | sed 's@showthread.php@https://house-of-usenet.com/showthread.php@g' | sed ':a;N;$!ba;s/\n/
\r\n/g' > "${PFAD}/results/${FILM}.html"
echo "
##############################" >> "${PFAD}/results/${FILM}.html"
echo "
Filmtitel auf Festplatte: ${FILM}" >> "${PFAD}/results/${FILM}.html"
#echo "##############################"
rm -f ${PFAD}/searchresults.txt
#sleep 60
done
beenden 0