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;