package GCPlugins::GCgames::GCMobyGames; ################################################### # # Copyright 2005-2011 Christian Jodar # # This file is part of GCstar. # # GCstar is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # GCstar is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GCstar; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA # ################################################### use strict; use utf8; use GCPlugins::GCgames::GCgamesCommon; { package GCPlugins::GCgames::GCPluginMobyGames; use base 'GCPlugins::GCgames::GCgamesPluginsBase'; use HTML::Entities; sub extractTips { my ($self, $html_ini) = @_; my $answer = ""; my @tmpAnswer = (); my $html = $self->loadPage($html_ini, 0, 1); $html =~ s|
||gi; $html =~ s|||gi; $html =~ s|||gi; $html =~ s|||gi; my $found = index($html,"class=\"sbL sbB sbT\">"); if ( $found >= 0 ) { $answer = substr($html, $found + length("class=\"sbL sbB sbT\">"),length($html)- $found -length("class=\"sbL sbB sbT\">") ); $answer = substr($answer, 0, index($answer,"
"); if ( $found >= 0 ) { my $html2 = substr($html, $found + length("class=\"sbR sbL sbB\">
"),length($html)- $found -length("class=\"sbR sbL sbB\">
") ); $html2 = substr($html2, 0, index($html2,"
")); $html2 =~ s/|\n|gi; $html2 =~ s|
||gi; $tmpAnswer[1] = decode_entities($html2); } } return @tmpAnswer; } sub extractPlayer { my ($self, $html_ini, $word) = @_; my $html = 0; my $found = index($html_ini,$word); if ( $found >= 0 ) { $html = substr($html_ini, $found + length($word),length($html_ini)- $found -length($word) ); $html = substr($html,0, index($html,"") ); $html = reverse($html); $html = substr($html,0, index($html,">") ); $html = reverse($html); $html =~ s/ / /g; $html =~ s/1 Player/1/; } return $html; } sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; $self->{inside}->{$tagname}++; if ($self->{parsingList}) { if ( !$self->{insideSearchImage} && ($tagname eq 'a') && ( substr($attr->{href},0,6) eq '/game/' ) ) { # Test if there is a platform name in it # (i.e. if we can find a second slash after game/ ) if ($attr->{href} =~ m|/game/[^/]*/|) { if ($self->{currentName}) { $self->{itemIdx}++; $self->{itemsList}[$self->{itemIdx}]->{url} = 'http://www.mobygames.com'.$attr->{href}.''; $self->{itemsList}[$self->{itemIdx}]->{name} = $self->{currentName}; $self->{isPlatform} = 1; } else { # This is a game we want to add $self->{isGame} = 1; $self->{itemIdx}++; $self->{itemsList}[$self->{itemIdx}]->{url} = 'http://www.mobygames.com'.$attr->{href}.''; $self->{isName} = 1 ; } } else { # We will need the name later $self->{isGameName} = 1; } } elsif ( ($tagname eq 'a') && ( substr($attr->{href},0,7) eq '/search' ) ) { $self->{isGame} = 0; } elsif ($tagname eq 'div') { if ($attr->{class} eq 'searchResult') { $self->{currentName} = ''; } elsif ($attr->{class} eq 'searchImage') { $self->{insideSearchImage} = 1; } } elsif ($tagname eq 'em') { $self->{isDate} = 1; } } elsif ($self->{parsingTips}) { if (($tagname eq 'table') && ($attr->{summary} eq 'List of Tips and Tricks')) { $self->{isSectionTips} = 2; } elsif ( ($tagname eq 'b') && ($self->{isSectionTips} eq '2') ) { $self->{isSectionTips} = 1; } elsif ( ($tagname eq 'tr') && (($attr->{class} eq 'mb1') || ($attr->{class} eq 'mb2')) ) { $self->{isTip} = 1 if ($self->{isTip} eq 2); $self->{isCode} = 1 if ($self->{isCode} eq 2); } elsif ( ($tagname eq 'a') && ($self->{isTip} eq 1)) { my @tips = $self->extractTips('http://www.mobygames.com'.$attr->{href}.''); if ($tips[0] =~ m/unlock/i) { $Text::Wrap::columns = 80; $tips[1] = Text::Wrap::wrap('', '', $tips[1]); #$self->{tmpCheatLine} = []; #push @{$self->{tmpCheatLine}}, @tips; push @{$self->{curInfo}->{unlockable}}, \@tips; } else { my $answer = $tips[0]; $answer .= "\n"; $answer .= $tips[1]; if ( ($self->{curInfo}->{secrets}) && ($answer ne "") ) { $self->{curInfo}->{secrets} .= "\n\n\n" } $self->{curInfo}->{secrets} .= $answer; } $self->{isTip} = 2; } elsif ( ($tagname eq 'a') && ($self->{isCode} eq 1)) { my @tips = $self->extractTips('http://www.mobygames.com'.$attr->{href}.''); @tips = reverse(@tips); $Text::Wrap::columns = 80; $tips[1] = Text::Wrap::wrap('', '', $tips[1]); #$self->{tmpCheatLine} = []; #push @{$self->{tmpCheatLine}}, @tips; push @{$self->{curInfo}->{code}}, \@tips; $self->{isCode} = 2; } elsif ($tagname eq 'br') { $self->{isTip} = 3; $self->{isCode} = 3; $self->{isSectionTips} = 0; } elsif ($tagname eq 'head') { $self->{isTip} = 0; $self->{isCode} = 0; $self->{isSectionTips} = 0; } } else { if ($tagname eq 'div') { for ($attr->{id}) { /^gameTitle$/ && ($self->{isName} = 1, last); /^gamePlatform/ && ($self->{isPlatform} = 1, last); #/^coreGameCover/ && ($self->{isBox} = 1, last); /^coreGameRelease/ && ($self->{isEditor} = 1, last); } if ($attr->{class} =~ m/scoreBoxBig/) { $self->{isRating} = 1; } if ($self->{curInfo}->{genre}) { $self->{isGenre} = 0; } $self->{isDescription} = 0; } elsif ( ($tagname eq 'a') && ($self->{isName}) ) { $self->{is} = 'name'; $self->{curInfo}->{exclusive} = 1; $self->{isName} = 0; } elsif ( ($tagname eq 'a') && ($self->{isPlatform}) ) { $self->{is} = 'platform'; $self->{isPlatform} = 0; } elsif ( ($tagname eq 'a') && ($self->{isEditor}) ) { $self->{is} = 'editor'; $self->{isEditor} = 0; } elsif ( ($tagname eq 'a') && ($self->{isDeveloper}) ) { $self->{is} = 'developer'; $self->{isDeveloper} = 0; } elsif ( ($tagname eq 'a') && ($self->{isDate}) ) { $self->{is} = 'released'; $self->{isDate} = 0; } elsif ( ($tagname eq 'a') && ($self->{isGenre}) ) { $self->{is} = 'genre'; } elsif ($tagname eq 'img') { if ($attr->{src} =~ m|covers/small|) { $attr->{src} =~ s|/small/|/large/| if $self->{bigPics}; $self->{curInfo}->{boxpic} = $attr->{src}; # From here we try to get back cover my $covers = $self->loadPage($self->{rootUrl}.'/cover-art', 0, 1); $covers =~ m|