Code 285 : LoL splash

Posté le , conservation toujours, coloration syntaxique : Perl, télécharger.

1
23
45
67
89
1011
1213
1415
1617
1819
2021
2223
2425
2627
2829
3031
3233
3435
3637
3839
4041
4243
4445
4647
4849
5051
5253
5455
5657
5859
6061
6263
6465
6667
6869
7071
use strict;
use warnings; 
use Data::Dumper; # For debugging 
use File::Path;use List::MoreUtils qw(uniq);
use LWP::Simple;use Sort::Naturally;
 $| = 1; # Autoflush
 # Configuration.
my $pref = "http://l3cdn.riotgames.com/releases/live";my $manifesturl = "/projects/lol_air_client/releases/%s/packages/files/packagemanifest";
 my $latest = "0.0.1.21";
my $path = "./img";my $path_min = "./thumb";
 # Get version list.
my $url = $pref . sprintf($manifesturl, $latest);my $manifest = get($url);
 my @versions = nsort uniq($manifest =~ m@releases/([.\d]+)/@g);
printf "%d versions found\n", scalar @versions; 
# We'll store each splash in this hash, with the associated URL.my %skins;
 # For each version, we fetch the associated package manifest file and parse it to find all possible spashes.
foreach my $version (@versions) {    my $url = $pref . sprintf($manifesturl, $version);
    printf "Fetching package manifest file for version %s... ", $version;    my $manifest = get($url);
    if (defined($manifest)) {        print "OK.\n";
        while ($manifest =~ m@(/projects/lol_air_client/releases/([.\d]+)/files/assets/images/champions/(.+)_Splash_(\d+).jpg)@gi) {            my ($url, $version, $name, $n) = ($1, $2, ucfirst $3, $4);
            $skins{$name}{$n}{$version} = $url;        }
    } else {        print "Fail.\n";
    }}
 # We iterate on the hash and download every image.
while (my ($name, $hash) = each(%skins)) {    mkpath sprintf "%s/%s", $path, $name;
    mkpath sprintf "%s/%s", $path_min, $name;    while (my ($n, $hash) = each(%$hash)) {
        while (my ($version, $url) = each(%$hash)) {            printf "Downloading %s's splash images... %s#%d      \r", $name, $version, $n;
                        {
                my $out = sprintf "%s/%s/%s_%s_%s.jpg", $path, $name, $name, $n, $version;                my $r = mirror $pref . $url, $out;
                printf "\nError! HTTP status = %d\n", $r if is_error($r);            }
                        {
                $url =~ s/splash_//i;                my $out = sprintf "%s/%s/%s_%s_%s_min.jpg", $path_min, $name, $name, $n, $version;
                my $r = mirror $pref . $url, $out;                printf "\nError! HTTP status = %d\n", $r if is_error($r);
            }        }
    }    printf "Downloading %s's splash images... OK.                       \n", $name;
} 

Durée de conservation :