package GCPlugins::GCgames::GCMobyGames; ################################################### # # Copyright 2005-2015 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 $html = $self->loadPage($html_ini, 0, 1); $html =~ s|
|\n|gi; $html =~ s|
||gi; $html =~ s|||gi;
$html =~ s|||gi;
$html =~ s|||gi;
$html =~ s|||gi;
my $found = index($html,"sbR sbL sbB\">");
if ( $found >= 0 )
{
$answer = substr($html, $found + length('sbR sbL sbB">'),length($html)- $found -length('sbR sbL sbB">') );
$answer = substr($answer, 0, index($answer,""));
$answer = decode_entities($answer);
}
return $answer;
}
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') && ($attr->{class} eq 'searchData'))
{
$self->{insideSearchImage} = 1;
}
elsif ($tagname eq 'br')
{
if ($attr->{clear} eq 'all')
{
$self->{currentName} = '';
$self->{insideSearchImage} = 0;
}
}
elsif ($tagname eq 'em')
{
$self->{isDate} = 1;
}
}
elsif ($self->{parsingTips})
{
if (($tagname eq 'tr') && ($attr->{class} eq 'mb2'))
{
$self->{isSectionTips} = 1;
}
elsif ( ($tagname eq 'a') && ($self->{isSectionTips}) )
{
$self->{tip_wait} = $self->extractTips('http://www.mobygames.com'.$attr->{href});
}
elsif ($tagname eq 'br')
{
$self->{isSectionTips} = 0;
}
elsif ($tagname eq 'head')
{
$self->{isSectionTips} = 0;
}
}
else
{
if ( ($tagname eq 'h1') && ($attr->{class} eq 'niceHeaderTitle') )
{
$self->{isName} = 1;
}
elsif ($tagname eq 'div')
{
if ($attr->{class} =~ m/scoreBoxBig/i)
{
$self->{isRating} = 1;
}
if ($self->{curInfo}->{genre})
{
$self->{isGenre} = 0;
}
if ($attr->{class} ne 'listing-detail')
{
$self->{isDescription} = 0;
$self->{isExclusive} = 0;
}
}
elsif ($tagname eq 'tpfdescriptiontpf')
{
$self->{isDescription} = 1;
}
elsif ( ($tagname eq 'a') && ($attr->{class} eq 'edit') )
{
$self->{isDescription} = 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->{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';
$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|