From b9a4e9c8a68dcb6b17617f4f7a5ad5ad3298bfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 9 Mar 2016 22:05:38 +0100 Subject: Imported Upstream version 1.7.1 --- lib/gcstar/GCPlugins/GCgames/GCJeuxVideoCom.pm | 512 ++++++++++++++----------- 1 file changed, 285 insertions(+), 227 deletions(-) (limited to 'lib/gcstar/GCPlugins/GCgames/GCJeuxVideoCom.pm') diff --git a/lib/gcstar/GCPlugins/GCgames/GCJeuxVideoCom.pm b/lib/gcstar/GCPlugins/GCgames/GCJeuxVideoCom.pm index 560a582..52d0e59 100644 --- a/lib/gcstar/GCPlugins/GCgames/GCJeuxVideoCom.pm +++ b/lib/gcstar/GCPlugins/GCgames/GCJeuxVideoCom.pm @@ -2,7 +2,7 @@ package GCPlugins::GCgames::GCJeuxVideoCom; ################################################### # -# Copyright 2005-2010 Tian +# Copyright 2005-2016 Tian # # This file is part of GCstar. # @@ -32,57 +32,159 @@ use GCPlugins::GCgames::GCgamesCommon; use base 'GCPlugins::GCgames::GCgamesPluginsBase'; + sub decryptUrl + { + my ($self, $src) = @_; + my $n = '0A12B34C56D78E9F'; + my $res = 'http://www.jeuxvideo.com'; + my $s = reverse $src; + my ($c, $l); + while (length $s) + { + $l = index $n, chop $s; + $c = index $n, chop $s; + my $car = $l * 16 + $c; + $res .= chr $car; + } + return $res; + } + + sub getPlatformName + { + my ($self, $platform) = @_; + $platform =~ s/^360$/Xbox 360/; + $platform =~ s/^32X$/Mega Drive 32X/; + $platform =~ s/^3DS$/Nintendo 3DS/; + $platform =~ s/^C64$/Commodore 64/; + $platform =~ s/^CPC$/Amstrad CPC/; + $platform =~ s/^DCAST$/Dreamcast/; + $platform =~ s/^DS$/Nintendo DS/; + $platform =~ s/^G.GEAR$/Game Gear/; + $platform =~ s/^GB$/Game Boy/; + $platform =~ s/^GBA$/Game Boy Advance/; + $platform =~ s/^Giz$/Gizmondo/; + $platform =~ s/^MD$/Mega Drive/; + $platform =~ s/^MS$/Master System/; + $platform =~ s/^N64$/Nintendo 64/; + $platform =~ s/^NEO$/Neo Geo/; + $platform =~ s/^New 3DS$/New Nintendo 3DS/; + $platform =~ s/^NGAGE$/N-Gage/; + $platform =~ s/^NGC$/Gamecube/; + $platform =~ s/^ONE$/Xbox One/; + $platform =~ s/^PC ENG$/PC Engine/; + $platform =~ s/^PS1$/PlayStation/; + $platform =~ s/^PS2$/PlayStation 2/; + $platform =~ s/^PS3$/PlayStation 3/; + $platform =~ s/^PS4$/PlayStation 4/; + $platform =~ s/^SNES$/Super Nintendo/; + $platform =~ s/^ST$/Atari ST/; + $platform =~ s/^V.BOY$/Virtual Boy/; + $platform =~ s/^Vita$/PS Vita/; + $platform =~ s/^WiiU$/Wii U/; + return $platform; + } + + sub loadMultipleResults + { + my ($self, $url) = @_; + my $page = $self->loadPage($url); $page =~ /(.*?)<\/div>/s; + my $tabs = $1; + $page =~ /Sortie\s+France\s+:\s+<\/strong>(.*)/i; + my $released = $1; + $page =~ /(.*?)<\/h1>/i; + my $name = $1; + $name =~ s/'/'/g; + $name =~ s/&/&/g; + my @lines = split /\n/, $tabs; + foreach my $line (@lines) + { + if ($line =~ /href="([^"]*)".*?>([0-9a-zA-Z_. -]*)<\/a>/) + { + my $url = $1; + my $platform = $self->getPlatformName($2); + $self->{itemIdx}++; + $self->{itemsList}[$self->{itemIdx}]->{url} = 'http://www.jeuxvideo.com'.$url; + $self->{itemsList}[$self->{itemIdx}]->{name} = $name; + $self->{itemsList}[$self->{itemIdx}]->{platform} = $platform; + $self->{itemsList}[$self->{itemIdx}]->{released} = $released; + } + elsif ($line =~ /([0-9a-zA-Z_. -]*)<\/span>/) + { + # for some reason, it ends with a / but it's not a multi-platform game + $self->{itemIdx}++; + $name =~ s/ sur $1$//e; + $self->{itemsList}[$self->{itemIdx}]->{url} = $url; + $self->{itemsList}[$self->{itemIdx}]->{name} = $name; + $self->{itemsList}[$self->{itemIdx}]->{platform} = $self->getPlatformName($1); + $self->{itemsList}[$self->{itemIdx}]->{released} = $released; + } + } + } + sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; $self->{inside}->{$tagname}++; - return if $self->{parsingEnded}; if ($self->{parsingList}) { - if (($tagname eq 'div') && (($attr->{id} eq 'new_mc') || ($attr->{id} eq 'old_mc'))) + if ($tagname eq 'span') { - $self->{inResults} = 1; - } - elsif ($self->{inResults}) - { - if ($tagname eq 'img') + if (($attr->{class} =~ /JvCare\s+([0-9A-F]*)\s+lien-jv/) && ($attr->{title} ne "")) { - $self->{currentPlatform} = $attr->{alt}; + my $url = $self->decryptUrl($1); + if (! exists $self->{urls}->{$url}) + { + if ($url =~ /\/$/) + { + #If it ends with a /, it means it's a multi-platform game, and the link points to a common page + $self->loadMultipleResults($url); + $self->{urls}->{$url} = 1; + } + else + { + $self->{itemIdx}++; + $self->{itemsList}[$self->{itemIdx}]->{url} = $url; + $self->{isGame} = 1; + # Note : some game's name contains '-' => not use $attr->{title} + $self->{isName} = 1; + + my @array = split(/-/,$attr->{title}); + if (scalar(@array) ge 3 ) + { + if (!($array[$#array] =~ /date/i)) + { + $self->{itemsList}[$self->{itemIdx}]->{released} = $array[$#array]; + } + } + + $self->{urls}->{$url} = 1; + } + } } - elsif (($tagname eq 'a') && ($attr->{href} =~ /^http/)) + return if !$self->{isGame}; + if ($attr->{class} =~ /recherche-aphabetique-item-machine/) { - $self->{itemIdx}++; - $self->{itemsList}[$self->{itemIdx}]->{url} = $attr->{href}; - $self->{itemsList}[$self->{itemIdx}]->{platform} = $self->{currentPlatform}; - $self->{isGame} = 1; + $self->{isPlatform} = 1; } } } elsif ($self->{parsingTips}) { - if ($tagname eq 'tpfdebuttpf') + if ($attr->{class} eq 'rubrique-asl') { $self->{isTip} = 1; } - elsif ( ($tagname eq 'h3') && ($attr->{class} eq 'titre_bloc') && ($self->{isTip} ne 4)) - { - $self->{isTip} = 2; - } - elsif ( (($tagname eq 'h3') || ($tagname eq 'h4') || ($tagname eq 'h5') ) && ($self->{isTip} ne 3) && ($self->{isTip} ne 4)) - { - $self->{isTip} = 2; - } - elsif ( ($tagname eq 'p') && ($self->{isTip} ne 3) && ($self->{isTip} ne 4)) + elsif (($tagname eq 'tpfdebuttpf') && ($self->{isTip} eq 2)) { - $self->{isTip} = 1; + $self->{isTip} = 3; } - elsif ($tagname eq 'tpfstopsolution') + elsif ( (($tagname eq 'p') || ($tagname eq 'h2') || ($tagname eq 'h3')) && (($self->{isTip} eq 3) || ($self->{isTip} eq 4)) ) { - $self->{isTip} = 4; + $self->{curInfo}->{secrets} .= "\n" if $self->{curInfo}->{secrets}; } - elsif ($tagname eq 'tpffintpf') + elsif (($tagname eq 'tpffintpf') && ($self->{isTip} ne 0)) { - $self->{isTip} = 3; + $self->{isTip} = 2; } elsif ($tagname eq 'head') { @@ -93,71 +195,78 @@ use GCPlugins::GCgames::GCgamesCommon; } else { - if (($tagname eq 'meta') && ($attr->{property} eq 'og:image')) + if ($tagname eq 'span') { - my $cover = $attr->{content}; - $cover =~ s|(http://[^/]*)/([^i])|$1/images/$2|; - if ($self->{bigPics}) + if ($attr->{class} =~ 'label-support active') { - $cover =~ s/-p(-|\.)/-g$1/; - $cover =~ s/t(\.jpg)/$1/; + $self->{is} = 'platform'; } - my $back = $cover; - if (!($back =~ s/-avant(-|\.)/-arriere$1/)) + elsif ($attr->{itemprop} eq 'description') { - $back =~ s/f(t?\.jpg)/r$1/; + $self->{is} = 'description'; } - $self->{curInfo}->{boxpic} = $cover; - $self->{curInfo}->{backpic} = $back; - } - elsif (($tagname eq 'li') && ($attr->{class} eq 'note_redac')) - { - $self->{is} = 'ratingpress'; - } - elsif ( ($tagname eq 'div') && ($attr->{class} eq 'series_images') ) - { - $self->{inScreenshots} = 1; - } - elsif ( ($tagname eq 'img') && ($self->{inScreenshots}) ) - { - if (! $self->{curInfo}->{screenshot1}) + elsif ($attr->{itemprop} eq 'genre') + { + $self->{is} = 'genre'; + } + elsif ($attr->{class} eq 'recto-jaquette actif') { - $self->{curInfo}->{screenshot1} = $attr->{src}; - $self->{curInfo}->{screenshot1} =~ s/.gif/.jpg/; - $self->{curInfo}->{screenshot1} =~ s/_m\.jpg/\.jpg/; + $self->{is} = 'boxpic'; } - elsif (! $self->{curInfo}->{screenshot2}) + elsif ($attr->{class} eq 'verso-jaquette actif') { - $self->{curInfo}->{screenshot2} = $attr->{src}; - $self->{curInfo}->{screenshot2} =~ s/.gif/.jpg/; - $self->{curInfo}->{screenshot2} =~ s/_m\.jpg/\.jpg/; - $self->{isScreen} = 0; + $self->{is} = 'backpic'; + } + elsif (($attr->{'data-modal'} eq 'image') && $self->{is}) + { + $self->{curInfo}->{$self->{is}} = 'http:'.$attr->{'data-selector'}; + $self->{is} = ''; } } - elsif (($attr->{href} =~ m^/(etajvhtm|cheats)/^) && ! ($self->{urlTips})) + elsif ($tagname eq 'div') { - $self->{urlTips} = $attr->{href}; + if ($attr->{class} eq 'game-top-title') + { + $self->{is} = 'name'; + } + elsif ($attr->{class} eq 'bloc-note-redac') + { + $self->{is} = 'ratingpress'; + } + elsif ($attr->{class} eq 'bloc-img-fiche') + { + $self->{is} = 'screenshot1'; + } + elsif ($attr->{class} eq 'bloc-all-support') + { + $self->{curInfo}->{exclusive} = 0; + } } - elsif (($attr->{href} =~ m/test.htm/) && ! ($self->{curInfo}->{players})) + elsif ($tagname eq 'img') { - my $html = $self->loadPage($attr->{href}); - - my $found = index($html,"
  • Multijoueurs :"); - if ( $found >= 0 ) + if ($self->{is} =~ /screenshot/) { - $html = substr($html, $found +length('
  • Multijoueurs :'),length($html)- $found -length('
  • Multijoueurs :')); - $self->{curInfo}->{players} = substr($html, 0, index($html, "<")); - - # Enleve les blancs en debut de chaine - $self->{curInfo}->{players} =~ s/^\s+//; - # Enleve les blancs en fin de chaine - $self->{curInfo}->{players} =~ s/\s+$//; - - $self->{curInfo}->{players} =~ s/-/1/; - $self->{curInfo}->{players} =~ s/non/1/i; - $self->{curInfo}->{players} =~ s/oui/Multijoueurs/i; + (my $src = 'http:'.$attr->{'data-srcset'}) =~ s/medias-sm/medias/; + $self->{curInfo}->{$self->{is}} = $src; + if ($self->{is} eq 'screenshot1') + { + $self->{is} = 'screenshot2'; + } + else + { + $self->{is} = ''; + } } } + elsif (($tagname eq 'h2') && ($attr->{class} =~ /titre-bloc/)) + { + $self->{isTip} = 1; + } + elsif (($self->{isTip} eq 2) && ($attr->{href} =~ /wiki/i)) + { + $self->{urlTips} = "http://www.jeuxvideo.com/" . $attr->{href}; + $self->{isTip} = 0; + } } } @@ -166,27 +275,33 @@ use GCPlugins::GCgames::GCgamesCommon; my ($self, $tagname) = @_; $self->{inside}->{$tagname}--; - return if $self->{parsingEnded}; - if ($self->{parsingList}) - { - if ($tagname eq 'div') - { - $self->{inResults} = 0; - } - } } sub text { my ($self, $origtext) = @_; - return if $self->{parsingEnded}; if ($self->{parsingList}) { - if ($self->{isGame}) + return if !$self->{isGame}; + if ($self->{isPlatform}) { + if ($self->{itemsList}[$self->{itemIdx}]->{platform} eq "" ) + { + # Enleve le " - " présent en début de chaîne + $origtext =~ s/- //; + $self->{itemsList}[$self->{itemIdx}]->{platform} = $self->getPlatformName($origtext); + } + $self->{isPlatform} = 0; + } + elsif ($self->{isName}) + { + # Enleve les blancs en debut de chaine + $origtext =~ s/^\s+//; + # Enleve les blancs en fin de chaine + $origtext =~ s/\s+$//; $self->{itemsList}[$self->{itemIdx}]->{name} = $origtext; - $self->{isGame} = 0; + $self->{isName} = 0; } } elsif ($self->{parsingTips}) @@ -194,71 +309,86 @@ use GCPlugins::GCgames::GCgamesCommon; # Enleve les blancs en debut de chaine $origtext =~ s/^\s+//; # Enleve les blancs en fin de chaine - $origtext =~ s/\s+$//; - if ($self->{isTip} eq 2) +# $origtext =~ s/\s+$//; +# There are problems with some texts if ended blanks are removed + if ($self->{isTip} eq 1) + { + $origtext =~ s|Gameboy|Game Boy|gi; + $origtext =~ s|Megadrive|Mega Drive|gi; + $origtext =~ s|PlayStation Portable|PSP|gi; + $origtext =~ s|PlayStation Vita|PS Vita|gi; + + if (($origtext =~ /$self->{curInfo}->{platform}/i) || ($origtext =~ /astuce/i) || ($origtext =~ /renseignement/i) || ($origtext =~ /campagne/i)) + { + $self->{isTip} = 2; + } + else + { + $self->{isTip} = 0; + } + } + elsif ($self->{isTip} eq 4) { - $self->{curInfo}->{secrets} .= "\n\n" if $self->{curInfo}->{secrets}; $self->{curInfo}->{secrets} .= $origtext; - $self->{isTip} = 0; } - elsif ($self->{isTip} eq 1) + elsif ($self->{isTip} eq 3) { chomp($origtext); if ( ($self->{curInfo}->{secrets}) && ($origtext ne "") ) { - $self->{curInfo}->{secrets} .= "\n" + $self->{curInfo}->{secrets} .= "\n\n" } $self->{curInfo}->{secrets} .= $origtext; - $self->{isTip} = 0; + $self->{isTip} = 4; } } else { - if ($self->{inside}->{h1}) + $origtext =~ s/^\s*//; + if ($self->{is} && $origtext) { - if ($self->{inside}->{a}) + if ($self->{is} eq 'genre') { - $self->{curInfo}->{name} = $origtext; - $self->{curInfo}->{exclusive} = 1; + $self->{curInfo}->{$self->{is}} .= "$origtext,"; } - elsif ($self->{inside}->{span}) + else { - if ($origtext !~ /^Fiche /) - { - $origtext =~ s/^\s*-?\s*//; - $self->{curInfo}->{platform} = $origtext; - } + $self->{curInfo}->{$self->{is}} = $origtext; } + $self->{curInfo}->{$self->{is}} =~ s/Non/1/i if $self->{is} eq 'players'; + $self->{curInfo}->{$self->{is}} = int($self->{curInfo}->{$self->{is}} / 2) if $self->{is} eq 'ratingpress'; + $self->{curInfo}->{$self->{is}} =~ s/\s+$// if $self->{is} eq 'released'; + $self->{curInfo}->{$self->{is}} = $self->getPlatformName($self->{curInfo}->{$self->{is}}) if $self->{is} eq 'platform'; + $self->{is} = ''; } - elsif ($self->{inside}->{strong}) - { - $self->{is} = 'released' if ($origtext =~ /Sortie :/) || ($origtext =~ /Sortie France :/); - $self->{is} = 'genre' if $origtext =~ /Type :/; - $self->{is} = 'description' if $origtext =~ /Descriptif :/; - $self->{is} = 'editor' if $origtext =~ /Editeur :/; - $self->{is} = 'developer' if $origtext =~ /D.*?veloppeur :/; - $self->{is} = 'players' if $origtext =~ /Multijoueurs :/; - $self->{curInfo}->{exclusive} = 0 if $origtext =~ /Existe aussi sur :/; - } - elsif ($self->{is}) + else { - $origtext =~ s/^\s*//; - $origtext =~ s/\n$//; - if ($origtext) + if ($self->{isTip} eq 1) { - if ($self->{is} eq 'players') - { - $origtext =~ s/-/1/; - $origtext =~ s/non/1/i; - $origtext =~ s/oui/Multijoueurs/i; - } - if ($self->{is} eq 'ratingpress') - { - $origtext =~ m|(\d*)/20|; - $origtext = int($1 / 2); - } - $self->{curInfo}->{$self->{is}} = $origtext; - $self->{is} = ''; + if (($origtext =~ /wiki/i) || ($origtext =~ /etajv/i)) + { + $self->{isTip} = 2; + } + else + { + $self->{isTip} = 0; + } + } + elsif ($origtext eq 'Editeur(s) / Développeur(s) : ') + { + $self->{is} = 'editor'; + } + elsif ($origtext =~ /^\s*\|\s*$/) + { + $self->{is} = 'developer' if ! $self->{curInfo}->{developer}; + } + elsif ($origtext eq 'Sortie France : ') + { + $self->{is} = 'released'; + } + elsif ($origtext eq 'Nombre maximum de joueurs : ') + { + $self->{is} = 'players'; } } } @@ -279,7 +409,8 @@ use GCPlugins::GCgames::GCgamesCommon; $self->{hasField} = { name => 1, - platform => 1 + platform => 1, + released => 1 }; $self->{isTip} = 0; @@ -293,49 +424,24 @@ use GCPlugins::GCgames::GCgamesCommon; my ($self, $html) = @_; if ($self->{parsingList}) { - $self->{parsingEnded} = 0; - $self->{inResults} = 0; $self->{isGame} = 0; + $self->{isName} = 0; + $self->{isReleased} = 0; + $self->{isPlatform} = 0; + $self->{urls} = {}; + $html =~ s/<\/?b>//ge; } elsif ($self->{parsingTips}) { - $html =~ s|

    Les astuces d|$self->RecupTips($1)|ge; - $html =~ s|

    La solution d|$self->RecupSolution($1)|ge; - $html =~ s|
    ||gi; - $html =~ s|

    Plus d'infos

    ||gi; - $html =~ s|
    ||gi; - $html =~ s|

    ||gi; - $html =~ s|

    ||gi; - $html =~ s|||gi; - $html =~ s|

    ||gi; - $html =~ s|

    ||gi; - $html =~ s|
    |

    |gi; - $html =~ s||

    |gi; - $html =~ s|||gi; - $html =~ s|||gi; - $html =~ s|||gi; - $html =~ s|||gi; - $html =~ s||Cercle|gi; - $html =~ s||Croix|gi; - $html =~ s||Carr.|gi; - $html =~ s||Triangle|gi; - $html =~ s||Cercle|gi; - $html =~ s||Croix|gi; - $html =~ s||Carr.|gi; - $html =~ s||Triangle|gi; - $html =~ s|\x{92}|'|gi; - $html =~ s|’|'|gi; - $html =~ s|•|*|gi; - $html =~ s|œ|oe|gi; - $html =~ s|…|...|gi; - $html =~ s|\x{85}|...|gi; - $html =~ s|\x{8C}|OE|gi; - $html =~ s|\x{9C}|oe|gi; + $html =~ s||$self->RecupTips("http://www.jeuxvideo.com" . $1)|ge; + $html =~ s|Chargement du lecteur vid(.)o...|

    "Une video est disponible"

    |gi; + $html =~ s|Partager sur :||gi; + $html =~ s|(.+?)|$2|gi; } else { $self->{is} = ''; - $self->{inScreenshots} = 0; + $self->{curInfo}->{exclusive} = 1; } return $html; } @@ -345,74 +451,32 @@ use GCPlugins::GCgames::GCgamesCommon; my ($self, $url) = @_; my $html = $self->loadPage($url); - my $savenexturl = ''; - - my $found = index($html,"

    = 0 ) - { - $savenexturl = substr($html, $found +length('

    "); - if ( $found >= 0 ) - { - $html = substr($html, $found +length('