Code 287 : LoL splash v3

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
7273
7475
7677
7879
8081
8283
8485
8687
8889
9091
9293
9495
9697
9899
100101
102103
104105
106107
108109
110111
112113
114115
116117
118119
120121
122123
124125
126127
128129
130131
132133
134135
136137
use strict;
use warnings; 
use Data::Dumper; # For debugging 
use File::Path;use File::Slurp;
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 $releaselisturl = "/projects/lol_air_client/releases/releaselisting"; 
my $path = "./img";my $path_min = "./thumb";
my $path_login = "./login";my $path_manifest = "./manifest";
 # Get version list.
my $url = $pref . $releaselisturl;my $releaselist = get($url);
 my @versions = nsort split /\r?\n/, $releaselist;
 printf "%d versions found\n", scalar @versions;
 # We'll store each splash in this hash, with the associated URL.
my %skins;my %logins;
my %loginmusic; 
# For each version, we fetch the associated package manifest file and parse it to find all possible spashes.mkpath $path_manifest;
foreach my $version (@versions) {    my $url = $pref . sprintf($manifesturl, $version);
    printf "Fetching package manifest file for version %s... ", $version;    my $out = sprintf("%s/manifest_%s", $path_manifest, $version);
        my $r = mirror($url, $out);
    if (is_success($r) || $r == 304) {        print "OK.\n";
        my @manifest = read_file($out);        @manifest = grep m@/images/champions/|swfs|ambient@, @manifest;
        my $manifest = join '\n', @manifest;        while ($manifest =~ m@(/projects/lol_air_client/releases/([.\d]+)/files/assets/images/champions/(\w+)_Splash_(\d+)\.jpg)@gi) {
            my ($url, $version, $name, $n) = ($1, $2, ucfirst $3, $4);            $name =~ s/Masteryi/MasterYi/; # Avoid duplicate.
            $skins{$name}{$n}{$version}{'splash'} = $url;            if ($manifest =~ m@(/projects/lol_air_client/releases/([.\d]+)/files/assets/images/champions/${name}_${n}\.jpg)@i) {
                my ($url_min, $version_min) = ($1, $2);                $skins{$name}{$n}{$version}{'min'} = $url_min;
            }        }
        if ($manifest =~ m@(/projects/lol_air_client/releases/([.\d]+)/files/assets/swfs/login\.swf)@i) {            my ($url, $version) = ($1, $2);
            $logins{$version} = $url;            if ($manifest =~ m@(/projects/lol_air_client/releases/([.\d]+)/files/assets/sounds/ambient/.+(?:nose|intro)\.mp3)@i) {
                my ($url_intro, $version_intro) = ($1, $2);                $loginmusic{$version}{'intro'} = $url_intro;
                if ($manifest =~ m@(/projects/lol_air_client/releases/([.\d]+)/files/assets/sounds/ambient/.+loop\.mp3)@i) {                    my ($url_loop, $version_loop) = ($1, $2);
                    $loginmusic{$version}{'loop'} = $url_loop;                }
            } else {                printf "No login music for version %s.\n", $version;
            }        }
    } else {        print "Fail.\n";
    }}
 # We iterate on the hash and download every image.
mkpath $path_login;while (my ($version, $url) = each(%logins)) {
    {        printf "Downloading login screen version %s... ", $version;
        my $out = sprintf "%s/login_%s.swf", $path_login, $version;        my $r = mirror $pref . $url, $out;
        if (is_error($r)) {            printf "\nError! HTTP status = %d for URL %s\n", $r, $url;
        } else {            print "OK.\n"
        }    }
        if (defined($loginmusic{$version})) {
        my $url = $loginmusic{$version}{'intro'};        printf "Downloading login screen music version %s [intro]... ", $version;
        my $out = sprintf "%s/login_music_%s_intro.mp3", $path_login, $version;        my $r = mirror $pref . $url, $out;
        if (is_error($r)) {            printf "\nError! HTTP status = %d for URL %s\n", $r, $url;
        } else {            print "OK.\n"
        }        if (defined($loginmusic{$version}{'loop'})) {
            my $url = $loginmusic{$version}{'loop'};            printf "Downloading login screen music version %s [loop]... ", $version;
            my $out = sprintf "%s/login_music_%s_loop.mp3", $path_login, $version;            my $r = mirror $pref . $url, $out;
            if (is_error($r)) {                printf "\nError! HTTP status = %d for URL %s\n", $r, $url;
            } else {                print "OK.\n"
            }        }
    }}
 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{'splash'}, $out;                printf "\nError! HTTP status = %d for URL %s\n", $r, $$url{'splash'} if is_error($r);
            }            
            if (defined($$url{'min'})) {                my $out = sprintf "%s/%s/%s_%s_%s_min.jpg", $path_min, $name, $name, $n, $version;
                my $r = mirror $pref . $$url{'min'}, $out;                printf "\nError! HTTP status = %d for URL %s\n", $r, $$url{'min'} if is_error($r);
            }        }
    }    printf "Downloading %s's splash images... OK.                       \n", $name;
} 

Durée de conservation :