{{tag>tutoriel}} ====== GCstar : Plugins internet ====== ===== Pré-requis ===== ===== Première étape ===== ===== Autres étapes ===== ==== version fonctionnelle pour le site de la Fnac ==== ++++ GCFnac.pm | package GCPlugins::GCbooks::GCFnac; ################################################### # # Copyright 2005-2006 Tian # # 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::GCbooks::GCbooksCommon; { package GCPlugins::GCbooks::GCPluginFnac; use base qw(GCPlugins::GCbooks::GCbooksPluginsBase); use URI::Escape; sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; $self->{inside}->{$tagname}++; if ($self->{parsingList}) { # Détection début d'un nouvel ouvrage de la liste if ($attr->{class} eq 'js-minifa-title') { # Le prochain bloc de texte est le titre $self->{isTitle} = 1 ; # Créer la nouvelle entrée $self->{itemIdx}++; # Récupération de la page concernant l'ouvrage seul $self->{itemsList}[$self->{itemIdx}]->{url} = $attr->{href}; return; } # Détection éditeur + date elsif ($tagname eq 'vark') { # Le bloc de texte après le suivant contient l'éditeur et la date $self->{isPublisher} = 1 ; } } else { # Détection éditeur if ($tagname eq 'varkeditor') { $self->{isPublisher} = 3 ; } # Détection ISBN elsif ($tagname eq 'varkISBN') { $self->{isISBN} = 3 ; } # Détection pages elsif ($tagname eq 'varkpages') { $self->{isPage} = 3 ; } # Détection date elsif ($tagname eq 'varkdate') { $self->{isPublication} = 3 ; } # Détection auteurs elsif ($tagname eq 'varkauthors') { $self->{isAuthor} = 3 ; } # Détection format elsif ($tagname eq 'varkformat') { $self->{isFormat} = 3 ; } # Détection traducteur elsif ($tagname eq 'varktranslator') { $self->{isTranslator} = 3 ; } # Détection titre elsif ($tagname eq 'varktitle') { $self->{isTitle} = 3 ; } # Capture image elsif ($tagname eq 'varkimage') { $self->{curInfo}->{cover} = $attr->{src}; } } } sub end { my ($self, $tagname) = @_; $self->{inside}->{$tagname}--; # Arrêt de l'ajout d'auteurs if (($self->{isAuthor} == 3) && ($tagname eq 'li')) { $self->{isAuthor} = 0; } } sub text { my ($self, $origtext) = @_; if ($self->{parsingList}) { # Capture du titre if ($self->{isTitle} == 1) { # Enleve les blancs en debut de chaine $origtext =~ s/^\s+//; # Enleve les blancs en fin de chaine $origtext =~ s/\s+$//g; $self->{itemsList}[$self->{itemIdx}]->{title} = $origtext; $self->{isTitle} = 0 ; # Le texte suivant contient l'auteur $self->{isAuthor} = 1 ; return; } # Capture auteur elsif ($self->{isAuthor} == 1) { # Enleve les blancs en debut de chaine $origtext =~ s/^\s+//; # Enleve les blancs en fin de chaine $origtext =~ s/\s+$//g; if ($origtext ne '') { $self->{itemsList}[$self->{itemIdx}]->{authors} = $origtext; $self->{isAuthor} = 0 ; } } elsif ($self->{isPublisher} == 1) { # Passe le texte contenant le type d'ouvrage; le texte suivant contient éditeur et date $self->{isPublisher} = 2 ; return ; } # Capture éditeur et date elsif ($self->{isPublisher} == 2) { my @array = split(/-/,$origtext); $array[2] =~ s/^\s+//; $array[2] =~ s/\s+$//g; $array[3] =~ s/^\s+//; $array[3] =~ s/\s+$//g; $self->{itemsList}[$self->{itemIdx}]->{edition} = $array[2]; $self->{itemsList}[$self->{itemIdx}]->{publication} = $array[3]; $self->{isPublisher} = 0 ; } } else { # Enleve les blancs en debut de chaine $origtext =~ s/^\s+//; # Enleve les blancs en fin de chaine $origtext =~ s/\s+$//g; # Capture titre if ($self->{isTitle} == 3) { $self->{curInfo}->{title} = $origtext; $self->{isTitle} = 0 ; } # Capture auteurs elsif (($self->{isAuthor} == 3) && ($origtext ne ',')) { if ($self->{curInfo}->{authors} eq '') { $self->{curInfo}->{authors} = $origtext; } else { $self->{curInfo}->{authors} .= ", " . $origtext; } } # Capture ISBN elsif ($self->{isISBN} == 3) { if ($origtext ne '') { $self->{curInfo}->{isbn} = $origtext; $self->{isISBN} = 0 ; } } #Capture éditeur elsif ($self->{isPublisher} == 3) { if ($origtext ne '') { $self->{curInfo}->{publisher} = $origtext; $self->{isPublisher} = 0 ; } } # Capture format elsif ($self->{isFormat} == 3) { if ($origtext ne '') { $self->{curInfo}->{format} = $origtext; $self->{isFormat} = 0 ; } } # Capture date elsif ($self->{isPublication} == 3) { if ($origtext ne '') { $self->{curInfo}->{publication} = $origtext; $self->{isPublication} = 0 ; } } # Capture pages elsif ($self->{isPage} == 3) { if ($origtext ne '') { $self->{curInfo}->{pages} = $origtext; $self->{isPage} = 0 ; } } # Capture traducteur elsif ($self->{isTranslator} == 3) { if ($origtext ne '') { $self->{curInfo}->{translator} = $origtext; $self->{isTranslator} = 0 ; } } # Capture description elsif (($self->{isDescription} == 4) && ($origtext ne '')) { $self->{curInfo}->{description} = $origtext; $self->{isDescription} = 0; } # Détection description (on saute une zone de texte) elsif (($self->{isDescription} == 3) && ($origtext ne '')) { $self->{isDescription} = 4; } # Détection description (elle est située deux zones de texte plus loin) elsif ($origtext eq 'Le mot de l\'éditeur') { $self->{isDescription} = 3; } } } sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); bless ($self, $class); $self->{hasField} = { title => 1, authors => 1, publication => 1, format => 0, edition => 1, serie => 0, }; $self->{isUrl} = 0; $self->{isTitle} = 0; $self->{isAuthor} = 0; $self->{isPublisher} = 0; $self->{isISBN} = 0; $self->{isPublication} = 0; $self->{isFormat} = 0; $self->{isSerie} = 0; $self->{isPage} = 0; $self->{isDescription} = 0; $self->{isCover} = 0; $self->{isTranslator} = 0; return $self; } sub preProcess { my ($self, $html) = @_; if ($self->{parsingList}) { # Mise en forme pour détecter facilement les éditeur et date $html =~ s|
||gmi; } else { $html =~ s|Editeur||omi; $html =~ s|Date de parution||omi; $html =~ s|EAN||omi; $html =~ s|Nombre de pages||omi; $html =~ s|Auteur||omi; $html =~ s|Format||omi; $html =~ s|Traduction||omi; $html =~ s|

Caractéristiques détaillées||omi; $html =~ s|img class="js-ProductVisuals-imagePreview"|varkimage|omi; $html =~ s|
  • |\n* |gi; $html =~ s|
    |\n|gi; $html =~ s|
    |\n|gi; $html =~ s|||gi; $html =~ s|||gi; $html =~ s|||gi; $html =~ s|||gi; $html =~ s|

    |\n|gi; $html =~ s|

    ||gi; $html =~ s|
  • ||gi; $html =~ s|\x{92}|'|g; $html =~ s|’|'|gi; $html =~ s|•|*|gi; $html =~ s|…|...|gi; $html =~ s|\x{85}|...|gi; $html =~ s|\x{8C}|OE|gi; $html =~ s|\x{9C}|oe|gi; } return $html; } sub getSearchUrl { my ($self, $word) = @_; return "http://www.fnac.com/search/quick.do?filter=-3&text=". $word ."&category=book"; } sub getItemUrl { my ($self, $url) = @_; return $url if $url; return 'http://www.fnac.com/'; } sub getName { return "Fnac (FR)"; } sub getCharset { my $self = shift; return "ISO-8859-15"; } sub getAuthor { return 'Varkolak'; } sub getLang { return 'FR'; } sub getSearchFieldsArray { return ['isbn', 'title', 'author']; } } 1;
    ++++ ++++ GCFnac.pm | package GCPlugins::GCbooks::GCFnac; ################################################### # # Copyright 2005-2006 Tian # Copyright 2015-2016 Kerenoc01 on Google Mail # # 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::GCbooks::GCbooksCommon; { package GCPlugins::GCbooks::GCPluginFnac; use base qw(GCPlugins::GCbooks::GCbooksPluginsBase); use URI::Escape; sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; $self->{inside}->{$tagname}++; if ($self->{parsingList}) { if (($tagname eq 'div') && ($attr->{class} eq "Article-itemInfo")) { $self->{isTitle} = 1; $self->{isPublisher} = 0; } elsif (($self->{isTitle} eq 1) && ($tagname eq 'a') && ($attr->{class} eq " js-minifa-title")) { $self->{itemIdx}++; $self->{itemsList}[$self->{itemIdx}]->{url} = $attr->{href}; $self->{isTitle} = 2; } elsif (($tagname eq 'p') && ($attr->{class} eq "Article-descSub")) { $self->{isAuthor} = 1; } elsif (($self->{isAuthor} eq 1) && ($tagname eq 'a')) { $self->{isAuthor} = 2; } elsif ($self->{isAuthor} && $tagname eq 'div') { $self->{isAuthor} = 0; } elsif (($tagname eq 'div') && ($attr->{class} eq "editorialInfo")) { $self->{isAnalyse} = 1; } } else { if (($tagname eq 'h1') && ($attr->{class} eq 'ProductSummary-title')) { $self->{isTitle} = 1 ; } elsif (($self->{isTitle} eq 1) && ($tagname eq 'span') && ($attr->{itemprop} eq 'name')) { $self->{isTitle} = 2 ; } elsif (($tagname eq 'div') && ($attr->{class} eq 'ProductSummary-subTitle')) { $self->{isAuthor} = 1 ; } elsif (($self->{isAuthor} eq 1) && ($tagname eq 'a')) { $self->{isAuthor} = 2 ; } elsif (($tagname eq 'a') && ($attr->{class} eq 'expandimg') && ($self->{bigPics})) { $self->{curInfo}->{cover} = $attr->{href} ; } elsif (($tagname eq 'img') && ($attr->{class} eq 'js-ProductVisuals-imagePreview') && ((!$self->{bigPics}) || ($self->{curInfo}->{cover} eq ''))) { $self->{curInfo}->{cover} = $attr->{src} ; } elsif ($tagname eq 'section' && $attr->{id} eq 'ficheResume') { $self->{isDescription} = 1 ; } elsif ($tagname eq 'div' && $attr->{class} eq 'productStrateTop') { $self->{isDescription} = 1 ; } elsif ($self->{isDescription} eq 1 && $tagname eq 'div' && $attr->{class} eq 'whiteContent') { $self->{isDescription} = 2 ; } elsif (($tagname eq 'ul') && ($attr->{class} =~ m/Feature-list/)) { $self->{isAnalyse} = 1 ; $self->{isDescription} = 0; } elsif (($tagname eq 'span') && ($attr->{class} =~ m/Feature-label/)) { $self->{isAnalyse} = 2 ; } elsif (($self->{isAnalyse} eq 1) && ($attr->{class} =~ m/Feature-desc/)) { $self->{isPublisher} = 2 if ($self->{isPublisher}); $self->{isPublication} = 2 if ($self->{isPublication}); $self->{isSerie} = 2 if $self->{isSerie}; $self->{isISBN} = 2 if $self->{isISBN}; $self->{isPage} = 2 if $self->{isPage}; } } } sub end { my ($self, $tagname) = @_; $self->{inside}->{$tagname}--; if ($self->{isAnalyse} && $tagname eq 'div') { $self->{isAnalyse} = 0; } elsif ($self->{isAuthor} && $tagname eq 'div') { $self->{isAuthor} = 0; } elsif ($self->{isAnalyse} eq 2 && $tagname eq 'strong') { $self->{isAnalyse} = 1; } elsif ($self->{isDescription} eq 2 && $tagname eq 'div') { # parfois des descriptions en double : resume + le mot de l'editeur # meme contenu avec une orthographe et une mise en page différente! $self->{isDescription} = 0; } } sub text { my ($self, $origtext) = @_; if ($self->{parsingList}) { if ($self->{isTitle} eq 2) { # Enleve les blancs en debut de chaine $origtext =~ s/^\s+//; # Enleve les blancs en fin de chaine $origtext =~ s/\s+$//g; if (($self->{itemsList}[$self->{itemIdx}]->{title} eq '') && ($origtext ne '')) { $self->{itemsList}[$self->{itemIdx}]->{title} = $origtext; } elsif ($origtext ne '') { $self->{itemsList}[$self->{itemIdx}]->{title} .= ' - '; $self->{itemsList}[$self->{itemIdx}]->{title} .= $origtext; } $self->{isTitle} = 0 ; } elsif ($self->{isAnalyse} > 0) { my @listInfo = split(/\n/, $origtext); my $nbInfos = scalar @listInfo ; if ($nbInfos eq 1) { return; } else { my $publication = $listInfo[$nbInfos-1]; $publication =~ s/^[-\s]+//; $publication =~ s/\s+$//g; $self->{itemsList}[$self->{itemIdx}]->{publication} = $publication; my $edition = $listInfo[$nbInfos-2]; $edition =~ s/^[-\s]+//; $edition =~ s/\s+$//g; $self->{itemsList}[$self->{itemIdx}]->{edition} = $edition; } } elsif ($self->{isAuthor} eq 2) { $origtext =~ s/^\s+//; $origtext =~ s/\s+$//g; if (($self->{itemsList}[$self->{itemIdx}]->{authors} eq '') && ($origtext ne '')) { $self->{itemsList}[$self->{itemIdx}]->{authors} = $origtext; } elsif ($origtext ne '') { $self->{itemsList}[$self->{itemIdx}]->{authors} .= ', '; $self->{itemsList}[$self->{itemIdx}]->{authors} .= $origtext; } $self->{isAuthor} = 1; } } else { # Enleve les blancs en debut de chaine $origtext =~ s/^\s+//; # Enleve les blancs en fin de chaine $origtext =~ s/\s+$//g; if ($self->{isTitle} eq '2') { $self->{curInfo}->{title} = $origtext; $self->{isTitle} = 0 ; } elsif ($self->{isAnalyse} eq 2) { $self->{isISBN} = 1 if ($origtext =~ m/ISBN/i); $self->{isPublisher} = 1 if ($origtext =~ m/Editeur/i); $self->{isFormat} = 1 if ($origtext =~ m/Format/i); $self->{isSerie} = 1 if ($origtext =~ m/Collection/i); $self->{isPublication} = 1 if ($origtext =~ m/Date de parution/i); $self->{isPage} = 1 if ($origtext =~ m/pages/i); $self->{isTranslator} = 1 if ($origtext =~ m/Traduction/i); $self->{isAnalyse} = 1 ; } elsif ($self->{isAuthor} eq 2) { # Enleve les virgules $origtext =~ s/,//; if ($origtext ne '') { $self->{author} = $origtext; } $self->{isAuthor} = 1; } elsif ($self->{isAuthor} eq 1) { if ($origtext =~ m/\(Traduct/) { $self->{curInfo}->{translator} = $origtext; } elsif ($origtext =~ m/^\(/) { $self->{curInfo}->{authors} .= $self->{author}; $self->{curInfo}->{authors} .= ", "; } } elsif ($self->{isISBN} eq 2) { $self->{curInfo}->{isbn} = $origtext; $self->{isISBN} = 0 ; } elsif ($self->{isPublisher} eq 2) { if ($origtext ne '') { $self->{curInfo}->{publisher} = $origtext; $self->{isPublisher} = 0 ; } } elsif ($self->{isFormat} eq 2) { if ($origtext ne '') { $self->{curInfo}->{format} = $origtext; $self->{isFormat} = 0 ; } } elsif ($self->{isSerie} eq 2) { if ($origtext ne '') { $self->{curInfo}->{serie} = $origtext; $self->{isSerie} = 0 ; } } elsif ($self->{isPublication} eq 2) { $self->{curInfo}->{publication} = $self->decodeDate($origtext) if (!$self->{curInfo}->{publication}); $self->{isPublication} = 0 ; } elsif (($self->{isPage} eq 2)) { if ($origtext ne '') { $self->{curInfo}->{pages} = $origtext; $self->{isPage} = 0 ; } } elsif ($self->{isTranslator}) { if ($origtext ne '') { $self->{curInfo}->{translator} = $origtext; $self->{isTranslator} = 0 ; } } elsif ($self->{isDescription} eq 2) { $origtext .= "\n"; $self->{curInfo}->{description} .= $origtext; } } } sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); bless ($self, $class); $self->{hasField} = { title => 1, authors => 1, publication => 1, format => 0, edition => 1, serie => 0, }; $self->{isTitle} = 0; $self->{isAuthor} = 0; $self->{isPublisher} = 0; $self->{isISBN} = 0; $self->{isPublication} = 0; $self->{isFormat} = 0; $self->{isSerie} = 0; $self->{isPage} = 0; $self->{isDescription} = 0; $self->{isTranslator} = 0; return $self; } sub preProcess { my ($self, $html) = @_; if ($self->{parsingList}) { $html =~ s|
    ||gmi; } else { # Le descriptif pouvant contenir des balises html je le repere maintenant my $found = index($html,"Mot de l'"); if ( $found >= 0 ) { my $html2 = substr($html, $found +length('Mot de l\''),length($html)- $found -length('Mot de l\'')); my $found2 = index($html2,"

    = 0 ) { $html3 = substr($html2, $found2 +length('

    "); if ( $found2 >= 0 ) { $html2 = substr($html2, $found2 +length(''),length($html2)- $found2 -length('')); } $html2 =~ s|
  • |\n* |gi; $html2 =~ s|
    |\n|gi; $html2 =~ s|
    |\n|gi; $html2 =~ s|||gi; $html2 =~ s|||gi; $html2 =~ s|||gi; $html2 =~ s|||gi; $html2 =~ s|

    |\n|gi; $html2 =~ s|

    ||gi; $html2 =~ s|
  • ||gi; $html2 =~ s|\x{92}|'|g; $html2 =~ s|’|'|gi; $html2 =~ s|•|*|gi; $html2 =~ s|…|...|gi; $html2 =~ s|\x{85}|...|gi; $html2 =~ s|\x{8C}|OE|gi; $html2 =~ s|\x{9C}|oe|gi; } } return $html; } sub getSearchUrl { my ($self, $word) = @_; return "http://www3.fnac.com/search/quick.do?filter=-3&text=". $word ."&category=book"; } sub getItemUrl { my ($self, $url) = @_; return $url if $url; return 'http://www.fnac.com/'; } sub getName { return "Fnac (FR)"; } sub getCharset { my $self = shift; return "ISO-8859-15"; } sub getAuthor { return 'TPF - Kerenoc'; } sub getLang { return 'FR'; } sub getSearchFieldsArray { return ['isbn', 'title']; } sub decodeDate { my ($self, $date) = @_; # date déjà dans le bon format return $date if ($date =~ m|/|); # date à convertir au format jour/mois/année my @dateItems = split(/\s/, $date); my @listeMois = ("janvier","février","mars","avril","mai","juin", "juillet","août","septmbre","octobre","novembre","décembre"); my $mois = 0; while ($mois < (scalar @listeMois) && $dateItems[(scalar @dateItems)-2] ne $listeMois[$mois]) { $mois++; } return "01/".sprintf("%02d",$mois)."/".$dateItems[1]; } } 1;
    ++++ ==== Amazon ==== ++++ GCAmazon.pm | package GCPlugins::GCbooks::GCAmazon; ################################################### # # Copyright 2005-2009 Tian # # 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::GCbooks::GCbooksCommon; { package GCPlugins::GCbooks::GCPluginAmazon; use base qw(GCPlugins::GCbooks::GCbooksPluginsBase); use XML::Simple; use LWP::Simple qw($ua); use Encode; use HTML::Entities; use GCUtils; sub start { my ($self, $tagname, $attr, $attrseq, $origtext) = @_; $self->{inside}->{$tagname}++; if ($self->{parsingList}) { # Identify beginning of comments if (($self->{isComment} == 0) && ($tagname eq 'varkcomment')) { $self->{isComment} = 1 ; } # Capture URL of book if (($self->{isComment} == 0) && ($self->{isUrl} == 1) && ($tagname eq 'a')) { $self->{itemsList}[$self->{itemIdx}]->{url} = $attr->{href}; $self->{isUrl} = 0 ; $self->{isTitle} = 1 ; return; } # Identify beginning of new book (next text is title) if (($self->{isComment} == 0) && ($tagname eq 'li') && ($attr->{id} =~ /result_[0-9]+/ )) { # Create new entry $self->{itemIdx}++; $self->{isUrl} = 1 ; $self->{isAuthor} = 0 ; return ; } # Identify end of authors list if (($self->{isComment} == 0) && ($tagname eq 'varkendauthors') && ($self->{isAuthor} != 0)) { $self->{isAuthor} = 0 ; return ; } } else { # Detection of book themes if (($self->{isTheme} == 0) && ($tagname eq 'varkgenre')) { $self->{isTheme} = 1 ; return ; } # Detection of book page count if (($self->{isPage} == 0) && ($tagname eq 'varkdata')) { $self->{isPage} = 1 ; return ; } # Detection of authors if ($tagname eq 'varkauthor') { $self->{isAuthor} = 1; return ; } # Capture of image if (($tagname eq 'img') && ($attr->{class} eq 'a-dynamic-image image-stretch-vertical frontImage')) { $attr->{src} =~ /http.+\.jpg/ ; $self->{curInfo}->{cover} = $attr->{src}; $self->{isImage} = 0 ; return ; } # Detection of book description if (($self->{isDescription} == 0) && ($tagname eq 'varkdescription')) { $self->{isDescription} = 1 ; return ; } if (($self->{isDescription} == 1) && ($tagname eq 'div')) { $self->{isDescription} = 2 ; return ; } # Detection title if (($self->{isTitle} == 0) && ($tagname eq 'varktitle')) { $self->{isTitle} = 2 ; return ; } } } sub end { my ($self, $tagname) = @_; $self->{inside}->{$tagname}--; if ($self->{parsingList}) { # Identify end of comments if (($self->{isComment} == 1) && ($tagname eq 'varkcomment')) { $self->{isComment} = 0 ; } } else { # Finishing themes analysis if (($self->{isTheme} != 0) && ($tagname eq 'li')) { $self->{isTheme} = 0 ; return ; } # Finishing description analysis if (($self->{isDescription} != 0) && ($tagname eq 'div')) { $self->{isDescription} = 0 ; return ; } } } sub text { my ($self, $origtext) = @_; if ($self->{parsingList}) { # Remove blanks before and after string $origtext =~ s/^\s+//; $origtext =~ s/\s+$//g; # Capture of book title if (($self->{isComment} == 0) && ($self->{isTitle} == 1) && ($origtext ne '')) { $self->{itemsList}[$self->{itemIdx}]->{title} = $origtext; $self->{isTitle} = 0 ; $self->{isPublication} = 1 ; return ; } # Capture of book publication date if (($self->{isComment} == 0) && ($self->{isPublication} == 1) && ($origtext ne '')) { $self->{itemsList}[$self->{itemIdx}]->{publication} = $origtext; $self->{isAuthor} = 1 ; $self->{isPublication} = 0 ; return ; } # Avoid a text area before the first author if (($self->{isComment} == 0) && ($self->{isAuthor} == 1) && ($origtext ne '')) { $self->{isAuthor} = 2 ; return ; } # Capture of authors if (($self->{isComment} == 0) && ($self->{isAuthor} == 2) && ($origtext ne '')) { if ($self->{itemsList}[$self->{itemIdx}]->{authors} eq '') { $self->{itemsList}[$self->{itemIdx}]->{authors} = $origtext; } else { $self->{itemsList}[$self->{itemIdx}]->{authors} .= " " . $origtext; } return; } } else { # Remove blanks before and after string $origtext =~ s/^\s+//; $origtext =~ s/\s+$//g; # Capture of title if (($self->{isTitle} == 2) && ($origtext ne '')) { $self->{isTitle} = 0 ; $self->{curInfo}->{title} = $origtext; return ; } # Capture of page number if (($self->{isPage} == 1) && ($origtext =~ /^[0-9]+/)) { $self->{curInfo}->{pages} = $origtext; $self->{isPage} = 0 ; return ; } # Capture of editor and publication date if (($self->{isEditor} == 0) && ($origtext eq $self->getTranslation(1))) { $self->{isEditor} = 1 ; return ; } if (($self->{isEditor} == 1) && ($origtext ne '')) { my @array = split('\(',$origtext); $array[1] =~ s/\)//g; $array[0] =~ s/^\s+//; $array[0] =~ s/\s+$//g; $array[1] =~ s/^\s+//; $array[1] =~ s/\s+$//g; $self->{curInfo}->{publisher} = $array[0]; $self->{curInfo}->{publication} = $array[1]; $self->{isEditor} = 0 ; return ; } # Capture of language if (($self->{isLanguage} == 0) && ($origtext eq $self->getTranslation(2))) { $self->{isLanguage} = 1 ; return ; } if (($self->{isLanguage} == 1) && ($origtext ne '')) { $self->{curInfo}->{language} = $origtext; $self->{isLanguage} = 0 ; return ; } # Capture of ISBN if (($self->{isISBN} == 0) && ($origtext eq $self->getTranslation(3))) { $self->{isISBN} =1 ; return ; } if (($self->{isISBN} == 1) && ($origtext ne '')) { $origtext =~ s|-||gi; $self->{curInfo}->{isbn} = $origtext; $self->{isISBN} = 0 ; return ; } # Capture of book dimensions if (($self->{isSize} == 0) && ($origtext eq $self->getTranslation(4))) { $self->{isSize} = 1 ; return ; } if (($self->{isSize} == 1) && ($origtext ne '')) { $self->{curInfo}->{format} = $origtext; $self->{isSize} = 0 ; return ; } # Detection of themes if (($origtext eq '>') && ($self->{isTheme} == 1)) { $self->{isTheme} = 2 ; return ; } # Capture of themes if (($self->{isTheme} == 2) && ($origtext ne '')) { if ($self->{curInfo}->{genre} eq '') { $self->{curInfo}->{genre} = $origtext; } else { $self->{curInfo}->{genre} .= ", " . $origtext; } $self->{isTheme} = 1 ; return; } # Capture of authors if (($self->{isAuthor} == 1) && ($origtext ne '') && ($origtext =~ /^(?:(?!Ajax).)*$/)) { if ($self->{curInfo}->{authors} eq '') { $self->{curInfo}->{authors} = $origtext; } else { $self->{curInfo}->{authors} .= ", " . $origtext; } $self->{isAuthor} = 0 ; return; } # Capture of description if (($self->{isDescription} == 2) && ($origtext ne '')) { if ($self->{curInfo}->{description} eq '') { $self->{curInfo}->{description} = $origtext; } else { $self->{curInfo}->{description} .= $origtext; } return ; } } } sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); bless ($self, $class); $self->{hasField} = { title => 1, authors => 1, publication => 1, format => 0, edition => 0, }; $self->{isComment} = 0; $self->{isUrl} = 0; $self->{isTitle} = 0; $self->{isPublication} = 0; $self->{isAuthor} = 0; $self->{isPage} = 0; $self->{isEditor} = 0; $self->{isISBN} = 0; $self->{isDescription} = 0; $self->{isLanguage} = 0 ; $self->{isTheme} = 0 ; return $self; } sub getItemUrl { my ($self, $url) = @_; return $url; } sub preProcess { my ($self, $html) = @_; if ($self->{parsingList}) { # Analysis of results must be disabled during comments $html =~ s|||gi; # Remove other commercial offers $html =~ s|END SPONSORED LINKS SCRIPT.*||s; # End of authors listing detection $html =~ s|

    ||gi; $html =~ s|
    ||gi; } else { # Beginning of book data : pages, editor, publication date, ISBN, dimensions $html =~ s|||gi; # Beginning of book image $html =~ s|
    ||; # Beginning and end of book description $html =~ s|