#!/bin/sh
# first sh box parser for titannit mfg obi

SRC=$1
INPUT=$2
PAGE=$3
NEXT=$4
PAGE2=$5
PAGE3=$6

PARSER=`echo $SRC | tr '/' '\n' | tail -n1 | sed 's/.sh//'`

#KinoX.to Alternativ Adressen: http://kinoS.TO - http://kinox.TV - http://kinox.ME - http://kinox.SI - http://kinox.IO
#Mirrors: http://kinox.SX - http://kinox.AM - http://kinox.NU - http://kinox.SG - http://kinox.GRATIS - http://kinox.MOBI
#http://kinox.SH - http://kinox.LOL - http://kinox.WTF - http://kinox.FUN - http://kinox.FYI - http://kinox.CLOUD http://kinox.AI - http://kinox.CLICK - http://kinox.TUBE - http://kinox.CLUB - http://kinox.DIGITAL http://kinox.DIRECT - http://kinox.PUB - http://kinox.EXPRESS - http://kinox.PARTY - http://kinox.LC 
#http://kinox.MS - http://kinox.MU - http://kinox.GS - http://kinox.BZ - http://kinox.GY - http://kinox.AF 
#kinoz.to

PARSER=`echo $SRC | tr '/' '\n' | tail -n1 | sed 's/.sh//'`
NAME=KinoX

getlangtext()
{
# comment block1 start
<<"COMMENT"
'1': 'DE', 
'2': 'EN', 
'4': 'ZA', 
'5': 'ES', 
'6': 'FR', 
'7': 'TR',
'8': 'JA', 
'9': 'AR', 
'11': 'IT', 
'12': 'HR', 
'13': 'SR',
            
'14': 'BS', 
'15': 'DE / EN', 
'16': 'NL', 
'17': 'KO',
            
'24': 'EL', 
'25': 'RU', 
'26': 'HI',

COMMENT
# comment block1 end
	if [ $1 == 0 ];then
		TEXT=DEFAULT
	elif [ $1 == 1 ];then
		TEXT=DE
	elif [ $1 == 2 ];then
		TEXT=EN
	elif [ $1 == 3 ];then
        TEXT="EN sub"
	elif [ $1 == 4 ];then
        TEXT=ZA
	elif [ $1 == 5 ];then
        TEXT=ES
	elif [ $1 == 6 ];then
        TEXT=FR
	elif [ $1 == 7 ];then
        TEXT=TR
	elif [ $1 == 8 ];then
        TEXT=JA
	elif [ $1 == 9 ];then
        TEXT=AR
	elif [ $1 == 11 ];then
        TEXT=IT
	elif [ $1 == 12 ];then
        TEXT=HR
	elif [ $1 == 13 ];then
        TEXT=SR
	elif [ $1 == 14 ];then
        TEXT=BS
	elif [ $1 == 15 ];then
        TEXT="DE/EN"
	elif [ $1 == 16 ];then
        TEXT=NL
	elif [ $1 == 17 ];then
        TEXT=KO
	elif [ $1 == 24 ];then
        TEXT=EL
	elif [ $1 == 25 ];then
        TEXT=RU
	elif [ $1 == 26 ];then
        TEXT=HI
	else
        TEXT="??"
	fi
    echo " ("$(echo $TEXT | tr 'A-Z' 'a-z' | tr -d '\n' )")"
#    echo $TEXT
}

case $2 in
	init)	;;
	*) 	. /tmp/localhoster/hoster.sh
	   	mkdir $TMP > /dev/null 2>&1

        DEBUGLEVEL=$(cat /mnt/config/titan.cfg | sed -nr 's/debuglevel=([^=]+)/\1/p')

		DISPLAYED=$(cat /mnt/config/titan.cfg | sed -nr 's/tithek_kinox_displayed=([^=]+)/\1/p')
		if [ -z "$DISPLAYED" ] || [ "$DISPLAYED" == 0 ]; then DISPLAYED=100;fi
        TMPDISPLAYED="d$DISPLAYED"

		SORTID=$(cat /mnt/config/titan.cfg | sed -nr 's/tithek_kinox_sort=([^=]+)/\1/p')
		if [ -z "$SORTID" ]; then SORTID=0;fi
		if [ "$SORTID" == 0 ];then
			#default
			SORTCOL=''
			SORTDIR=''
			SORTURL=''
		elif [ "$SORTID" == 1 ];then
			#a-z
			SORTCOL=2
			SORTDIR=asc
			SORTURL='?sort=title_asc'
		elif [ "$SORTID" == 2 ];then
			#z-a
			SORTCOL=2
			SORTDIR=desc
			SORTURL='?sort=title_desc'
		elif [ "$SORTID" == 3 ];then
			#neueste
			SORTCOL=100
			SORTDIR=desc
			SORTURL='?sort=year_desc'
		elif [ "$SORTID" == 4 ];then
			#älteste
			SORTCOL=100
			SORTDIR=asc
			SORTURL='?sort=year_asc'
		elif [ "$SORTID" == 5 ];then
			#hohe wertung
			SORTCOL=6
			SORTDIR=desc
			SORTURL='?sort=imdbrating_desc'
		elif [ "$SORTID" == 6 ];then
			#niedrige wertung
			SORTCOL=6
			SORTDIR=asc
			SORTURL='?sort=imdbrating_asc'
		elif [ "$SORTID" == 7 ];then
			#trending
			SORTCOL=101
			SORTDIR=desc
			SORTURL='?sort=popular'
		elif [ "$SORTID" == 8 ];then
			#letzte
			SORTCOL=102
			SORTDIR=desc
			SORTURL='?sort=latest'
		elif [ "$SORTID" == 9 ];then
			#updates
			SORTCOL=103
			SORTDIR=desc
			SORTURL='?sort=updated'
