#!/usr/bin/tclsh

puts "================================================"
puts "This program is for educational purposes only. Using it to gather keys for illegally watching TV channels is STRICTLY prohibited. If you intend to do so, please don't use it. It's prohibited for you.."
puts "================================================"
puts "Read the license.txt file for the license."
puts "Program made by satcat. Have fun with it ! :)"
puts ""

set DIR [clock format [clock seconds] -format "%d-%m-%Y"]
file delete -force "$DIR-old"
catch {file rename $DIR "$DIR-old"}
file mkdir $DIR 
cd $DIR

package require http

# Get from www.rdi-sat.com
puts "Getting from www.rdi-sat.com"
set S [list seca nagra viaccess]
foreach sys $S {
	set token [http::geturl "http://www.rdi-sat.com/$sys.php"]
	http::wait $token
	set fid [open rdi-sat.com.$sys w]
	puts -nonewline $fid [http::data $token]
	close $fid
}


puts "Getting from http://www.cardmanie-original.cz/key/softCam.Key"
set token [http::geturl "http://www.cardmanie-original.cz/key/softCam.Key"]
http::wait $token
set fid [open "SoftCam-cardmanie.Key" w]
puts -nonewline $fid [http::data $token]
close $fid

catch {
puts "Getting from http://xamuh.modshack.co.uk/files/SoftCam.Key"
set token [http::geturl "http://xamuh.modshack.co.uk/files/SoftCam.Key"]
http::wait $token
set fid [open "SoftCam-xamuh.Key" w]
puts -nonewline $fid [http::data $token]
close $fid
} var
if {$var != ""} {
	puts "Could not get keys from xamuh.modshack.co.uk."
	puts "\tERROR: $var"
}

global outputFile
set outputFile "../SoftCam.Key"

source ../parseall.tcl 

puts "Generated 'SoftCam.Key' file in the current directory."
puts "Press ENTER to finish..."
gets stdin
exit

# Get from http://www.pablosat.hpg.ig.com.br/keys/keydice.zip
#puts "Getting from http://www.pablosat.hpg.ig.com.br/keys/*.zip"
#wget -i ../urls-pablosat -o log-pablosat -t 200 -c 
#unzip -o -u "*.zip" 2>/dev/null

# Get from http://softcam.tforums.com
#puts "Getting from http://softcam.tforums.com"
#../get-tforums.tcl

# Get from http://www.sat-key.com/sat-key/
puts "Getting from http://www.sat-key.com/"
#wget -i ../urls-sat-key -o log-sat-key -t 200 -c
lynx -hiddenlinks=ignore -nolist -dump http://users.pcnet.ro/predut/irdeto/irdetopmk.htm > sat-key.com.irdetopmk
lynx -hiddenlinks=ignore -nolist -dump http://users.pcnet.ro/predut/irdetoopkeys.htm > sat-key.com.irdetoopkeys
lynx -hiddenlinks=ignore -nolist -dump http://users.pcnet.ro/predut/viaccesskeys.htm > sat-key.com.viaccesskeys
lynx -hiddenlinks=ignore -nolist -dump http://users.pcnet.ro/predut/secakeys.htm > sat-key.com.secakeys
lynx -hiddenlinks=ignore -nolist -dump http://users.pcnet.ro/predut/nagrakeys.htm > sat-key.com.nagrakeys
lynx -hiddenlinks=ignore -nolist -dump http://users.pcnet.ro/predut/d2mackeys.htm > sat-key.com.d2mackeys

# Get from http://starr-inc.host.sk/cl%E9encourPPVencour/derniereclef.htm
#puts "Getting from http://starr-inc.host.sk/cl%E9encourPPVencour/derniereclef.htm"
#wget -i ../urls-starr-inc.host.sk -o log-starr-inc.host.sk -t 200 -c

#puts "Getting from www.sattech.ca"
#wget -i ../urls-www.sattech.ca -o log-www.sattech.ca -t 200 -c

#puts "Getting from stopstop.info"
#wget -i ../urls-stopstop.info -o log-stopstop.info -t 200 -c
#mv keys.html stopstop-keys.html

# Tonydoe takes it from Cardmanie
#puts "Getting from http://www.tonydoe.com/softcam.zip"
#wget http://www.tonydoe.com/softcam.zip -t 2 -c -o log-tonydoe
#unzip -a softcam.zip
#mv SoftCam.Key SoftCam-tonydoe.Key 



puts "Getting from www.hot.ee"
wget -i ../urls-www.hot.ee -o log-www.hot.ee -c -O hot.ee-keys.html

cd ..

./parseall 1> $DIR/SoftCam.Key 2>$DIR/SoftCam.Key.err
puts >> $DIR/SoftCam.Key
puts >> $DIR/SoftCam.Key
puts >> $DIR/SoftCam.Key
puts ";==========================================================================" >> $DIR/SoftCam.Key
puts ";===                    ERRORS" >> $DIR/SoftCam.Key
puts ";==========================================================================" >> $DIR/SoftCam.Key

cat $DIR/SoftCam.Key.err >> $DIR/SoftCam.Key
rm -f $DIR/SoftCam.Key.err
cp $DIR/SoftCam.Key .

puts "SoftCam.Key file generated in current directory."