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/GCGameSpot.pm | 365 +++++++++++++++++------------ 1 file changed, 220 insertions(+), 145 deletions(-) (limited to 'lib/gcstar/GCPlugins/GCgames/GCGameSpot.pm') diff --git a/lib/gcstar/GCPlugins/GCgames/GCGameSpot.pm b/lib/gcstar/GCPlugins/GCgames/GCGameSpot.pm index c5870b4..3c6e390 100644 --- a/lib/gcstar/GCPlugins/GCgames/GCGameSpot.pm +++ b/lib/gcstar/GCPlugins/GCgames/GCGameSpot.pm @@ -2,7 +2,7 @@ package GCPlugins::GCgames::GCGameSpot; ################################################### # -# Copyright 2005-2011 Christian Jodar +# Copyright 2005-2014 Christian Jodar # # This file is part of GCstar. # @@ -40,45 +40,76 @@ use GCPlugins::GCgames::GCgamesCommon; $self->{inside}->{$tagname}++; if ($self->{parsingList}) { - if ($tagname eq 'div') + if ($tagname eq 'head') { - $self->{isGame} = 1 - if $attr->{class} =~ /result_title/; + $self->{isGame} = 0; } - elsif ($tagname eq 'tpfdatetpf') + elsif (($tagname eq 'ul') && ($attr->{class} eq 'editorial river search-results')) { - $self->{isDate} = 1; + $self->{isGame} = 1; } elsif (($tagname eq 'a') && ($self->{isGame})) { $self->{itemIdx}++; - $self->{itemsList}[$self->{itemIdx}]->{url} = $attr->{href}; + $self->{itemsList}[$self->{itemIdx}]->{url} = 'http://www.gamespot.com'.$attr->{href}; + } + elsif (($tagname eq 'time') && ($attr->{class} eq 'media-date') && ($self->{isGame})) + { + $self->{itemsList}[$self->{itemIdx}]->{released} = $attr->{datetime}; + $self->{isPlatform} = 0; + + my @array = split(/,/,$self->{itemsList}[$self->{itemIdx}]->{platform}); + my $element; + + my $SaveName = $self->{itemsList}[$self->{itemIdx}]->{name}; + my $SaveDate = $self->{itemsList}[$self->{itemIdx}]->{released}; + my $SaveUrl = $self->{itemsList}[$self->{itemIdx}]->{url}; + $self->{itemIdx}--; + + foreach $element (@array) + { + if ($element ne '') + { + $self->{itemIdx}++; + $self->{itemsList}[$self->{itemIdx}]->{name} = $SaveName; + $self->{itemsList}[$self->{itemIdx}]->{released} = $SaveDate; + $self->{itemsList}[$self->{itemIdx}]->{platform} = $element; + $self->{itemsList}[$self->{itemIdx}]->{url} = $SaveUrl . 'tpfplatformtpf' . $self->{itemsList}[$self->{itemIdx}]->{platform}. 'tpfreleasetpf' . $self->{itemsList}[$self->{itemIdx}]->{released}; + } + } + } + elsif (($tagname eq 'h3') && ($attr->{class} eq 'media-title') && ($self->{isGame})) + { $self->{isName} = 1; } + elsif (($tagname eq 'div') && ($attr->{class} eq 'media-byline') && ($self->{isGame})) + { + $self->{isPlatform} = 1; + } + elsif (($tagname eq 'span') && ($self->{isPlatform} eq 1)) + { + $self->{isPlatform} = 2; + } + elsif (($tagname eq 'ul') && ($attr->{class} eq 'paginate')) + { + $self->{isGame} = 0; + } } elsif ($self->{parsingTips}) { - if (($tagname eq 'h2') && ($attr->{class} eq 'module_title')) + if (($tagname eq 'h2') && ($attr->{class} eq 'cheats__title')) { $self->{isSection} = 1; } - elsif (($tagname eq 'th') && ($attr->{scope} eq 'row') && ($attr->{class} eq 'code') && ($self->{section} ne '')) + elsif (($tagname eq 'th') && ($attr->{scope} eq 'row') && ($attr->{class} eq 'cheats__code') && (($self->{section} eq 'Codes') || ($self->{section} eq 'Unlockables'))) { $self->{isCheat} = 1; } - elsif (($tagname eq 'td') && ($attr->{class} eq 'effect') && ($self->{section} ne '')) + elsif (($tagname eq 'td') && ($attr->{class} eq 'cheats__effect') && ($self->{section} ne '')) { $self->{isDesc} = 1; } - elsif (($tagname eq 'h3') && ($attr->{class} eq 'cheatCodeTitle') && ($self->{section} eq 'Secrets')) - { - $self->{curInfo}->{secrets} .= "\n" if $self->{curInfo}->{secrets}; - } - elsif ($tagname eq 'tpfdebuttpf') - { - $self->{section} = 'Secrets'; - } - elsif (($tagname eq 'div') && ($attr->{class} eq 'head')) + elsif (($tagname eq 'li') && ($attr->{class} eq 'cheats-list__item')) { $self->{section} = ''; } @@ -89,112 +120,74 @@ use GCPlugins::GCgames::GCgamesCommon; } else { - if ($tagname eq 'img') + if (($tagname eq 'a') && ($self->{isScreen})) { - $self->{curInfo}->{boxpic} = ' ' - if $attr->{src} =~ /no_preview/; - if ((! $self->{curInfo}->{boxpic}) && ($attr->{src} =~ /[^xo]boxs[^c]/)) + if (! $self->{curInfo}->{screenshot1}) { - $self->{curInfo}->{boxpic} = $attr->{src}; + $self->{curInfo}->{screenshot1} = $attr->{href}; } - if ($attr->{src} =~ /thumb/) + elsif (! $self->{curInfo}->{screenshot2}) { - my $pic = $attr->{src}; - $pic =~ s/thumb00([0-9])/screen00$1/; - if ($1 && ($1 <= 2)) - { - $self->{curInfo}->{'screenshot'.$1} = $pic - if ! $self->{curInfo}->{'screenshot'.$1}; - } + $self->{curInfo}->{screenshot2} = $attr->{href}; } + $self->{isScreen} = 0; } - elsif (($tagname eq 'div') && ($attr->{class} eq 'boxshot')) - { - $self->{isBox} = 1; - } - elsif (($tagname eq 'a') && ($self->{isBox} eq 1)) - { - my $html = $self->loadPage($self->getItemUrl($attr->{href}), 0, 1); - my $found = index($html,"id=\"main_image\" src=\""); - if ( $found >= 0 ) - { - $html = substr($html, $found +length('id="main_image" src="'),length($html)- $found -length('id="main_image" src="')); - - my @array = split(/"/,$html); - #" - if ($self->{bigPics}) - { - $self->{curInfo}->{boxpic} = $array[0]; - } - $self->{curInfo}->{backpic} = $array[0]; - $self->{curInfo}->{backpic} =~ s/_front/_back/; - } - $self->{isBox} = 0; - } - elsif (($tagname eq 'h1') && ($attr->{class} eq 'productPageTitle')) - { - $self->{isName} = 1 if ! $self->{curInfo}->{name}; - } - elsif (($tagname eq 'meta') && ($attr->{name} eq 'description')) - { - $self->{curInfo}->{description} = $attr->{content}; - } - elsif (($tagname eq 'li') && ($attr->{class} =~ /activeFilter/)) + elsif (($tagname eq 'a') && ($attr->{href} =~ /\/cheats\//)) { - $self->{curInfo}->{exclusive} = 0; - } - elsif (($tagname eq 'span') && ($attr->{class} eq 'reviewer')) - { - $self->{isRating} = 1; + $self->{urlTips} = $attr->{href}; } - elsif (($tagname eq 'a') && ($self->{isRating} eq 1)) + elsif (($tagname eq 'li') && ($attr->{class} eq 'pod-images__item')) { - $self->{isRating} = 2; + $self->{isScreen} = 1; } - elsif (($tagname eq 'li') && ($attr->{class} eq 'moreStat play_info number_of_players')) + elsif (($tagname eq 'img') && ($self->{isBox})) { - $self->{isPlayers} = 1; + $self->{curInfo}->{boxpic} = $attr->{src}; + $self->{curInfo}->{boxpic} =~ s/_medium/_avatar/ if !$self->{bigPics} ; + $self->{isBox} = 0; } - elsif (($tagname eq 'p') && ($self->{isPlayers} eq 1)) + elsif (($tagname eq 'dt') && ($attr->{class} eq 'pod-objectStats__title')) { - $self->{isPlayers} = 2; + $self->{isGame} = 1 if ! $self->{curInfo}->{name}; } - elsif (($tagname eq 'li') && ($attr->{class} eq 'publisher')) + elsif (($tagname eq 'footer') && ($self->{isGame})) { - $self->{isEditor} = 1; + $self->{isGame} = 0; + if ($self->{curInfo}->{exclusive} ne 1) + { + $self->{curInfo}->{exclusive} = 0; + } } - elsif (($tagname eq 'a') && ($self->{isEditor} eq 1)) + elsif (($tagname eq 'h3') && ($self->{isGame})) { - $self->{isEditor} = 2; + $self->{isName} = 1 if ! $self->{curInfo}->{name}; } - elsif (($tagname eq 'li') && ($attr->{class} eq 'developer')) + elsif (($tagname eq 'ul') && ($attr->{class} eq 'system-list') && ($self->{isGame})) { - $self->{isDeveloper} = 1; + $self->{curInfo}->{exclusive} = 0; } - elsif (($tagname eq 'a') && ($self->{isDeveloper} eq 1)) + elsif (($tagname eq 'li') && ($attr->{class} =~ m/system /i) && ($self->{isGame})) { - $self->{isDeveloper} = 2; + $self->{curInfo}->{exclusive} = $self->{curInfo}->{exclusive} + 1; + $self->{isPlatform} = 1 if ($attr->{class} =~ m/$self->{curInfo}->{platform}/i); } - elsif (($tagname eq 'li') && ($attr->{class} eq 'genre')) + elsif (($tagname eq 'div') && ($attr->{class} eq 'media-img imgflare--boxart') && ($self->{isGame})) { - $self->{isGenre} = 1; + $self->{isBox} = 1; } - elsif (($tagname eq 'a') && ($self->{isGenre})) + elsif (($tagname eq 'li') && ($attr->{class} eq 'pod-objectStats__item') && ($self->{isGame})) { - $self->{curInfo}->{genre} = $attr->{title}; + $self->{isEditor} = 0; + $self->{isDeveloper} = 0; $self->{isGenre} = 0; } - elsif (($tagname eq 'li') && ($attr->{class} eq 'date')) + elsif (($tagname eq 'dd') && ($attr->{class} eq 'pod-objectStats__deck')) { - $self->{isReleased} = 1; - } - elsif (($tagname eq 'a') && ($self->{isReleased} eq 1)) - { - $self->{isReleased} = 2; + $self->{isDesc} = 1; } - elsif (($tagname eq 'a') && ($attr->{href} =~ /\/cheats\//) && ($attr->{class} eq 'navItemAction')) + elsif (($tagname eq 'div') && ($attr->{class} eq 'gs-score__cell')) { - $self->{urlTips} = $attr->{href}; + $self->{isRating} = 1 if ! $self->{curInfo}->{ratingpress}; } } } @@ -204,14 +197,6 @@ use GCPlugins::GCgames::GCgamesCommon; my ($self, $tagname) = @_; $self->{inside}->{$tagname}--; - if ($self->{parsingList}) - { - $self->{isGame} = 0 - if ($tagname eq 'div'); - } - elsif ($self->{parsingTips}) - { - } } sub text @@ -220,30 +205,53 @@ use GCPlugins::GCgames::GCgamesCommon; if ($self->{parsingList}) { - if ($self->{isName}) + if ($self->{isName} eq 1) { - $origtext =~ /^(.*?)\s*\((.*?)\)\s*$/; - $self->{itemsList}[$self->{itemIdx}]->{name} = $1; - $self->{itemsList}[$self->{itemIdx}]->{platform} = $2; - $self->{itemsList}[$self->{itemIdx}]->{url} = $self->{itemsList}[$self->{itemIdx}]->{url} . 'tpfplatformtpf' . $self->{itemsList}[$self->{itemIdx}]->{platform}; + # 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->{isName} = 0; } - elsif ($self->{isDate}) + elsif ($self->{isPlatform} eq 2) { - $origtext =~ /^\s*Release Date:\s*(.*?)\s*$/ms; - $self->{itemsList}[$self->{itemIdx}]->{released} = $1; - $self->{isDate} = 0; + # Enleve les blancs en debut de chaine + $origtext =~ s/^\s+//; + # Enleve les blancs en fin de chaine + $origtext =~ s/\s+$//; + + if ($self->{itemsList}[$self->{itemIdx}]->{platform} eq '') + { + $self->{itemsList}[$self->{itemIdx}]->{platform} = $origtext; + } + else + { + $self->{itemsList}[$self->{itemIdx}]->{platform} .= ','.$origtext; + } + + $self->{isPlatform} = 1; } } elsif ($self->{parsingTips}) { - if (($self->{isSection} eq 1) && $self->{inside}->{h2}) - { - $self->{section} = 'Codes' if $origtext =~ /Cheat Codes$/; - $self->{section} = 'Unlockables' if $origtext =~ /Unlockables$/; - $self->{section} = 'Secrets' if $origtext =~ /Secrets$/; - $self->{section} = 'Secrets' if $origtext =~ /Easter Eggs$/; + if (($self->{isSection}) && $self->{inside}->{h2}) + { + $self->{section} = 'Codes' if $origtext =~ /^Cheat Codes/i; + $self->{section} = 'Codes' if $origtext =~ /cheats/i; + $self->{section} = 'Unlockables' if $origtext =~ /^Unlockables/i; + $self->{section} = 'Unlockables' if $origtext =~ /^Achievements/i; + $self->{section} = 'Unlockables' if $origtext =~ /^Trophies/i; + $self->{section} = 'Unlockables' if $origtext =~ /^Steam Achievements/i; + $self->{section} = 'Secrets' if $origtext =~ /^Secrets/i; + $self->{section} = 'Secrets' if $origtext =~ /^Easter Eggs/i; + + $self->{section} = 'Secrets' if $self->{section} eq ''; + $self->{section} = '' if $origtext =~ /Walkthrough/i; + $self->{section} = '' if $origtext =~ /FAQ/i; $self->{isSection} = 0; + } elsif (($self->{section} eq 'Codes') || ($self->{section} eq 'Unlockables')) { @@ -283,12 +291,18 @@ use GCPlugins::GCgames::GCgamesCommon; $self->{isDesc} = 0; } } - elsif ($self->{section} eq 'Secrets') + + if ($self->{section} eq 'Secrets') { $origtext =~ s/^\s*//; $origtext =~ s/\s*$//; return if !$origtext; - $self->{curInfo}->{secrets} .= "\n" if $self->{curInfo}->{secrets}; + # Un peu de mise en page + $self->{curInfo}->{secrets} .= "\n\n" if (($self->{curInfo}->{secrets}) && ($self->{inside}->{h2})); + $self->{curInfo}->{secrets} .= "\n" if (($self->{curInfo}->{secrets}) && (! $self->{inside}->{td}) && (! $self->{inside}->{h2}) && ($origtext ne 'Effect')); + $self->{curInfo}->{secrets} .= "\t\t\t" if (($self->{curInfo}->{secrets}) && ($self->{inside}->{td})); + $self->{curInfo}->{secrets} .= "\t\t\t" if (($self->{curInfo}->{secrets}) && ($origtext eq 'Effect')); + $self->{curInfo}->{secrets} .= $origtext; } } @@ -299,34 +313,82 @@ use GCPlugins::GCgames::GCgamesCommon; $origtext =~ s/\n//g; $self->{curInfo}->{name} = $origtext; $self->{curInfo}->{platform} = $self->{url_plateforme}; - $self->{curInfo}->{exclusive} = 1; + $self->{curInfo}->{released} = $self->{url_release}; $self->{isName} = 0; } - elsif ($self->{isRating} eq 2) + elsif ($self->{isPlatform}) + { + $self->{curInfo}->{platform} = $origtext; + $self->{isPlatform} = 0; + } + elsif (($origtext eq 'Published By:') && ($self->{isGame})) + { + $self->{isEditor} = 1; + } + elsif (($origtext eq 'Developed By:')&& ($self->{isGame})) + { + $self->{isDeveloper} = 1; + } + elsif (($origtext eq 'Genre:')&& ($self->{isGame})) + { + $self->{isGenre} = 1; + } + elsif ($self->{isRating}) { + # Enleve les blancs en debut de chaine + $origtext =~ s/^\s+//; + # Enleve les blancs en fin de chaine + $origtext =~ s/\s+$//; + $self->{curInfo}->{ratingpress} = $origtext; $self->{isRating} = 0; } + elsif ($self->{isDesc}) + { + # Enleve les blancs en debut de chaine + $origtext =~ s/^\s+//; + # Enleve les blancs en fin de chaine + $origtext =~ s/\s+$//; + $self->{curInfo}->{description} = $origtext; + $self->{isDesc} = 0; + } else { $origtext =~ s/^\s*//; $origtext =~ s/\s*$//; return if !$origtext; - if ($self->{isReleased} eq 2) + if (($self->{isEditor}) && ($origtext ne ',')) { - $origtext =~ s/ .$//; - $self->{curInfo}->{released} = $origtext; - $self->{isReleased} = 0; + if ($self->{curInfo}->{editor} ne '') + { + $self->{curInfo}->{editor} = $self->{curInfo}->{editor} . ','.$origtext; + } + else + { + $self->{curInfo}->{editor} = $origtext; + } } - elsif ($self->{isEditor} eq 2) + elsif (($self->{isDeveloper}) && ($origtext ne ',')) { - $self->{curInfo}->{editor} = $origtext; - $self->{isEditor} = 0; + if ($self->{curInfo}->{developer} ne '') + { + $self->{curInfo}->{developer} = $self->{curInfo}->{developer} . ','.$origtext; + } + else + { + $self->{curInfo}->{developer} = $origtext; + } } - elsif ($self->{isDeveloper} eq 2) + elsif (($self->{isGenre}) && ($origtext ne ',')) { - $self->{curInfo}->{developer} = $origtext; - $self->{isDeveloper} = 0; + if ($self->{curInfo}->{genre} ne '') + { + $self->{curInfo}->{genre} = $self->{curInfo}->{genre} . ','.$origtext; + } + else + { + $self->{curInfo}->{genre} = $origtext; + } } elsif ($self->{isPlayers} eq 2) { @@ -359,7 +421,7 @@ use GCPlugins::GCgames::GCgamesCommon; $self->{isName} = 0; $self->{isGame} = 0; - $self->{isDate} = 0; + $self->{isPlatform} = 0; $self->{isCheat} = 0; $self->{isDesc} = 0; $self->{isTip} = 0; @@ -372,10 +434,10 @@ use GCPlugins::GCgames::GCgamesCommon; $self->{isReleased} = 0; $self->{isPlayers} = 0; $self->{isBox} = 0; - $self->{isExclu} = 0; - $self->{url_plateforme} = ''; + $self->{isScreen} = 0; $self->{urlTips} = ""; - $self->{SaveUrl} = ""; + $self->{url_plateforme} = ''; + $self->{url_release} = ''; return $self; } @@ -386,22 +448,26 @@ use GCPlugins::GCgames::GCgamesCommon; if ($self->{parsingTips}) { - $html =~ s|(.*?)|$1|g; - $html =~ s|(.*?)|$1|g; + my $found = index($html,"Cheats For " . $self->{curInfo}->{platform}); + if ( $found >= 0 ) + { + $html = substr($html, $found + length('Cheats For ' . $self->{curInfo}->{platform}),length($html)- $found -length('Cheats For ' . $self->{curInfo}->{platform}) ); + $found = index($html,"\"tab-pane \""); + if ( $found >= 0 ) + { + $html = substr($html, 0, $found); + } + } + $html =~ s|||; + ## It takes too much time # $html =~ s|
  • Go to Online Walkthrough|'' . $self->RecupSolution($1) . ''|ge; } elsif ($self->{parsingList}) { - $html =~ s|Release Date|Release Date|g; } else { - my $found = index($html,"Similar Games"); - if ( $found >= 0 ) - { - $html = substr($html, 0, $found); - } } return $html; @@ -440,18 +506,27 @@ use GCPlugins::GCgames::GCgamesCommon; my ($self, $word) = @_; #return 'http://www.gamespot.com/search.html?qs='.$word.'&sub=g&stype=11&type=11'; - return 'http://www.gamespot.com/pages/search/solr_search_ajax.php?q='.$word.'&type=game&offset=0&tags_only=false&sort=false'; + #return 'http://www.gamespot.com/pages/search/solr_search_ajax.php?q='.$word.'&type=game&offset=0&tags_only=false&sort=false'; + #return 'http://www.gamespot.com/search/?qs='.$word.'&filter=summary'; #return 'http://www.gamespot.com/search.html?qs=' .$word. '&tag=masthead%3Bsearch'; + return 'http://www.gamespot.com/search/?indices[0]=game&page=1&q='.$word; } sub getItemUrl { my ($self, $url) = @_; + my $found = index($url,"tpfplatformtpf"); if ( $found >= 0 ) { $self->{url_plateforme} = substr($url, $found +length('tpfplatformtpf'),length($url)- $found -length('tpfplatformtpf')); $url = substr($url, 0,$found); + $found = index($self->{url_plateforme},"tpfreleasetpf"); + if ( $found >= 0 ) + { + $self->{url_release} = substr($self->{url_plateforme}, $found +length('tpfreleasetpf'),length($self->{url_plateforme})- $found -length('tpfreleasetpf')); + $self->{url_plateforme} = substr($self->{url_plateforme}, 0, $found); + } } return 'http://www.gamespot.com' . $url -- cgit v1.2.3