#		else
#			#default
#			SORTCOL=''
#			SORTDIR=''
#			SORTURL=''
		fi

		LANGID=$(cat /mnt/config/titan.cfg | sed -nr 's/tithek_kinox_lang=([^=]+)/\1/p')
		if [ -z "$LANGID" ]; then LANGID=0;fi
		if [ $(echo "$PAGE" | grep 'Search.html?q=' | wc -l) == 1 ] && [ -z "$SORTURL" ]; then
			LANGURL="&language=$LANGID"
		elif [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
			LANGURL="?language=$LANGID"
		else
			LANGURL="&language=$LANGID"
			TMPSORT="sc$SORTCOL.sd$SORTDIR"
		fi
        TMPLANG=$(getlangtext $LANGID)
		if [ "$TMPLANG" == "??" ]; then TMPLANG="langid$LANGID";fi
#echo LANGID $LANGID
#echo TMPLANG $TMPLANG
#exit

		FILENAME="$PARSER $INPUT $PAGE $NEXT $PAGE2 $PAGE3 $TMPDISPLAYED $TMPLANG $TMPSORT"
	   	FILENAME=$(echo $FILENAME | tr '&' '.' | tr '/' '.' | tr '?' '.' | tr '=' '.' | sed -e 's/\&\+/./g' -e 's#\/\+#.#g' -e 's/\?\+/./g' -e 's/;\+/./g' -e 's/=\+/./g' -e 's/ \+/./g' -e 's/\.\+/./g')
		if [ -z "$FILENAME" ]; then FILENAME=none;fi
           	PICNAME="$FILENAME"
		URL=`cat /mnt/config/titan.cfg | grep tithek_kinox_url | grep -v "#" | cut -d "=" -f2`
		if [ -z "$URL" ];then URL=https://kinos.to; fi
		if [ `cat /mnt/config/titan.cfg | grep tithek_kinox_localhoster=1 | wc -l` -eq 1 ];then
			ACTIVEBIN="$curlbin" 
		elif [ `cat /mnt/config/titan.cfg | grep tithek_kinox_localhoster=2 | wc -l` -eq 1 ];then
			ACTIVEBIN="$BIN /tmp/localhoster/cloudflare.py"
		else
			ACTIVEBIN="$curlbin" 
		fi

		if [ -e /etc/.oebuild ];then
			unset PYTHONHOME
			BIN=python3
		fi
	    ;;
esac

if [ `echo $SRC | grep ^"/mnt/parser" | wc -l` -gt 0 ];then
	TYPE="$SRC - Shell script"
elif [ `echo $SRC | grep ^"/var/swap" | wc -l` -gt 0 ];then
	TYPE="Swap - Shell script"
elif [ `echo $SRC | grep ^"/mnt/swapextensions" | wc -l` -gt 0 ];then
	TYPE="Mnt - Shell script"
else
	TYPE="Flash - Shell script"
fi

init()
{
	rm -rf $TMP > /dev/null 2>&1
	echo "$NAME ($TYPE)#$SRC $SRC mainmenu#http://openaaf.dyndns.tv/mediathek/menu/$PARSER.jpg#$PARSER.jpg#TiThek#0"
}

mainmenu()
{
	echo "Kino#$SRC $SRC kino 'Kino-filme.html'#http://openaaf.dyndns.tv/mediathek/menu/Cine-Films.jpg#Cine-Films.jpg#$NAME#0" >$TMP/$FILENAME.list

#	echo "Movie (Latest)#$SRC $SRC latest 'Latest-Movies.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Movies.jpg#Latest-Movies.jpg#$NAME#0" >>$TMP/$FILENAME.list
#	echo "Movie (Popular)#$SRC $SRC latest 'Popular-Movies.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Movies.jpg#Popular-Movies.jpg#$NAME#0" >>$TMP/$FILENAME.list
#	echo "Movie (A-Z)#$SRC $SRC sorted movie#http://openaaf.dyndns.tv/mediathek/menu/a-z.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Movie (Latest)#$SRC $SRC kino 'Latest-Filme.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Movies.jpg#Latest-Movies.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Movie (Popular)#$SRC $SRC kino 'Popular-Filme.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Movies.jpg#Popular-Movies.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Movie (Updates)#$SRC $SRC kino 'Updates-Filme.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Movies.jpg#Updates-Movies.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Movie (A-Z)#$SRC $SRC sorted movie#http://openaaf.dyndns.tv/mediathek/menu/a-z.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list

##	echo "Tv (Latest)#$SRC $SRC latest 'Latest-TVSeries.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Series.jpg#Latest-Series.jpg#$NAME#0" >>$TMP/$FILENAME.list
##	echo "Tv (Popular)#$SRC $SRC latest 'Popular-TVSeries.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Series.jpg#Popular-Series.jpg#$NAME#0" >>$TMP/$FILENAME.list
#	echo "Tv (Latest)#$SRC $SRC latest 'Latest-TVSerien.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Series.jpg#Latest-Series.jpg#$NAME#0" >>$TMP/$FILENAME.list
#	echo "Tv (Popular)#$SRC $SRC latest 'Popular-TVSerien.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Series.jpg#Popular-Series.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Tv (Latest)#$SRC $SRC kino 'Latest-TVSerien.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Series.jpg#Latest-Series.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Tv (Popular)#$SRC $SRC kino 'Popular-TVSerien.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Series.jpg#Popular-Series.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Tv (A-Z)#$SRC $SRC sorted series#http://openaaf.dyndns.tv/mediathek/menu/a-z.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list

#	echo "Doku (Latest)#$SRC $SRC latest 'Latest-Documentations.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Documentations.jpg#Latest-Documentations.jpg#$NAME#0" >>$TMP/$FILENAME.list
#	echo "Doku (Popular)#$SRC $SRC latest 'Popular-Documentations.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Documentations.jpg#Popular-Documentations.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Doku (Latest)#$SRC $SRC kino 'Latest-Dokumentationen.html'#http://openaaf.dyndns.tv/mediathek/menu/Latest-Documentations.jpg#Latest-Documentations.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Doku (Popular)#$SRC $SRC kino 'Popular-Dokumentationen.html'#http://openaaf.dyndns.tv/mediathek/menu/Popular-Documentations.jpg#Popular-Documentations.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Doku (A-Z)#$SRC $SRC sorted documentation#http://openaaf.dyndns.tv/mediathek/menu/a-z.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list

	echo "Actor (A-Z)#$SRC $SRC sorted actor#http://openaaf.dyndns.tv/mediathek/menu/a-z.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Director (A-Z)#$SRC $SRC sorted director#http://openaaf.dyndns.tv/mediathek/menu/a-z.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list
	echo "Genre#$SRC $SRC genre#http://openaaf.dyndns.tv/mediathek/menu/genre.jpg#a-z.jpg#$NAME#0" >>$TMP/$FILENAME.list

#	echo "Search#http://openaaf.dyndns.tv/mediathek/youtube/streams/kinox.all-sorted.list#http://openaaf.dyndns.tv/mediathek/menu/search.jpg#search.jpg#KinoX#21" >>$TMP/$FILENAME.list
	echo "Search#$SRC $SRC kino 'Search.html?q=%search%'#http://openaaf.dyndns.tv/mediathek/menu/search.jpg#search.jpg#$NAME#112" >>$TMP/$FILENAME.list
#	echo "Search Cast#http://openaaf.dyndns.tv/mediathek/youtube/streams/kinox.all-sorted.list#http://openaaf.dyndns.tv/mediathek/menu/search.jpg#search10.jpg#KinoX#31" >>$TMP/$FILENAME.list
	echo "Search Cast#$SRC $SRC cast 'https://www.imdb.com/find/?s=nm&q=%search%'#http://openaaf.dyndns.tv/mediathek/menu/search.jpg#search.jpg#$NAME#112" >>$TMP/$FILENAME.list

	echo "$TMP/$FILENAME.list"
}

sort()
{
# comment block1 start
<<"COMMENT"
#standart
https://ww22.kinos.to/Popular-Filme.html
#a-z
https://ww22.kinos.to/Popular-Filme.html?sort=title_asc
#z-a
https://ww22.kinos.to/Popular-Filme.html?sort=title_desc
#neueste
https://ww22.kinos.to/Popular-Filme.html?sort=year_desc
#älteste
https://ww22.kinos.to/Popular-Filme.html?sort=year_asc
#hohe wertung
https://ww22.kinos.to/Popular-Filme.html?sort=imdbrating_desc
#niedrige wertung
https://ww22.kinos.to/Popular-Filme.html?sort=imdbrating_asc
#trending
https://ww22.kinos.to/Popular-Filme.html?sort=popular
#letzte
https://ww22.kinos.to/Popular-Filme.html?sort=latest
#updated
https://ww22.kinos.to/Popular-Filme.html?sort=updated
COMMENT
# comment block1 end

#rm  "$TMP/$FILENAME.list"
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		watchlist="
			Standart#standart
			A-Z#?sort=title_asc
			Z-A#?sort=title_desc
			Neueste#?sort=year_desc
			Älteste#?sort=year_asc
			Hohe-Wertung-(iMDB)#?sort=imdbrating_desc
			Niedrige-Wertung-(iMDB)#?sort=imdbrating_asc
			Trending-(Popular)#?sort=popular
			Letzte#?sort=latest
			Updates#?sort=updated
			"
		rm $TMP/$FILENAME.list > /dev/null 2>&1

		for ROUND in $watchlist; do
			ID=`echo $ROUND | cut -d"#" -f2`
#			TITLE=`echo $ROUND | cut -d"#" -f1 | tr '-' ' '`
#TITLE $TITLE
			TITLE=`echo $ROUND | cut -d"#" -f1 | sed 's/-/ /g'`
			filename=`echo $TITLE | tr [A-Z] [a-z] | tr ' ' '_'`	

			echo "$TITLE#$SRC $SRC sorted genre '$ID'#http://openaaf.dyndns.tv/mediathek/menu/$ROUND0.jpg#$filename.jpg#$NAME#0" >> $TMP/$FILENAME.list

		done
	fi
  	echo "$TMP/$FILENAME.list"
}


genre()
{
#rm  "$TMP/$FILENAME.list"
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		watchlist="
			Action:1
			Adult:30
			Adventure:2
			Animation:3
			Anime:4
			Biography:23
			Bollywood:24
			Comedy:5
			Crime:6
			Documentary:7
			Drama:8
			Family:9
			Fantasy:10
			History:11
			Horror:12
			Music:14
			Musical:29
			Mystery:15
			Reality-TV:32
			Romance:16
			Sci-Fi:31
			Short:28
			Sport:18
			Thriller:20
			War:21
			Western:22
			"
		rm $TMP/$FILENAME.list > /dev/null 2>&1

		for ROUND in $watchlist; do
			ID=`echo $ROUND | cut -d":" -f2`
			TITLE=`echo $ROUND | cut -d":" -f1`

			filename=`echo $TITLE | tr [A-Z] [a-z]`	
			echo "$TITLE#$SRC $SRC sorted genre '$ID'#http://openaaf.dyndns.tv/mediathek/menu/$ROUND0.jpg#$filename.jpg#$NAME#0" >> $TMP/$FILENAME.list
		done
	fi
  	echo "$TMP/$FILENAME.list"
}

sorted()
{
#rm "$TMP/$FILENAME.list"
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		watchlist="ALL 1 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"

		rm $TMP/$FILENAME.list > /dev/null 2>&1

		for ROUND in $watchlist; do
			TITLE=`echo $ROUND`
			if [ "$ROUND" == "1" ];then
				TITLE="0-9"
			fi

			filename=`echo $TITLE | tr [A-Z] [a-z]`
			echo "$TITLE#$SRC $SRC search '$PAGE' 0 $ROUND $NEXT#http://openaaf.dyndns.tv/mediathek/menu/$filename.jpg#$filename.jpg#$NAME#0" >> $TMP/$FILENAME.list

		done
	fi
  	echo "$TMP/$FILENAME.list"
}

#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=@NEXT@&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22movie%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#                                                                                                                                                                                                                                                                          additional=%7B%22fType%22%3A%22$@PAGE2@%22%2C%22fLetter%22%3A%22$@PAGE@%22%7D

#https://www.kinos.to/aGET/Actor/?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=false&additional=%7B%22fLetter%22%3A%22B%22%2C%22fSex%22%3A%22%22%7D
#https://www.kinos.to/aGET/Actor/?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=false&additional=%7B%22fLetter%22%3A%22A%22%2C%22fSex%22%3A%22%22%7D
#https://www.kinos.to/aGET/Director/?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=false&additional=%7B%22fLetter%22%3A%22A%22%2C%22fSex%22%3A%22%22%7D

#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22Length%22%3A60%2C%22fLetter%22%3A1%2C%22fGenre%22%3A%226%22%7D

#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22movie%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22documentation%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22series%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#https://www.kinos.to/aGET/List/?sEcho=3&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22series%22%2C%22Length%22%3A60%2C%22fLetter%22%3A%22B%22%7D

#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22Length%22%3A60%2C%22fLetter%22%3A1%2C%22fGenre%22%3A%226%22%7D


#https://ww22.kinos.to/aGET/List/?sEcho=7&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22movie%22%2C%22 iSortingCols %22%3A1%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22asc%22%2C%22Length%22%3A60%2C%22fLetter%22%3A%22A%22%7D' \
#https://www.kinos.to /aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22movie%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D

cast()
{
#	rm $TMP/cache.$FILENAME.* > /dev/null 2>&1
#	rm $TMP/$FILENAME.list
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		piccount=0
#		TMPURL=$(echo $PAGE | cut -d"/" -f3)
		TMPURL=$(echo $PAGE | sed -nr 's/(http.*\/\/.*)\/.*/\1/p')
		TMPPAGE=$(echo $PAGE | cut -d"/" -f4)

#		$curlbin $PAGE -o $TMP/cache.$FILENAME.1
		$curlbin3 -A "$USERAGENT2" "$PAGE" -o $TMP/cache.$FILENAME.1

		cat $TMP/cache.$FILENAME.1 | grep "find-results-section-name" | sed 's#href="/name/nm#\nfound="/name/nm#g'| grep ^"found="  >$TMP/cache.$FILENAME.2

		while read -u 3 ROUND; do
#			TITLE=`echo $ROUND | sed -nr 's/.*<h3 class="ipc-title__text">([^>]+)<\/h3>.*/\1/p'`
			TITLE=`echo $ROUND | sed -nr 's/.*aria-label="([^"]+)".*/\1/p'`
			if [ -z "$TITLE" ] || [ "$TITLE" == "Add to list" ];then
				continue
			fi

			ID=`echo $ROUND | sed -nr 's/.*found="([^"]+)".*/\1/p' | sed 's/\/name\///' | cut -d"/" -f1`
			NEWPAGE="/People/$ID"

			if [ -z "$PIC" ]; then
				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
			fi
	
#			TITLE=`echo $TITLE | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/ä/g' -e 's/&uuml;/ü/g' -e 's/&ouml;/ö/g' -e 's/&eacute;/é/g' -e 's/&egrave;/è/g' -e 's/%F6/ö/g' -e 's/%FC/ü/g' -e 's/%E4/ä/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`
			TITLE=`echo $TITLE | sed -e 's/u2013/-/g' | sed -e 's/u00f4/ô/g' | sed -e 's/u00e9/é/g' | sed -e 's/u00e8/è/g' | sed -e 's/u00c4/Ä/g' | sed -e 's/u00dc/Ü/g' | sed -e 's/u00f6/ö/g' | sed -e 's/u00e4/ä/g' | sed -e 's/u00fc/ü/g' | sed -e 's/u00df/ß/g' | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/\E4/g' -e 's/&uuml;/\FC/g' -e 's/&ouml;/\F6/g' -e 's/&eacute;/\E9/g' -e 's/&egrave;/\E8/g' -e 's/%F6/\F6/g' -e 's/%FC/\FC/g' -e 's/%E4/\E4/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`
	
			if [ ! -z "$TITLE" ] && [ ! -z "$TMPURL" ];then
				if [ ! -e $TMP/$FILENAME.list ];then
					touch $TMP/$FILENAME.list
				fi
				piccount=`expr $piccount + 1`
#
#				LINE="$TITLE#$SRC $SRC search '$NEWPAGE'#$PIC#$PARSER.$INPUT.$NEXT.$PAGE2.$FILENAME.$piccount.jpg#$NAME#0"
				LINE="$TITLE#$NEWPAGE#$PIC#$PARSER.$INPUT.$NEXT.$PAGE2.$FILENAME.$piccount.jpg#KinoX - Cast Search#32"

				echo "$LINE" >> $TMP/$FILENAME.list
			fi
	
		done 3<$TMP/cache.$FILENAME.2

		rm $TMP/cache.$FILENAME.* > /dev/null 2>&1
	fi
	echo "$TMP/$FILENAME.list"
}

search()
{
#	rm $TMP/cache.$FILENAME.* > /dev/null 2>&1
#	rm $TMP/$FILENAME.list
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		piccount=0
#		$ACTIVEBIN "$URL/aGET/List/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=50&iSortingCols=1&iSortCol_0=5&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22$PAGE2%22%2C%22fLetter%22%3A%22$PAGE%22%7D" > $TMP/cache.$FILENAME.1

		if [ "$PAGE" == "genre" ];then

# comment block1 start
<<"COMMENT"
standart
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%7D
additional={"Length":60,"fGenre":"8","fLetter":"N"}
a-z
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22asc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":2,"sSortDir_0":"asc","iSortingCols":1}
z-a
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22desc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":2,"sSortDir_0":"desc","iSortingCols":1}
neueste
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A100%2C%22sSortDir_0%22%3A%22desc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":100,"sSortDir_0":"desc","iSortingCols":1}
älteste
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A100%2C%22sSortDir_0%22%3A%22asc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":100,"sSortDir_0":"asc","iSortingCols":1}
hohe wertung
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A6%2C%22sSortDir_0%22%3A%22desc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":6,"sSortDir_0":"desc","iSortingCols":1}
niedrige wertung
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A6%2C%22sSortDir_0%22%3A%22asc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":6,"sSortDir_0":"asc","iSortingCols":1}
trending
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A101%2C%22sSortDir_0%22%3A%22desc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":101,"sSortDir_0":"desc","iSortingCols":1}
letzte
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A102%2C%22sSortDir_0%22%3A%22desc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":102,"sSortDir_0":"desc","iSortingCols":1}
updates
additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%228%22%2C%22fLetter%22%3A%22N%22%2C%22iSortCol_0%22%3A103%2C%22sSortDir_0%22%3A%22desc%22%2C%22iSortingCols%22%3A1%7D
additional={"Length":60,"fGenre":"8","fLetter":"N","iSortCol_0":103,"sSortDir_0":"desc","iSortingCols":1}

additional=%7B%22fType%22%3A%22movie%22%2C%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22desc%22%2C%22Length%22%3A60%2C%22fLetter%22%3A%22A%22%7D' \
additional={"fType":"movie","iSortingCols":1,"iSortCol_0":2,"sSortDir_0":"desc","Length":60,"fLetter":"A"}'\

additional=%7B%22Length%22%3A60%2C%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22desc%22%2C%22fType%22%3A%22movie%22%2C%22fLetter%22%3A%22movie%22%7D
additional={"Length":60,"iSortingCols":1,"iSortCol_0":2,"sSortDir_0":"desc","fType":"movie","fLetter":"movie"}
COMMENT
# comment block1 end

#			$ACTIVEBIN "$URL/aGET/List/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=50&iSortingCols=1&iSortCol_0=5&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22$PAGE%22%2C%22fLetter%22%3A%22$PAGE2%22%7D" > $TMP/cache.$FILENAME.1
			TMPPFAD=List
			SORTING="%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A$SORTCOL%2C%22sSortDir_0%22%3A%22$SORTDIR%22"
			LENGTH="%22Length%22%3A$DISPLAYED"
			FLETTER="%22fLetter%22%3A%22$PAGE2%22"
			FGENRE="%22fGenre%22%3A%22$PAGE3%22"
			LANGUAGE="%22language%22%3A$LANGID"
            if [ "$PAGE2" == "ALL" ]; then
			    if [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
                    SORTCOL=2
				    additional="%7B$LENGTH%2C$FGENRE%2C$LANGUAGE%7D"
			    else
				    additional="%7B$LENGTH%2C$SORTING%2C$FGENRE%2C$LANGUAGE%7D"
			    fi
            else
			    if [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
                    SORTCOL=2
				    additional="%7B$LENGTH%2C$FGENRE%2C$FLETTER%2C$LANGUAGE%7D"
			    else
				    additional="%7B$LENGTH%2C$SORTING%2C$FGENRE%2C$FLETTER%2C$LANGUAGE%7D"
			    fi
            fi
		elif [ "$PAGE" == "movie" ] || [ "$PAGE" == "series" ] || [ "$PAGE" == "documentation" ];then
#			$ACTIVEBIN "$URL/aGET/List/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=50&iSortingCols=1&iSortCol_0=5&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22$PAGE%22%2C%22fLetter%22%3A%22$PAGE2%22%7D" > $TMP/cache.$FILENAME.1
			TMPPFAD=List
			SORTING="%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A$SORTCOL%2C%22sSortDir_0%22%3A%22$SORTDIR%22"
			LENGTH="%22Length%22%3A$DISPLAYED"
   			FLETTER="%22fLetter%22%3A%22$PAGE2%22"
			FTYPE="%22fType%22%3A%22$PAGE%22"
			LANGUAGE="%22language%22%3A$LANGID"
            if [ "$PAGE2" == "ALL" ]; then
			    if [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
                    SORTCOL=2
                    SORTDIR=asc
				    additional="%7B$LENGTH%2C$FTYPE%2C$LANGUAGE%7D"
			    else
				    additional="%7B$LENGTH%2C$SORTING%2C$FTYPE%2C$LANGUAGE%7D"
			    fi
            else
			    if [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
                    SORTCOL=2
                    SORTDIR=asc
				    additional="%7B$LENGTH%2C$FTYPE%2C$FLETTER%2C$LANGUAGE%7D"
			    else
				    additional="%7B$LENGTH%2C$SORTING%2C$FTYPE%2C$FLETTER%2C$LANGUAGE%7D"
			    fi
            fi
# additional={"fType":"movie","iSortingCols":1,"iSortCol_0":2,"sSortDir_0":"asc","Length":60,"fLetter":"A"}'\
# additional={"fType":"movie","Length":60,"fLetter":1}

		elif [ "$PAGE" == "actor" ];then
#			$ACTIVEBIN "$URL/aGET/Actor/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=50&iSortingCols=1&iSortCol_0=5&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fLetter%22%3A%22$PAGE2%22%2C%22fSex%22%3A%22%22%7D" > $TMP/cache.$FILENAME.1
			TMPPFAD=Actor
			#PAGE=actor
			#PAGE2=A
#			FLETTER="%22fLetter%22%3A%22$PAGE2%22"
#			FSEX="%22fSex%22%3A%22%22"
##			additional="%7B$FLETTER%2C$FSEX%7D"
#			SORTING="%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22asc%22%2C%22Length%22%3A60"	
#			additional="%7B$FLETTER%2C$FSEX%2C$SORTING%7D"

			SORTING="%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A$SORTCOL%2C%22sSortDir_0%22%3A%22$SORTDIR%22"
			LENGTH="%22Length%22%3A$DISPLAYED"
			FLETTER="%22fLetter%22%3A%22$PAGE2%22"
			FSEX="%22fSex%22%3A%22%22"
			if [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
                SORTCOL=2
                SORTDIR=asc
				additional="%7B$LENGTH%2C$FSEX%2C$FLETTER%7D"
			else
				additional="%7B$LENGTH%2C$SORTING%2C$FSEX%2C$FLETTER%7D"
			fi
		elif [ "$PAGE" == "director" ];then
#			$ACTIVEBIN "$URL/aGET/Director/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=50&iSortingCols=1&iSortCol_0=5&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fLetter%22%3A%22$PAGE2%22%2C%22fSex%22%3A%22%22%7D" > $TMP/cache.$FILENAME.1
			TMPPFAD=Director
			#PAGE=director
			#PAGE2=A
#			FLETTER="%22fLetter%22%3A%22$PAGE2%22"
#			FSEX="%22fSex%22%3A%22%22"
##			additional="%7B$FLETTER%2C$FSEX%7D"
#			SORTING="%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A2%2C%22sSortDir_0%22%3A%22asc%22%2C%22Length%22%3A60"	
#			additional="%7B$FLETTER%2C$FSEX%2C$SORTING%7D"

			SORTING="%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A$SORTCOL%2C%22sSortDir_0%22%3A%22$SORTDIR%22"
			LENGTH="%22Length%22%3A$DISPLAYED"
			FLETTER="%22fLetter%22%3A%22$PAGE2%22"
			FSEX="%22fSex%22%3A%22%22"
			if [ -z "$SORTCOL" ] || [ -z "$SORTDIR" ] || [ -z "$SORTURL" ]; then
                SORTCOL=2
                SORTDIR=asc
				additional="%7B$LENGTH%2C$FSEX%2C$FLETTER%7D"
			else
				additional="%7B$LENGTH%2C$SORTING%2C$FSEX%2C$FLETTER%7D"
			fi
		fi

#echo TMPPFAD $TMPPFAD
#echo FLETTER $FLETTER

#echo FSEX $FSEX
#echo FTYPE $FTYPE
#echo FGENRE $FGENRE
#echo PAGE $PAGE
#echo additional $additional

#####	$ACTIVEBIN "$URL/aGET/$TMPPFAD/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=50&iSortingCols=1&iSortCol_0=5&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=$additional" > $TMP/cache.$FILENAME.1
		$ACTIVEBIN "$URL/aGET/$TMPPFAD/?sEcho=1&iColumns=10&sColumns=&iDisplayStart=$NEXT&iDisplayLength=$DISPLAYED&iSortingCols=1&iSortCol_0=$SORTCOL&sSortDir_0=$SORTDIR&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=$additional" > $TMP/cache.$FILENAME.1

#curl 'https://www22.kinox.to/aGET/List/' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0' 
#-H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' -H 'Accept-Encoding: gzip, deflate, br, zstd' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' 
#-H 'Origin: https://www22.kinox.to' -H 'Connection: keep-alive' -H 'Referer: https://www22.kinox.to/All-Filme.html' 
#-H 'Cookie: ListMode=list; PHPSESSID=vmpii3tntkv37555iceg9coog2; dom3ic8zudi28v8lr6fgphwffqoz0j6c=2b07c179-d852-4816-b0c0-60fb4913d445%3A3%3A1; prefetchAd_8611390=true; pp_main_91b83e20f432fbce3ffaa5563a9b96f6=1; sb_page_f9eb567a6d93473eaa9431be266bc409=1; sb_main_f9eb567a6d93473eaa9431be266bc409=1; sb_count_f9eb567a6d93473eaa9431be266bc409=1; pp_sub_91b83e20f432fbce3ffaa5563a9b96f6=1; pp_delay_91b83e20f432fbce3ffaa5563a9b96f6=1' 
#-H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'TE: trailers' 
#--data-raw 'Page=1&Per_Page=10&url=%2FaGET%2FList%2F&dir=desc&sort=title&per_page=10&ListMode=cover&additional=%7B%22fType%22%3A%22movie%22%2C%22iSortingCols%22%3A1%2C%22iSortCol_0%22%3A6%2C%22sSortDir_0%22%3A%22desc%22%2C%22Length%22%3A60%7D&iDisplayStart=0&iDisplayLength=10'

#--data-raw'Page=1&Per_Page=10&url=/aGET/List/&dir=desc&sort=title&per_page=10&ListMode=cover&additional={"fType":"movie","iSortingCols":1,"iSortCol_0":6,"sSortDir_0":"desc","Length":60}&iDisplayStart=0&iDisplayLength=10'
#data="Page=1&Per_Page=10&url=/aGET/List/&dir=desc&sort=title&per_page=10&ListMode=cover&additional=$additional"



#LISTMOD=cover
#data="Page=1&Per_Page=10&url=/aGET/List/&dir=$SORTDIR$SORTURL&per_page=10&ListMode=$LISTMOD&additional=$additional"

#		$ACTIVEBIN -X POST --data "$data" "$URL/aGET/$TMPPFAD/"
#echo data $data
#curl 'https://www22.kinox.to/aGET/List/' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0' --data-raw 'Page=1&Per_Page=10&url=%2FaGET%2FList%2F&dir=desc&sort=title&per_page=10&ListMode=cover&additional=%7B%22fType%22%3A%22movie%22%2C%22Length%22%3A60%7D&iDisplayStart=0&iDisplayLength=10'


#curl 'https://www22.kinox.to/aGET/List/' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: de,en-US;q=0.7,en;q=0.3' -H 'Accept-Encoding: gzip, deflate, br, zstd' -H 'Content-Type: application/x-www-form-urlencoded' -H 'X-Requested-With: XMLHttpRequest' -H 'Origin: https://www22.kinox.to' -H 'Connection: keep-alive' -H 'Referer: https://www22.kinox.to/Genre/Action' -H 'Cookie: ListMode=cover; PHPSESSID=vmpii3tntkv37555iceg9coog2; dom3ic8zudi28v8lr6fgphwffqoz0j6c=2b07c179-d852-4816-b0c0-60fb4913d445%3A3%3A1; pp_main_91b83e20f432fbce3ffaa5563a9b96f6=1; sb_page_f9eb567a6d93473eaa9431be266bc409=2; sb_main_f9eb567a6d93473eaa9431be266bc409=1; sb_count_f9eb567a6d93473eaa9431be266bc409=2; pp_sub_91b83e20f432fbce3ffaa5563a9b96f6=1; prefetchAd_8611390=true; SpryMedia_DataTables_RsltTable_fernseh-tvserien.html=%7B%22iCreate%22%3A1767044401581%2C%22iStart%22%3A0%2C%22iEnd%22%3A0%2C%22iLength%22%3A25%2C%22sFilter%22%3A%22%22%2C%22sFilterEsc%22%3Atrue%2C%22aaSorting%22%3A%5B%20%5B2%2C%22asc%22%5D%5D%2C%22aaSearchCols%22%3A%5B%20%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%2C%5B%22%22%2Ctrue%5D%5D%2C%22abVisCols%22%3A%5B%20true%2Ctrue%2Ctrue%2Ctrue%2Ctrue%2Ctrue%2Ctrue%5D%7D; pp_show_on_48fae91c18e4281028a402328c03c8b8=1; pp_main_48fae91c18e4281028a402328c03c8b8=1; pp_exp_48fae91c18e4281028a402328c03c8b8=1767048017790; sb_page_4582c29d94d4ee56fc899eeb4a9f3636=1; sb_main_4582c29d94d4ee56fc899eeb4a9f3636=1; sb_count_4582c29d94d4ee56fc899eeb4a9f3636=1; sb_delay_4582c29d94d4ee56fc899eeb4a9f3636=1; total_count_48fae91c18e4281028a402328c03c8b8=1; pp_sub_48fae91c18e4281028a402328c03c8b8=1; pp_delay_48fae91c18e4281028a402328c03c8b8=1' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin' -H 'Priority: u=0' -H 'TE: trailers' 
#--data-raw 'Page=1&Per_Page=10&url=%2FaGET%2FList%2F&dir=desc&sort=title&per_page=10&ListMode=cover&additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%221%22%7D&iDisplayStart=0&iDisplayLength=10'
#--data-raw 'Page=1&Per_Page=10&url=%2FaGET%2FList%2F&dir=$SORTDIR&sort=$SORTURL&per_page=10&ListMode=cover&additional=%7B%22Length%22%3A60%2C%22fGenre%22%3A%221%22%7D&iDisplayStart=0&iDisplayLength=10'

#exit
#https://www.kinos.to/aGET/Actor/?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=false&additional=%7B%22fLetter%22%3A%22B%22%2C%22fSex%22%3A%22%22%7D
#https://www.kinos.to/aGET/Actor/?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=false&additional=%7B%22fLetter%22%3A%22A%22%2C%22fSex%22%3A%22%22%7D
#https://www.kinos.to/aGET/Director/?sEcho=1&iColumns=2&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=1&sSortDir_0=asc&bSortable_0=true&bSortable_1=false&additional=%7B%22fLetter%22%3A%22A%22%2C%22fSex%22%3A%22%22%7D
#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22Length%22%3A60%2C%22fLetter%22%3A1%2C%22fGenre%22%3A%226%22%7D

#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22movie%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22documentation%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#https://www.kinos.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22series%22%2C%22Length%22%3A60%2C%22fLetter%22%3A1%7D
#https://www.kinos.to/aGET/List/?sEcho=3&iColumns=7&sColumns=&iDisplayStart=0&iDisplayLength=25&iSortingCols=1&iSortCol_0=2&sSortDir_0=asc&bSortable_0=true&bSortable_1=true&bSortable_2=true&bSortable_3=false&bSortable_4=false&bSortable_5=false&bSortable_6=true&additional=%7B%22fType%22%3A%22series%22%2C%22Length%22%3A60%2C%22fLetter%22%3A%22B%22%7D

		if [ `cat $TMP/cache.$FILENAME.1 | grep "KinoX 404 Not Found" | wc -l` -eq 1 ];then
			ERRORMSG="KinoX 404 Not Found"
			LINE="$ERRORMSG#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
			echo "$LINE" > $TMP/$FILENAME.list
			exit
		fi

		if [ `cat $TMP/cache.$FILENAME.1 | grep "KinoX 503 Service Temporarily Unavailable" | wc -l` -eq 1 ];then
			ERRORMSG="KinoX 503 Service Temporarily Unavailable"
			LINE="$ERRORMSG#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
			echo "$LINE" > $TMP/$FILENAME.list
			exit
		fi
#{"sEcho":"1","iTotalRecords":null,"iTotalDisplayRecords":75,"aaData":
		pages=`cat $TMP/cache.$FILENAME.1 | sed -nr 's/.*iTotalDisplayRecords":([^:]+),.*/\1/p'`

		if [ -z "$pages" ];then
			pages=0
		fi
#		cat $TMP/cache.$FILENAME.1 | tr '\n' ' ' | sed 's!<TR>!\nfound=!g'| grep ^"found="  >$TMP/cache.$FILENAME.2
		cat $TMP/cache.$FILENAME.1 | tr '\n' ' ' | sed 's!\["!\nfound=["!g' | grep ^"found="  >$TMP/cache.$FILENAME.2

#exit
		if [ "$pages" == " " ] || [ -z "$pages" ] || [ "$pages" == 0 ]; then
			echo errormsg="no pages $pages found"
#			rm $TMP/cache.$FILENAME.1
#			break
#			ls $TMP/cache.$FILENAME.1
#			exit
		fi
	
#		if [ $pages -gt 1000 ]; then
#			pages=1000
#		fi
	
		max=`expr $pages - 4`

		cat $TMP/cache.$FILENAME.2 > $TMP/cache.$FILENAME.3

		if [ "$PAGE" == "actor" ] || [ "$PAGE" == "director" ];then
			cat $TMP/cache.$FILENAME.1 | sed "s!\[!\n\[!g" | grep '"nm' > $TMP/cache.$FILENAME.3
		fi

		count=0

		while read -u 3 ROUND; do
			piccount=`expr $piccount + 1`#			filename=`echo $ROUND | sed 's!/Stream/!!'`
			filename=`echo $ROUND | sed -nr 's#.*<a href="/Stream/([^/]+)" .*#\1#p'`
			picname=`echo $filename | sed 's!.html!.jpg!'`
			searchname=`echo $filename | sed 's!.html!!'`
			TITLE=`echo $ROUND | sed -nr 's#.*onclick="return false;">([^>]+)</a> .*#\1#p'`

			if [ -z "$TITLE" ];then
				TITLE=`echo $ROUND | sed -nr 's#.*false;">([^>]+)</a> .*#\1#p'`
			fi
			YEAR=`echo $ROUND | sed -nr 's#.*"Year">([^>]+)</span>.*#\1#p'`
			IMDB=`echo $ROUND | sed -nr 's#.*\|([^|]+)".*#\1#p' | cut -d'"' -f1`
            LANG=`echo $ROUND | cut -d'"' -f2`
#OLD=0
#if [ $OLD == 1 ];then
			if [ `cat /mnt/config/titan.cfg | grep tithek_kinox_pic=1 | wc -l` -eq 1 ];then
		#		$wgetbin --no-check-certificate "$MAINURL/$ROUND1" -O cache."$filename".list
#				echo $BIN /tmp/localhoster/cloudflare.py "$URL/Stream/$ROUND"
				$ACTIVEBIN "$URL/Stream/$ROUND" > $TMP/cache."$filename".list
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN2 /tmp/localhoster/cloudflare.py "$URL/Stream/$ROUND"
					$ACTIVEBIN "$URL/Stream/$ROUND" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN3 /tmp/localhoster/cloudflare.py "$URL/Stream/$ROUND"
					$ACTIVEBIN "$URL/Stream/$ROUND" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN4 /tmp/localhoster/cloudflare.py "$URL/Stream/$ROUND"
					$ACTIVEBIN "$URL/Stream/$ROUND" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN5 /tmp/localhoster/cloudflare.py "$URL/Stream/$ROUND"
					$ACTIVEBIN "$URL/Stream/$ROUND" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN6 /tmp/localhoster/cloudflare.py "$URL/Stream/$ROUND"
					$ACTIVEBIN "$URL/Stream/$ROUND" > $TMP/cache."$filename".list
				fi
				PIC=$URL/`cat $TMP/cache."$filename".list | tr '><' '>\n<' | grep $picname | cut -d '"' -f2 | sort -um`
				LANG=`cat $TMP/cache."$filename".list | grep 'alt="language" src="/gr/sys/lng' | sed 's!alt="language" src="/gr/sys/lng/!\n!' | tail -n1 |cut -d"." -f1`
#			else
#				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
#				LANG=1
			fi
#fi

            LANGTXT=$(getlangtext $LANG)

#			NEWPAGE="$URL/$PAGE"
#			NEWPAGE="$URL/Stream/$ROUND"
			NEWPAGE="$URL/Stream/$filename"

			if [ ! -z "$IMDB" ];then
				IMDBTXT=" ($IMDB)"
			fi
			if [ ! -z "$YEAR" ];then
				YEARTXT=" ($YEAR)"
			fi

			if [ -z "$PIC" ] || [ "$PIC" == "$URL""/statics/thumbs/" ]; then
				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
			fi

			if [ "$PAGE" == "actor" ] || [ "$PAGE" == "director" ];then
				TMPPFAD=`echo $ROUND | sed -nr 's/.*","([^"]+)".*/\1/p'`
				NEWPAGE="/People/$TMPPFAD"
#["A. Abdul Hameed","nm1869655"],

				TITLE=`echo $ROUND | sed -nr 's/.*"([^"]+)",.*/\1/p'`
			fi
			if [ -z "$PIC" ]; then
				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
			fi

#tu00e4glich gru00fcu00dft das Murmeltier
			TITLE=`echo $TITLE | sed -e 's/u2013/-/g' | sed -e 's/u00f4/ô/g' | sed -e 's/u00e9/é/g' | sed -e 's/u00e8/è/g' | sed -e 's/u00c4/Ä/g' | sed -e 's/u00dc/Ü/g' | sed -e 's/u00f6/ö/g' | sed -e 's/u00e4/ä/g' | sed -e 's/u00fc/ü/g' | sed -e 's/u00df/ß/g' | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/\E4/g' -e 's/&uuml;/\FC/g' -e 's/&ouml;/\F6/g' -e 's/&eacute;/\E9/g' -e 's/&egrave;/\E8/g' -e 's/%F6/\F6/g' -e 's/%FC/\FC/g' -e 's/%E4/\E4/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`
#decode title
#			TITLE=$(echo "$TITLE" | $BIN -c 'import html, sys; [print(html.unescape(l), end="") for l in sys.stdin]')
#

			if [ ! -z "$TITLE" ] && [ ! -z "$NEWPAGE" ];then
				if [ ! -e $TMP/$FILENAME.list ];then
					touch $TMP/$FILENAME.list
				fi
				piccount=`expr $piccount + 1`

                #<div class="Descriptore">John Rambo ist in einem Provinznest auf der Suche nach einem Kriegskameraden, mit dem er in Vietnam in einer Spezialeinheit gewesen war. Aber sein Freund ist bereits gestorben. Die Polizei hält den hochdekorierten Vietnam-Veteranen Rambo für einen Landstreicher und nimmt ihn fest. Polizeichef Teasle, der ihn auf der Wache quält und demütigt, ahnt nicht, dass er damit eine Lawine ins Rollen bringt: Rambos Instinkte werden wach. In einer atemberaubenden Aktion flieht er in die Berge. Teasle hetzt ihm den gesamten Polizeistab hinterher, doch Rambo ist ganz in seinem Element und lässt den Beamten keine Chance.<br /> <br /> <a href="">Jetzt herunterladen!</a>
                #</div>
                desc="$ACTIVEBIN --connect-timeout 5 $NEWPAGE | sed -nr 's/.*<div class=\"Descriptore\">([^>]+)<.*/\1/p'"

                #<div class="Grahpics"><a href="/Stream/Rambo_First_Blood.html"><img src="/statics/thumbs/00002000/Rambo_First_Blood.jpg" alt="Rambo: First Blood" /></a></div>
                PIC="echo $URL | tr -d '\n' && $ACTIVEBIN --connect-timeout 5 $NEWPAGE | sed -nr 's/.*<div class=\"Grahpics\"><a href=\".*img src=\"([^\"]+)\".*/\1/p' | tr -d '\n'"

#				LINE="$TITLE$LANGTXT#$NEWPAGE#$PIC#$FILENAME"_"$piccount"_"$filename.jpg#KinoX#22#$desc"
				LINE="$TITLE$LANGTXT$YEARTXT$IMDBTXT#$NEWPAGE#$PIC#$FILENAME"_"$piccount"_"$filename.jpg#KinoX#22#$desc"
#				LINE="$TITLE$LANGTXT$YEARTXT$IMDBTXT#$NEWPAGE#$PIC#$FILENAME"_"$piccount"_"$filename.jpg#KinoX#22#$PLOT"

				if [ "$PAGE" == "actor" ] || [ "$PAGE" == "director" ];then
#					LINE="$TITLE#$SRC $SRC search 'movie' 1 '$NEWPAGE'#$PIC#kinox_$piccount.jpg#KinoX#0"
					LINE="$TITLE#$NEWPAGE#$PIC#$FILENAME"_"$piccount"_"$filename.jpg#KinoX#32#$desc"
				fi
#echo LINE $LINE
				echo "$LINE" >> $TMP/$FILENAME.list
			fi

		done 3<$TMP/cache.$FILENAME.3

		if [ "$NEXT" -lt "$pages" ]; then
			NEXTPAGE=`expr $NEXT + $DISPLAYED`
			LINE="Next Results ($NEXTPAGE/$pages)#$SRC $SRC search '$PAGE' '$NEXTPAGE' '$PAGE2' '$PAGE3'#http://openaaf.dyndns.tv/mediathek/menu/next.jpg#next.jpg#$NAME#0"
			echo "$LINE" >> $TMP/"$FILENAME".list
		fi

		rm $TMP/cache.$FILENAME.* > /dev/null 2>&1
	fi
	echo "$TMP/$FILENAME.list"
}

kino()
{
#echo kino
#	rm $TMP/cache.$FILENAME.* > /dev/null 2>&1
#	rm $TMP/$FILENAME.list
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		piccount=0
#		$curlbin "$URL/$PAGE" -o "$TMP/cache.$FILENAME.1"
		$ACTIVEBIN "$URL/$PAGE$SORTURL$LANGURL" > $TMP/cache.$FILENAME.1

#LISTMOD=cover
#data="Page=1&Per_Page=10&url=/aGET/List/&dir=$SORTDIR$SORTURL&per_page=10&ListMode=$LISTMOD&additional=$additional"

#		$ACTIVEBIN -X POST --data "$data" "$URL/aGET/$TMPPFAD/"
#echo data $data
#curl 'https://www22.kinox.to/aGET/List/' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:138.0) Gecko/20100101 Firefox/138.0' --data-raw 'Page=1&Per_Page=10&url=%2FaGET%2FList%2F&dir=desc&sort=title&per_page=10&ListMode=cover&additional=%7B%22fType%22%3A%22movie%22%2C%22Length%22%3A60%7D&iDisplayStart=0&iDisplayLength=10' > $TMP/cache.$FILENAME.1


		if [ `cat $TMP/cache.$FILENAME.1 | grep "KinoX 404 Not Found" | wc -l` -eq 1 ];then
			ERRORMSG="KinoX 404 Not Found"
#			echo "errormsg=$ERRORMSG"
			LINE="$ERRORMSG#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
			echo "$LINE" > $TMP/$FILENAME.list
			exit
		fi
		if [ `cat $TMP/cache.$FILENAME.1 | grep "KinoX 503 Service Temporarily Unavailable" | wc -l` -eq 1 ];then
			ERRORMSG="KinoX 503 Service Temporarily Unavailable"
#			echo "errormsg=$ERRORMSG"
			LINE="$ERRORMSG#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
			echo "$LINE" > $TMP/$FILENAME.list
			exit
		fi

#		cat $TMP/cache.$FILENAME.1 | grep /Stream/ | sed 's!/Stream/!\n/Stream/!' | grep ^/Stream/ | cut -d '"' -f1  | cut -d "'" -f1 | sort -um >$TMP/cache.$FILENAME.2
#		cat $TMP/cache.$FILENAME.1 | grep /Stream/ | sed 's!/Stream/!\n/Stream/!' | grep ^/Stream/ | cut -d '"' -f1  | cut -d "'" -f1 >$TMP/cache.$FILENAME.2

		cat $TMP/cache.$FILENAME.1 | tr '\n' ' ' | sed 's!location.href!\nlocation.href!g' | grep ^'location.href' | grep "/Stream/" >$TMP/cache.$FILENAME.2

		while read -u 3 ROUND; do
			piccount=`expr $piccount + 1`
			PAGE=`echo $ROUND | sed -nr "s/.*location.href='([^']+)'.*/\1/p"`
			filename=`echo $PAGE | cut -d "/" -f3`
			picname=`echo $filename | sed 's!.html!.jpg!'`
			searchname=`echo $filename | sed 's!.html!!'`	

			TITLE=`echo $ROUND | sed -nr 's/.*title="([^"]+)".*/\1/p'`
#			PIC="$URL""/statics/thumbs/"`echo $ROUND | sed -nr 's/.*\/statics\/thumbs\/(.*)" \/>.*/\1/p'`
			PIC="$URL""/statics/thumbs/"`echo $ROUND | sed -nr 's/.*\/statics\/thumbs\/(.*)" \/><.*/\1/p'`
			PLOT=`echo $ROUND | sed -nr 's/.*<div class="Descriptor">([^>]+)<\/div>.*/\1/p'`
			LANG=`echo $ROUND | grep 'src="/gr/sys/lng' | sed 's!src="/gr/sys/lng/!\n!' | tail -n1 |cut -d"." -f1`
			IMDB=`echo $ROUND | sed -nr 's/.*<b>IMDb:<\/b> ([^ ]+) \/.*/\1/p'`
			YEAR=`echo $ROUND | sed -nr 's/.*"Year">([^>]+)<\/span>.*/\1/p'`

            LANGTXT=$(getlangtext $LANG)

			NEWPAGE="$URL/$PAGE"

			if [ ! -z "$IMDB" ] && [ "$IMDB" != 0 ];then
				IMDBTXT=" ($IMDB)"
			fi
			if [ ! -z "$YEAR" ];then
				YEARTXT=" ($YEAR)"
			fi

			if [ -z "$PIC" ] || [ "$PIC" == "$URL""/statics/thumbs/" ]; then
				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
			fi
#			TITLE=`echo $TITLE | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/\E4/g' -e 's/&uuml;/\FC/g' -e 's/&ouml;/\F6/g' -e 's/&eacute;/\E9/g' -e 's/&egrave;/\E8/g' -e 's/%F6/\F6/g' -e 's/%FC/\FC/g' -e 's/%E4/\E4/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`
			TITLE=`echo $TITLE | sed -e 's/u2013/-/g' | sed -e 's/u00f4/ô/g' | sed -e 's/u00e9/é/g' | sed -e 's/u00e8/è/g' | sed -e 's/u00c4/Ä/g' | sed -e 's/u00dc/Ü/g' | sed -e 's/u00f6/ö/g' | sed -e 's/u00e4/ä/g' | sed -e 's/u00fc/ü/g' | sed -e 's/u00df/ß/g' | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/\E4/g' -e 's/&uuml;/\FC/g' -e 's/&ouml;/\F6/g' -e 's/&eacute;/\E9/g' -e 's/&egrave;/\E8/g' -e 's/%F6/\F6/g' -e 's/%FC/\FC/g' -e 's/%E4/\E4/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`

			if [ ! -z "$TITLE" ] && [ ! -z "$NEWPAGE" ];then
				if [ ! -e $TMP/$FILENAME.list ];then
					touch $TMP/$FILENAME.list
				fi
				piccount=`expr $piccount + 1`
				LINE="$TITLE$LANGTXT$YEARTXT$IMDBTXT#$NEWPAGE#$PIC#$FILENAME"_"$piccount"_"$filename.jpg#KinoX#22#$PLOT"

				if [ `cat $TMP/$FILENAME.list | grep "$TITLE" | wc -l` -eq 0 ];then
					echo "$LINE" >> $TMP/$FILENAME.list
				fi
			fi

		done 3<$TMP/cache.$FILENAME.2
		rm $TMP/cache.$FILENAME.* > /dev/null 2>&1

	fi
	echo "$TMP/$FILENAME.list"
}

latest()
{
#	rm $TMP/cache.$FILENAME.* > /dev/null 2>&1
#	rm $TMP/$FILENAME.list
	if [ ! -e "$TMP/$FILENAME.list" ]; then
		piccount=0
#		$curlbin "$URL/$PAGE" -o "$TMP/cache.$FILENAME.1"
		$ACTIVEBIN "$URL/$PAGE" > $TMP/cache.$FILENAME.1

		if [ `cat $TMP/cache.$FILENAME.1 | grep "KinoX 404 Not Found" | wc -l` -eq 1 ];then
			ERRORMSG="KinoX 404 Not Found"
#			echo "errormsg=$ERRORMSG"
			LINE="$ERRORMSG#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
			echo "$LINE" > $TMP/$FILENAME.list
			exit
		fi

		if [ `cat $TMP/cache.$FILENAME.1 | grep "KinoX 503 Service Temporarily Unavailable" | wc -l` -eq 1 ];then
			ERRORMSG="KinoX 503 Service Temporarily Unavailable"
#			echo "errormsg=$ERRORMSG"
			LINE="$ERRORMSG#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
			echo "$LINE" > $TMP/$FILENAME.list
			exit
		fi

		cat $TMP/cache.$FILENAME.1 | tr '\n' ' ' | sed 's/<tr>/\n<tr>/g' | grep ^"<tr>" | grep "/Stream/" >$TMP/cache.$FILENAME.2

		while read -u 3 ROUND; do
			piccount=`expr $piccount + 1`
			filename=`echo $ROUND | sed -nr 's/.*<a href="\/Stream\/([^\/]+)" .*/\1/p' | cut -d'"' -f1`
			picname=`echo $filename | sed 's!.html!.jpg!'`
			searchname=`echo $filename | sed 's!.html!!'`	

			PAGE=`echo $ROUND | sed -nr 's/.*<a href="([^"]+)" .*/\1/p'`
			TITLE=`echo $picname | sed 's!.jpg!!' | tr "_" " "`
			LANG=`echo $ROUND | grep 'src="/gr/sys/lng' | sed 's!src="/gr/sys/lng/!\n!' | tail -n1 |cut -d"." -f1`
			IMDB=`echo $ROUND | sed -nr 's/.*"Rating">([^>]+)<\/td>.*/\1/p'`
			YEAR=`echo $ROUND | sed -nr 's/.*"Year">([^>]+)<\/span>.*/\1/p'`

			if [ `cat /mnt/config/titan.cfg | grep tithek_kinox_pic=1 | wc -l` -eq 1 ];then
		#		$wgetbin --no-check-certificate "$MAINURL/$PAGE" -O cache."$filename".list
#				echo $BIN /tmp/localhoster/cloudflare.py "$URL/$PAGE"
				$ACTIVEBIN "$URL/$PAGE" > $TMP/cache."$filename".list
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN2 /tmp/localhoster/cloudflare.py "$URL/$PAGE"
					$ACTIVEBIN "$URL/$PAGE" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN3 /tmp/localhoster/cloudflare.py "$URL/$PAGE"
					$ACTIVEBIN "$URL/$PAGE" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN4 /tmp/localhoster/cloudflare.py "$URL/$PAGE"
					$ACTIVEBIN "$URL/$PAGE" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN5 /tmp/localhoster/cloudflare.py "$URL/$ROUND"
					$ACTIVEBIN "$URL/$filepath" > $TMP/cache."$filename".list
				fi
				if [ $(cat $TMP/cache."$filename".list | wc -l) -eq 0 ];then
#					echo $BIN6 /tmp/localhoster/cloudflare.py "$URL/$PAGE"
					$ACTIVEBIN "$URL/$PAGE" > $TMP/cache."$filename".list
				fi
				PIC=$URL/`cat $TMP/cache."$filename".list | tr '><' '>\n<' | grep $picname | cut -d '"' -f2 | sort -um`
				LANG=`cat $TMP/cache."$filename".list | grep 'alt="language" src="/gr/sys/lng' | sed 's!alt="language" src="/gr/sys/lng/!\n!' | tail -n1 |cut -d"." -f1`
#			else
#				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
#				LANG=1
			fi

            LANGTXT=$(getlangtext $LANG)

			if [ ! -z "$IMDB" ];then
				IMDBTXT=" ($IMDB)"
			fi
			if [ ! -z "$YEAR" ];then
				YEARTXT=" ($YEAR)"
			fi

			NEWPAGE="$URL$PAGE"

			if [ -z "$PIC" ]; then
				PIC="http://openaaf.dyndns.tv/mediathek/menu/default.jpg"
			fi

#			TITLE=`echo $TITLE | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/\E4/g' -e 's/&uuml;/\FC/g' -e 's/&ouml;/\F6/g' -e 's/&eacute;/\E9/g' -e 's/&egrave;/\E8/g' -e 's/%F6/\F6/g' -e 's/%FC/\FC/g' -e 's/%E4/\E4/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`
			TITLE=`echo $TITLE | sed -e 's/u2013/-/g' | sed -e 's/u00f4/ô/g' | sed -e 's/u00e9/é/g' | sed -e 's/u00e8/è/g' | sed -e 's/u00c4/Ä/g' | sed -e 's/u00dc/Ü/g' | sed -e 's/u00f6/ö/g' | sed -e 's/u00e4/ä/g' | sed -e 's/u00fc/ü/g' | sed -e 's/u00df/ß/g' | sed -e 's/&#038;/&/g' -e 's/&amp;/und/g' -e 's/&quot;/"/g' -e 's/&lt;/\</g' -e 's/&#034;/\"/g' -e 's/&#039;/\"/g' -e 's/#034;/\"/g' -e 's/#039;/\"/g' -e 's/&szlig;/\C3x/g' -e 's/&ndash;/-/g' -e 's/&Auml;/\C3/g' -e 's/&Uuml;/\C3S/g' -e 's/&Ouml;/\C3/g' -e 's/&auml;/\E4/g' -e 's/&uuml;/\FC/g' -e 's/&ouml;/\F6/g' -e 's/&eacute;/\E9/g' -e 's/&egrave;/\E8/g' -e 's/%F6/\F6/g' -e 's/%FC/\FC/g' -e 's/%E4/\E4/g' -e 's/%26/&/g' -e 's/%C4/\C3/g' -e 's/%D6/\C3/g' -e 's/%DC/\C3S/g' -e 's/%28/(/g' -e 's/%29/)/g' -e 's/%3A/:/g' -e 's/%40/@/g' -e 's/%2B/&/g' -e 's/%C3/A/g' -e 's/%B1/&/g' -e 's/%5B//g' -e 's/%5D//g' -e 's!%2F!/!g' -e 's/|/ /g' -e 's/(/ /g' -e 's/)/ /g' -e 's/+/ /g' -e 's/\//-/g' -e 's/,/ /g' -e 's/;/ /g' -e 's/:/ /g' -e 's/\.\+/./g'`

			if [ ! -z "$TITLE" ] && [ ! -z "$NEWPAGE" ];then
				if [ ! -e $TMP/$FILENAME.list ];then
					touch $TMP/$FILENAME.list
				fi

                #<div class="Descriptore">John Rambo ist in einem Provinznest auf der Suche nach einem Kriegskameraden, mit dem er in Vietnam in einer Spezialeinheit gewesen war. Aber sein Freund ist bereits gestorben. Die Polizei hält den hochdekorierten Vietnam-Veteranen Rambo für einen Landstreicher und nimmt ihn fest. Polizeichef Teasle, der ihn auf der Wache quält und demütigt, ahnt nicht, dass er damit eine Lawine ins Rollen bringt: Rambos Instinkte werden wach. In einer atemberaubenden Aktion flieht er in die Berge. Teasle hetzt ihm den gesamten Polizeistab hinterher, doch Rambo ist ganz in seinem Element und lässt den Beamten keine Chance.<br /> <br /> <a href="">Jetzt herunterladen!</a>
                #</div>
                desc="$ACTIVEBIN --connect-timeout 5 $NEWPAGE | sed -nr 's/.*<div class=\"Descriptore\">([^>]+)<.*/\1/p'"

                #<div class="Grahpics"><a href="/Stream/Rambo_First_Blood.html"><img src="/statics/thumbs/00002000/Rambo_First_Blood.jpg" alt="Rambo: First Blood" /></a></div>
                PIC="echo $URL | tr -d '\n' && $ACTIVEBIN --connect-timeout 5 $NEWPAGE | sed -nr 's/.*<div class=\"Grahpics\"><a href=\".*img src=\"([^\"]+)\".*/\1/p' | tr -d '\n'"

				piccount=`expr $piccount + 1`
#				LINE="$TITLE$LANGTXT$YEARTXT$IMDBTXT#$NEWPAGE#$PIC#kinox_$piccount.jpg#KinoX#22"
				LINE="$TITLE$LANGTXT$YEARTXT$IMDBTXT#$NEWPAGE#$PIC#$FILENAME"_"$piccount"_"$filename.jpg#KinoX#22#$desc"

				if [ `cat $TMP/$FILENAME.list | grep "$TITLE" | wc -l` -eq 0 ];then
					echo "$LINE" >> $TMP/$FILENAME.list
				fi
			fi
		done 3<$TMP/cache.$FILENAME.2
		rm $TMP/cache.$FILENAME.* > /dev/null 2>&1

	fi
	echo "$TMP/$FILENAME.list"
}

case $INPUT in
	init) $INPUT;;
	mainmenu) $INPUT;;
	search) $INPUT;;
	kino) $INPUT;;
	latest) $INPUT;;
	sorted) $INPUT;;
	cast) $INPUT;;
	genre) $INPUT;;
esac
