Description: fix ISBNdb book plugin Author: Marc Deslauriers Forwarded: http://forums.gcstar.org/viewtopic.php?id=18072 Index: gcstar-1.7.0/lib/gcstar/GCPlugins/GCbooks/GCISBNdb.pm =================================================================== --- gcstar-1.7.0.orig/lib/gcstar/GCPlugins/GCbooks/GCISBNdb.pm 2011-07-17 08:23:00.000000000 -0400 +++ gcstar-1.7.0/lib/gcstar/GCPlugins/GCbooks/GCISBNdb.pm 2013-08-07 16:47:41.752463960 -0400 @@ -42,49 +42,51 @@ if ($self->{parsingList}) { - if (($tagname eq 'div') && ($attr->{class} eq 'bookInfo') && ($self->{searchField} ne 'isbn')) + if (($tagname eq 'div') && ($attr->{class} eq 'bookSnippetBasic')) { $self->{isBook} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{href},"/d/book/") >= 0) && ($self->{isBook})) + elsif (($tagname eq 'a') && ( index($attr->{href},"/book/") >= 0) && ($self->{isBook})) { $self->{itemIdx}++; - $self->{itemsList}[$self->{itemIdx}]->{url} = "http://isbndb.com" . $attr->{href}; + $self->{itemsList}[$self->{itemIdx}]->{url} = $attr->{href}; + } + elsif (($tagname eq 'h1') && ($self->{isBook})) + { $self->{isTitle} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{href},"/d/person/") >= 0) && ($self->{isBook})) + elsif (($tagname eq 'a') && ( index($attr->{href},"/author/") >= 0) && ($self->{isBook})) { $self->{isAuthor} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{href},"/d/publisher/") >= 0) && ($self->{isBook})) + elsif (($tagname eq 'a') && ( index($attr->{href},"/publisher/") >= 0) && ($self->{isBook})) { $self->{isPublisher} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{onclick},"isbndbTrackBuy") >= 0) && ($self->{itemIdx} eq '-1')) - { - $self->{itemIdx}++; - $self->{itemsList}[$self->{itemIdx}]->{url} = $self->{loadedUrl} ; - } - elsif (($tagname eq 'span') && ($attr->{class} eq 'inactive')) + elsif ($tagname eq 'span') { $self->{isBook} = 0 ; } } else { - if ($tagname eq 'title') + if (($tagname eq 'div') && ($attr->{class} eq 'bookSnippetBasic')) + { + $self->{isBook} = 1 ; + } + if (($tagname eq 'h1') && ($self->{isBook})) { $self->{isTitle} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{href},"/d/person/") >= 0)) + elsif (($tagname eq 'a') && ( index($attr->{href},"/author/") >= 0)) { $self->{isAuthor} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{href},"/d/publisher/") >= 0)) + elsif (($tagname eq 'a') && ( index($attr->{href},"/publisher/") >= 0)) { $self->{isPublisher} = 1 ; } - elsif (($tagname eq 'a') && ( index($attr->{href},"/c/Library_Shelves/Dewey") >= 0)) + elsif (($tagname eq 'a') && ( index($attr->{href},"/subject/") >= 0)) { $self->{isGenre} = 1 ; } @@ -104,6 +106,10 @@ $self->{curInfo}->{cover} = $array[0]; } } + elsif (($tagname eq 'div') && ($attr->{id} eq 'rightColumn')) + { + $self->{isBook} = 0 ; + } } } @@ -127,14 +133,34 @@ } elsif ($self->{isAuthor}) { + my @nom_prenom = split(/,/,$origtext); + # Enleve les blancs en debut de chaine + $nom_prenom[0] =~ s/^\s//; + $nom_prenom[1] =~ s/^\s//; + # Enleve les blancs en fin de chaine + $nom_prenom[0] =~ s/\s+$//; + $nom_prenom[1] =~ s/\s+$//; if ($self->{itemsList}[$self->{itemIdx}]->{authors} eq '') { - $self->{itemsList}[$self->{itemIdx}]->{authors} = $origtext; + if ($nom_prenom[1] ne '') + { + $self->{itemsList}[$self->{itemIdx}]->{authors} = $nom_prenom[1] ." " . $nom_prenom[0]; + } + else + { + $self->{itemsList}[$self->{itemIdx}]->{authors} = $nom_prenom[0]; + } } else { - $self->{itemsList}[$self->{itemIdx}]->{authors} .= ', '; - $self->{itemsList}[$self->{itemIdx}]->{authors} .= $origtext; + if ($nom_prenom[1] ne '') + { + $self->{itemsList}[$self->{itemIdx}]->{authors} .= ", " . $nom_prenom[1] ." " . $nom_prenom[0]; + } + else + { + $self->{itemsList}[$self->{itemIdx}]->{authors} .= ", " . $nom_prenom[0]; + } } $self->{isAuthor} = 0 ; } @@ -157,8 +183,35 @@ } elsif ($self->{isAuthor}) { - $self->{curInfo}->{authors} .= $origtext; - $self->{curInfo}->{authors} .= ","; + my @nom_prenom = split(/,/,$origtext); + # Enleve les blancs en debut de chaine + $nom_prenom[0] =~ s/^\s//; + $nom_prenom[1] =~ s/^\s//; + # Enleve les blancs en fin de chaine + $nom_prenom[0] =~ s/\s+$//; + $nom_prenom[1] =~ s/\s+$//; + if ($self->{curInfo}->{authors} eq '') + { + if ($nom_prenom[1] ne '') + { + $self->{curInfo}->{authors} = $nom_prenom[1] ." " . $nom_prenom[0]; + } + else + { + $self->{curInfo}->{authors} = $nom_prenom[0]; + } + } + else + { + if ($nom_prenom[1] ne '') + { + $self->{curInfo}->{authors} .= ", " . $nom_prenom[1] ." " . $nom_prenom[0]; + } + else + { + $self->{curInfo}->{authors} .= ", " . $nom_prenom[0]; + } + } $self->{isAuthor} = 0 ; } elsif ($self->{isPublisher}) @@ -168,9 +221,9 @@ } elsif ($self->{isAnalyse}) { - $self->{isFormat} = 1 if ($origtext =~ m/Book Details:/i); - $self->{isDescription} = 1 if ($origtext =~ m/Notes:/i); - $self->{isDescription} = 1 if ($origtext =~ m/Summary:/i); + $self->{isFormat} = 1 if ($origtext =~ m/Book Details/i); + $self->{isDescription} = 1 if ($origtext =~ m/Notes/i); + $self->{isDescription} = 1 if ($origtext =~ m/Summary/i); $self->{isAnalyse} = 0 ; } @@ -233,14 +286,25 @@ } elsif ($self->{isGenre}) { - my @array = split(/--/,$origtext); + $origtext =~ s/ -- /\//gi; - $self->{curInfo}->{genre} = $array[1]; # Enleve les blancs en debut de chaine - $self->{curInfo}->{genre} =~ s/^\s+//; + $origtext =~ s/^\s+//; + # Enleve les blancs en fin de chaine + $origtext =~ s/\s+$//g; + + if ($self->{curInfo}->{genre} eq '') + { + $self->{curInfo}->{genre} = $origtext; + } + else + { + $self->{curInfo}->{genre} .= ", " . $origtext; + } $self->{isGenre} = 0 ; } - elsif (($origtext =~ m/ISBN:/i) && ($self->{curInfo}->{isbn} eq '')) + elsif ((($origtext =~ m/ISBN10:/i) && ($self->{curInfo}->{isbn} eq '')) || + ($origtext =~ m/ISBN13:/i)) { my @array = split(/:/,$origtext); @@ -297,7 +361,10 @@ else { $html =~ s|||gi; - $html =~ s|
  • |\n* |gi; + $html =~ s|
  • ||gi; + $html =~ s|
  • ||gi; + $html =~ s|||gi; $html =~ s|
    |\n|gi; $html =~ s|
    |\n|gi; $html =~ s|||gi; @@ -312,7 +379,7 @@ $html =~ s|…|...|gi; $html =~ s|\x{8C}|OE|gi; $html =~ s|\x{9C}|oe|gi; - + $html =~ s|\x{94}|\n|gi; } return $html; @@ -321,14 +388,13 @@ sub getSearchUrl { my ($self, $word) = @_; - if ($self->{searchField} eq 'isbn') { - return "http://isbndb.com/search-all.html?kw=" .$word; + return "http://isbndb.com/search/all?query=" .$word; } else { - return "http://isbndb.com/search-title.html?kw=" .$word ."&isn="; + return "http://isbndb.com/search/books/1?query=" .$word; } } @@ -348,7 +414,7 @@ sub getCharset { my $self = shift; - return "ISO-8859-15"; + return "UTF-8"; } sub getAuthor