summaryrefslogtreecommitdiff
path: root/lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm')
-rw-r--r--lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm287
1 files changed, 170 insertions, 117 deletions
diff --git a/lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm b/lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm
index c6650c3..d6c7ace 100644
--- a/lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm
+++ b/lib/gcstar/GCPlugins/GCgames/GCMobyGames.pm
@@ -2,7 +2,7 @@ package GCPlugins::GCgames::GCMobyGames;
###################################################
#
-# Copyright 2005-2011 Christian Jodar
+# Copyright 2005-2015 Christian Jodar
#
# This file is part of GCstar.
#
@@ -37,37 +37,35 @@ use GCPlugins::GCgames::GCgamesCommon;
{
my ($self, $html_ini) = @_;
my $answer = "";
- my @tmpAnswer = ();
my $html = $self->loadPage($html_ini, 0, 1);
- $html =~ s|<pre>||gi;
- $html =~ s|</pre>||gi;
+ $html =~ s|<ul>||gi;
+ $html =~ s|</ul>||gi;
$html =~ s|<b>||gi;
$html =~ s|</b>||gi;
- my $found = index($html,"class=\"sbL sbB sbT\">");
+ $html =~ s|<li>||gi;
+ $html =~ s|</li>||gi;
+ $html =~ s|</h3>||gi;
+ $html =~ s|<hr />||gi;
+ $html =~ s|<br>|\n|gi;
+ $html =~ s|<p>|\n|gi;
+ $html =~ s|</p>||gi;
+ $html =~ s|<pre>||gi;
+ $html =~ s|</pre>||gi;
+ $html =~ s|</td>||gi;
+ $html =~ s|</tr>||gi;
+ my $found = index($html,"sbR sbL sbB\">");
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,"</td><td align="));
-
- $tmpAnswer[0] = decode_entities($answer);
-
- $found = index($html,"class=\"sbR sbL sbB\"><p>");
- if ( $found >= 0 )
- {
- my $html2 = substr($html, $found + length("class=\"sbR sbL sbB\"><p>"),length($html)- $found -length("class=\"sbR sbL sbB\"><p>") );
- $html2 = substr($html2, 0, index($html2,"</p>"));
- $html2 =~ s/<br>/\n/gi;
- $html2 =~ s|<p>|\n|gi;
- $html2 =~ s|</p>||gi;
-
- $tmpAnswer[1] = decode_entities($html2);
- }
+ $answer = substr($html, $found + length('sbR sbL sbB">'),length($html)- $found -length('sbR sbL sbB">') );
+ $answer = substr($answer, 0, index($answer,"</table>"));
+ $answer = decode_entities($answer);
}
- return @tmpAnswer;
+ return $answer;
}
+
sub extractPlayer
{
my ($self, $html_ini, $word) = @_;
@@ -93,7 +91,7 @@ use GCPlugins::GCgames::GCgamesCommon;
$self->{inside}->{$tagname}++;
if ($self->{parsingList})
{
- if ( !$self->{insideSearchImage}
+ if ( $self->{insideSearchImage}
&& ($tagname eq 'a')
&& ( substr($attr->{href},0,6) eq '/game/' ) )
{
@@ -127,15 +125,16 @@ use GCPlugins::GCgames::GCgamesCommon;
{
$self->{isGame} = 0;
}
- elsif ($tagname eq 'div')
+ elsif ( ($tagname eq 'div') && ($attr->{class} eq 'searchData'))
{
- if ($attr->{class} eq 'searchResult')
+ $self->{insideSearchImage} = 1;
+ }
+ elsif ($tagname eq 'br')
+ {
+ if ($attr->{clear} eq 'all')
{
$self->{currentName} = '';
- }
- elsif ($attr->{class} eq 'searchImage')
- {
- $self->{insideSearchImage} = 1;
+ $self->{insideSearchImage} = 0;
}
}
elsif ($tagname eq 'em')
@@ -145,66 +144,20 @@ use GCPlugins::GCgames::GCgamesCommon;
}
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') )
+ if (($tagname eq 'tr') && ($attr->{class} eq 'mb2'))
{
$self->{isSectionTips} = 1;
}
- elsif ( ($tagname eq 'tr') && (($attr->{class} eq 'mb1') || ($attr->{class} eq 'mb2')) )
+ elsif ( ($tagname eq 'a') && ($self->{isSectionTips}) )
{
- $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;
-
+ $self->{tip_wait} = $self->extractTips('http://www.mobygames.com'.$attr->{href});
}
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;
}
@@ -212,17 +165,13 @@ use GCPlugins::GCgames::GCgamesCommon;
else
{
- if ($tagname eq 'div')
+ if ( ($tagname eq 'h1') && ($attr->{class} eq 'niceHeaderTitle') )
{
- 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->{isName} = 1;
+ }
+ elsif ($tagname eq 'div')
+ {
+ if ($attr->{class} =~ m/scoreBoxBig/i)
{
$self->{isRating} = 1;
}
@@ -232,19 +181,20 @@ use GCPlugins::GCgames::GCgamesCommon;
$self->{isGenre} = 0;
}
- $self->{isDescription} = 0;
+ if ($attr->{class} ne 'listing-detail')
+ {
+ $self->{isDescription} = 0;
+ $self->{isExclusive} = 0;
+ }
}
- elsif ( ($tagname eq 'a') && ($self->{isName}) )
+ elsif ($tagname eq 'tpfdescriptiontpf')
{
- $self->{is} = 'name';
- $self->{curInfo}->{exclusive} = 1;
- $self->{isName} = 0;
+ $self->{isDescription} = 1;
}
- elsif ( ($tagname eq 'a') && ($self->{isPlatform}) )
+ elsif ( ($tagname eq 'a') && ($attr->{class} eq 'edit') )
{
- $self->{is} = 'platform';
- $self->{isPlatform} = 0;
+ $self->{isDescription} = 0;
}
elsif ( ($tagname eq 'a') && ($self->{isEditor}) )
{
@@ -256,6 +206,25 @@ use GCPlugins::GCgames::GCgamesCommon;
$self->{is} = 'developer';
$self->{isDeveloper} = 0;
}
+ elsif ( ($tagname eq 'a') && ($self->{isExclusive}) )
+ {
+ if ($self->{isExclusive} eq 1)
+ {
+ $self->{isExclusive} = $self->{isExclusive} + 1;
+ }
+ else
+ {
+ $self->{curInfo}->{exclusive} = 0;
+ $self->{isExclusive} = 0;
+ }
+ }
+ elsif ( ($tagname eq 'a') && ($self->{isName}) )
+ {
+ $self->{is} = 'name';
+ $self->{curInfo}->{platform} = $self->{url_plateforme};
+ $self->{curInfo}->{exclusive} = 1;
+ $self->{isName} = 0;
+ }
elsif ( ($tagname eq 'a') && ($self->{isDate}) )
{
$self->{is} = 'released';
@@ -275,9 +244,9 @@ use GCPlugins::GCgames::GCgamesCommon;
# From here we try to get back cover
my $covers = $self->loadPage($self->{rootUrl}.'/cover-art', 0, 1);
$covers =~ m|<img alt=".*?Back Cover".*?src="([^"]*)"|;
- $self->{curInfo}->{backpic} = $1;
- $self->{curInfo}->{backpic} =~ s|/small/|/large/|
- if $self->{bigPics};
+ $self->{curInfo}->{backpic} = $1;
+ $self->{curInfo}->{backpic} =~ s|/small/|/large/|
+ if $self->{bigPics};
}
}
elsif ($tagname eq 'html')
@@ -332,10 +301,6 @@ use GCPlugins::GCgames::GCgamesCommon;
{
my ($self, $tagname) = @_;
$self->{inside}->{$tagname}--;
- if ($self->{parsingList} && ($tagname eq 'div'))
- {
- $self->{insideSearchImage} = 0;
- }
}
sub text
@@ -359,6 +324,7 @@ use GCPlugins::GCgames::GCgamesCommon;
elsif ($self->{isPlatform})
{
$self->{itemsList}[$self->{itemIdx}]->{platform} = $origtext;
+ $self->{itemsList}[$self->{itemIdx}]->{url} = $self->{itemsList}[$self->{itemIdx}]->{url} . 'tpfplatformtpf' . $self->{itemsList}[$self->{itemIdx}]->{platform};
$self->{isPlatform} = 0;
}
elsif ($self->{isGameName})
@@ -377,6 +343,7 @@ use GCPlugins::GCgames::GCgamesCommon;
{
$self->{previous} =~ s/[\s\(]*$//g;
$self->{itemsList}[$self->{itemIdx}]->{platform} = $self->{previous};
+ $self->{itemsList}[$self->{itemIdx}]->{url} = $self->{itemsList}[$self->{itemIdx}]->{url} . 'tpfplatformtpf' . $self->{itemsList}[$self->{itemIdx}]->{platform};
}
}
$self->{isDate} = 0;
@@ -385,20 +352,53 @@ use GCPlugins::GCgames::GCgamesCommon;
}
elsif ($self->{parsingTips})
{
- if ($self->{isSectionTips} eq 1)
+ if ($self->{tip_wait} ne '')
{
- if ($origtext =~ m/General Hints\/Tips/i)
- {
- $self->{isTip} = 2;
- $self->{isCode} = 0;
- }
- elsif ($origtext =~ m/Cheats\/Codes/i)
+ $self->{isUnlock} = 1 if $origtext =~ /Unlockables/i;
+ $self->{isUnlock} = 1 if $origtext =~ /Achievement/i;
+ $self->{isCode} = 1 if $origtext =~ /Cheat/i;
+ }
+ if (($self->{isCode}) || ($self->{isUnlock}))
+ {
+ $Text::Wrap::columns = 80;
+ $self->{tip_wait} = Text::Wrap::wrap('', '', $self->{tip_wait});
+
+ my @array = split(/\n/,$self->{tip_wait});
+ my $element;
+
+ foreach $element (@array)
{
- $self->{isTip} = 0;
- $self->{isCode} = 2;
+ if (($element =~ m/:/i) && !($element =~ m/type one of the following code/i))
+ {
+ $self->{tmpCheatLine} = [];
+ $self->{tmpCheatLine}[0] = substr($element, 0, index($element,":") );
+ $self->{tmpCheatLine}[1] = substr($element, index($element,":") + length(":"),length($element)- index($element,":") -length(":") );
+
+ # Enleve les blancs en debut de chaine
+ $self->{tmpCheatLine}[0] =~ s/^\s+//;
+ $self->{tmpCheatLine}[1] =~ s/^\s+//;
+ # Enleve les blancs en fin de chaine
+ $self->{tmpCheatLine}[0] =~ s/\s+$//;
+ $self->{tmpCheatLine}[1] =~ s/\s+$//;
+
+ push @{$self->{curInfo}->{code}}, $self->{tmpCheatLine} if ($self->{isCode});
+ push @{$self->{curInfo}->{unlockable}}, $self->{tmpCheatLine} if ($self->{isUnlock});
+ $self->{tmpCheatLine} = [];
+ }
}
- $self->{isSectionTips} = 2;
- }
+ $self->{tip_wait} = '';
+ $self->{isCode} = 0;
+ $self->{isUnlock} = 0;
+ }
+ else
+ {
+ if ($self->{curInfo}->{secrets})
+ {
+ $self->{curInfo}->{secrets} .= "\n\n";
+ }
+ $self->{curInfo}->{secrets} .= $self->{tip_wait};
+ $self->{tip_wait} = '';
+ }
}
else
{
@@ -423,6 +423,13 @@ use GCPlugins::GCgames::GCgamesCommon;
$self->{is} = '';
}
+ elsif ($self->{isName} eq 3)
+ {
+ $self->{curInfo}->{name} = $origtext;
+ $self->{curInfo}->{platform} = $self->{url_plateforme};
+ $self->{curInfo}->{exclusive} = 1;
+ $self->{isName} = 0;
+ }
elsif ($self->{isRating})
{
$self->{curInfo}->{ratingpress} = int($origtext/10+0.5);
@@ -432,9 +439,17 @@ use GCPlugins::GCgames::GCgamesCommon;
{
$self->{curInfo}->{description} .= $origtext;
}
+ elsif ($origtext eq 'Published by')
+ {
+ $self->{isEditor} = 1;
+ }
elsif ($origtext eq 'Developed by')
{
- $self->{isDeveloper} = 1
+ $self->{isDeveloper} = 1;
+ }
+ elsif ($origtext eq 'Platforms')
+ {
+ $self->{isExclusive} = 1;
}
elsif ( ($origtext eq 'Also For') || (($origtext eq 'Platforms')))
{
@@ -485,11 +500,13 @@ use GCPlugins::GCgames::GCgamesCommon;
$self->{isDate} = 0;
$self->{isGenre} = 0;
$self->{isDescription} = 0;
- $self->{isBox} = 0;
$self->{isSectionTips} = 0;
- $self->{isTip} = 0;
$self->{isCode} = 0;
+ $self->{isUnlock} = 0;
$self->{is} = '';
+ $self->{url_plateforme} = '';
+ $self->{isExclusive} = 0;
+ $self->{tip_wait} = '';
return $self;
}
@@ -497,7 +514,36 @@ use GCPlugins::GCgames::GCgamesCommon;
sub preProcess
{
my ($self, $html) = @_;
+
$self->{rootUrl} = $self->{loadedUrl};
+
+ if ($self->{parsingTips})
+ {
+ }
+ elsif ($self->{parsingList})
+ {
+ }
+ else
+ {
+ my $found = index($html,"<meta name=\"description\" content=\"");
+ if ( $found >= 0 )
+ {
+ my $rech_description = substr($html, $found,length($html)- $found);
+ $found = index($rech_description,"..");
+ if ( $found >= 0 )
+ {
+ $rech_description = substr($rech_description, index($rech_description,"for ".$self->{url_plateforme})+length("for ".$self->{url_plateforme}), $found-index($rech_description,"for ".$self->{url_plateforme})-length("for ".$self->{url_plateforme}));
+ $rech_description = substr($rech_description, index($rech_description,";")+1, length($rech_description)-index($rech_description,";")-1);
+ # Enleve les blancs en debut de chaine
+ $rech_description =~ s/^\s+//;
+ }
+
+ $html =~ s|<i>||g;
+ $html =~ s|</i>||g;
+ $html =~ s|$rech_description|<tpfdescriptiontpf>$rech_description</tpfdescriptiontpf>|g;
+
+ }
+ }
return $html;
}
@@ -510,6 +556,13 @@ use GCPlugins::GCgames::GCgamesCommon;
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);
+ }
return $url if $url;
return 'http://www.mobygames.com/';