summaryrefslogtreecommitdiff
path: root/getresources.pl
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2015-09-10 23:01:37 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2015-09-10 23:05:09 +0200
commit90a1fb391c29c1165baab5021a167d42e841534a (patch)
treebd3512a16ca1cd829f0468e32dea1f837b6f3a67 /getresources.pl
downloadhearthstone-90a1fb391c29c1165baab5021a167d42e841534a.tar.gz
hearthstone-90a1fb391c29c1165baab5021a167d42e841534a.tar.bz2
hearthstone-90a1fb391c29c1165baab5021a167d42e841534a.zip
initial commit.
Diffstat (limited to 'getresources.pl')
-rwxr-xr-xgetresources.pl166
1 files changed, 166 insertions, 0 deletions
diff --git a/getresources.pl b/getresources.pl
new file mode 100755
index 0000000..87ee7b6
--- /dev/null
+++ b/getresources.pl
@@ -0,0 +1,166 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+package getimg;
+
+my ($htmldir, $imagedir, $sounddir, $lower, $upper) = @ARGV;
+
+if(!($htmldir && $imagedir && $sounddir && $lower && $upper)) {
+ print "Usage $0 html-dir image-dir sound-dir lower-bound upper-bound\n";
+ #die;
+}
+
+if(! -d $htmldir) {
+ mkdir $htmldir or die "could not create ${htmldir}\n";
+}
+
+if(! -d $imagedir) {
+ mkdir $imagedir or die "could not create ${imagedir}\n";
+}
+
+if(! -d $sounddir) {
+ mkdir $imagedir or die "could not create ${imagedir}\n";
+}
+
+sub rand_range {
+ my ($x, $y) = @_;
+ return int(rand($y - $x)) + $x;
+}
+
+my %imagehash;
+
+for(my $i = $lower; $i <= $upper; $i++) {
+
+ our $rand_value = rand_range(0, 5);
+ print "going to sleep for $rand_value seconds\n";
+ #sleep($rand_value);
+ print "slept\n";
+
+ our $htmlfile = "${htmldir}/${i}.html";
+
+ my $useragent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17";
+ my $cmd = "curl -A \"$useragent\" \"http://www.hearthhead.com/card=$i\" > \"$htmlfile\"";
+
+ if (! -e $htmlfile) {
+ system($cmd);
+ } else {
+ print "using cached html file: \"${htmlfile}\"\n"
+ }
+
+ my $document = do {
+ local $/ = undef;
+ open my $fh, "<", $htmlfile
+ or die "could not open $htmlfile: ${!}\n";
+ <$fh>;
+ };
+
+ my $name = undef;
+ my $normalimagefile = undef;
+ my $premiumimagefile = undef;
+ my $sound1file = undef;
+ my $sound2file = undef;
+ my $sound3file = undef;
+
+ if ($document =~ /_\[${i}\]={name_enus:'(.+?)',icon:'/) {
+ $name = $1;
+ $name =~ s/\\(.)/$1/g;
+ $name =~ s/"/\\"/g;
+ print "Name: " . $name . "\n";
+ } else {
+ print "No name found\n";
+ next;
+ }
+
+ if ( ! exists $imagehash{$name} ) {
+ $normalimagefile = "${imagedir}/${name}.png";
+ $premiumimagefile = "${imagedir}/${name}_premium.gif";
+ $sound1file = "${sounddir}/${name}_battlecry.ogg";
+ $sound2file = "${sounddir}/${name}_attack.ogg";
+ $sound3file = "${sounddir}/${name}_death.ogg";
+ $imagehash{$name} = 1;
+ } else {
+ print $imagehash{$name};
+ $normalimagefile = "${imagedir}/${name}_" . $imagehash{$name} . ".png";
+ $premiumimagefile = "${imagedir}/${name}_" . $imagehash{$name} . "_premium.gif";
+ $sound1file = "${sounddir}/${name}_" . $imagehash{$name} . "_battlecry.ogg";
+ $sound2file = "${sounddir}/${name}_" . $imagehash{$name} . "_attack.ogg";
+ $sound3file = "${sounddir}/${name}_" . $imagehash{$name} . "_death.ogg";
+ $imagehash{$name}++;
+ }
+
+
+ my $get_normal_cmd = undef;
+ my $get_premium_cmd = undef;
+ my $get_sound1file_cmd = undef;
+ my $get_sound2file_cmd = undef;
+ my $get_sound3file_cmd = undef;
+
+
+ if ($document =~ /_\[${i}\]\.tooltip_enus = '<img src="(.+?)"/) {
+ $get_normal_cmd = "curl -A \"$useragent\" \"$1\" > \"${normalimagefile}\"";
+ print "Normal: " . $1 . "\n";
+ } else {
+ print "Could not find normal version of ${name}\n";
+ }
+
+ if ($document =~ /_\[${i}\]\.tooltip_premium_enus = '<img src="(.+?)"/) {
+ $get_premium_cmd = "curl -A \"$useragent\" \"$1\" > \"${premiumimagefile}\"";
+ print "Premium: $1 \n";
+ } else {
+ print "Could not find premium version of ${name}\n";
+ }
+
+ if ($document =~ /<audio id="cardsound0"><source src="(.+?)"/) {
+ $get_sound1file_cmd = "curl -A \"$useragent\" \"$1\" > \"${sound1file}\"";
+ print "BattleCry: $1 \n";
+ } else {
+ print "Could not find the BattleCry sound of ${name}\n";
+ }
+
+ if ($document =~ /<audio id="cardsound1"><source src="(.+?)"/) {
+ $get_sound2file_cmd = "curl -A \"$useragent\" \"$1\" > \"${sound2file}\"";
+ print "Attack: $1 \n";
+ } else {
+ print "Could not find the Attack sound of ${name}\n";
+ }
+
+ if ($document =~ /<audio id="cardsound2"><source src="(.+?)"/) {
+ $get_sound3file_cmd = "curl -A \"$useragent\" \"$1\" > \"${sound3file}\"";
+ print "Death: $1 \n";
+ } else {
+ print "Could not find the Death sound of ${name}\n";
+ }
+
+ if (! -e $normalimagefile) {
+ system($get_normal_cmd);
+ } else {
+ print "normal $name already downloaded\n";
+ }
+
+ if (! -e $premiumimagefile) {
+ system($get_premium_cmd);
+ } else {
+ print "premium $name already downloaded\n";
+ }
+
+ if (! -e $sound1file) {
+ system($get_sound1file_cmd);
+ } else {
+ print "Battlecry $name already downloaded\n";
+ }
+
+ if (! -e $sound2file) {
+ system($get_sound2file_cmd);
+ } else {
+ print "Attack $name already downloaded\n";
+ }
+
+ if (! -e $sound3file) {
+ system($get_sound3file_cmd);
+ } else {
+ print "Death $name already downloaded\n";
+ }
+}
+
+