summaryrefslogtreecommitdiff
path: root/lib/gcstar/GCPlugins/GCcomics/GCmangasanctuary.pm
blob: d05d0c8f21ad4f9c0caa98963cb582986e59fad3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
package GCPlugins::GCcomics::GCmangasanctuary;

###################################################
#
#  Copyright 2005-2007 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::GCcomics::GCcomicsCommon;

{

	package GCPlugins::GCcomics::GCPluginmangasanctuary;

	use LWP::Simple qw($ua);

	use base qw(GCPlugins::GCcomics::GCcomicsPluginsBase);

	sub start
	{
		my ( $self, $tagname, $attr, $attrseq, $origtext ) = @_;
		if ( $self->{parsingList} )# partie en rapport à la page de résultats
		{

			#The interesting part to parse looks like this :
			#<li class="row1"><a href="/manhwa-rebirth-vol-2-simple-s1397-p682.html">Rebirth #2</a> <span>Manhwa</span></li>
			if ( $tagname eq "a" )
			{
				$self->{isDebut} = 1;
				$self->{itemIdx}++;
				$self->{itemsList}[ $self->{itemIdx} ]->{url} = "http://www.manga-sanctuary.com" . $attr->{href};
				$attr->{href} =~ m/\/(.*?)-.*-vol-\d+-(.*?)-s\d+-p\d+.html/;
				$self->{itemsList}[ $self->{itemIdx} ]->{type} =  $1;
				$self->{itemsList}[ $self->{itemIdx} ]->{format} = $2;
			}
		}
		else# partie en rapport à la page de l'élément
		{

			#Commencer par récupérer l'image
			#<a target="_blank" href="/couvertures/big/rebirth1gd.jpg"><img src="/couvertures/rebirth1gd.jpg"></a>
			if (   ( $tagname eq "a" ) && ( $attr->{href} =~ m/couvertures.*\.[jJ][pP][gG]/ ) )
			{
				my $response = $ua->get("http://www.manga-sanctuary.com" . $attr->{href});
				if ($response->content_type =~ m/text\/html/) #la grande image n'existe pas
				{
					$self->{downloadThumbnail} = 1;
				}
				else#la grande image existe
				{
					$self->{curInfo}->{image} = "http://www.manga-sanctuary.com" . $attr->{href};
				}
			}
			if (  ( $tagname eq "img" ) && ( $attr->{src} =~ m/couvertures.*\.[jJ][pP][gG]/ ) && ($self->{downloadThumbnail} == 1) )
			{
				$self->{curInfo}->{image} = "http://www.manga-sanctuary.com" . $attr->{src};
				$self->{downloadThumbnail} =0;
			}
			#Code général détection dt et dd
			if ( $tagname eq "dt")
			{
				$self->{tagDTdetected} =1;
			}elsif ( $tagname eq "dd")
			{
				$self->{tagDDdetected} =1;
			}elsif ( $tagname eq "h3")
			{
				$self->{tagH3detected} =1;
			}elsif ( $tagname eq "p")
			{
				$self->{tagPdetected} =1;
			}elsif ( $tagname eq "a")
			{
				$self->{tagAdetected} =1;
			}
			#Code pour différencier les types de titres (original /français)			
			if (  ( $tagname eq "img") && ( $attr->{src} =~ m/\/design\/img\/flags/ ) && ($self->{titleDetected} == 1) )
			{
				$attr->{src} =~ m/\/(\d*)\.png$/;
				if ($1 == 77)
				{
					$self->{titreFrancais} = 1;
				}
				else
				{
					$self->{titreFrancais} = 0;
				}
			}
			#Code pour récupérer la notation
			#<ul id="notation">\nStaff MS:<img src="/design/img/9.gif" title="8.5/10"/></ul>
			if (  ( $tagname eq "ul") && ( $attr->{id} =~ m/notation/ ) )
			{
				$self->{notationDetected} = 1;
			}elsif (  ( $tagname eq "img") && ( $self->{notationDetected} == 1 ) )
			{
				$attr->{title} =~ m/^(\d*\.?\d*)\/10/;
				$self->{curInfo}->{rating} = $1;
				$self->{notationDetected} = 0;
				
				#Récupération du format dans l'adresse de la page.
				#http://www.manga-sanctuary.com/manga-duds-hunt-vol-1-simple-s1169-p1477.html
				#Peut être fait dès que webPage est renseigné, placé ici pour être sûr de n'être lancé qu'une seule fois.
				$self->{curInfo}->{webPage} =~ m/vol-\d+-(.*?)-s\d+-p\d+\.html/;
				$self->{curInfo}->{format} = $1;
			}
		}
	}

	sub end
	{
		my ( $self, $tagname ) = @_;
		if ( $self->{parsingList} )# partie en rapport à la page de résultats
		{
			if ( ( $tagname eq "a" ) && $self->{isFin} == 1 )
			{
				#end of collection, next field is title
				$self->{isFin} = 0;
			}
		}
		else# partie en rapport à la page de l'élément
		{
			#Code général détection dt et dd
			if ( $tagname eq "dt")
			{
				$self->{tagDTdetected} =0;
			}elsif ( $tagname eq "dd")
			{
				$self->{tagDDdetected} =0;
				#RAZ en cas de champ vide
				$self->{titleDetected} =0;
				$self->{titreFrancais} = 1;
				$self->{publisherDetected} =0;
				$self->{collectionDetected} =0;
				$self->{publishdateDetected} =0;
				$self->{costDetected} =0;
				$self->{typeDetected} =0;
				$self->{categoryDetected} =0;
				$self->{genresDetected} =0;
				$self->{scenaristeDetected} =0;
				$self->{dessinateurDetected} =0;
			}elsif ( $tagname eq "div")#Le code à récupérer pour un titre h3 donné se trouve après la balise <\h3> donc on ne peut pas l'utiliser.
			{
				$self->{tagH3detected} =0;
			}elsif ( $tagname eq "p")
			{
				$self->{tagPdetected} =0;
				#RAZ en cas de champ vide
				$self->{synopsisDetected} =0;
				$self->{critiquesDetected} =0;
				$self->{reactionsDetected} =0;
			}elsif ( $tagname eq "a")
			{
				$self->{tagAdetected} =0;
			}elsif ( $tagname eq "ul" )
			{
				$self->{notationDetected} = 0;
			}
		}
	}

	sub text
	{
		my ( $self, $origtext ) = @_;

		return if ( $origtext eq " " );

		return if ( $self->{parsingEnded} );

		if ( $self->{parsingList} )# partie en rapport à la page de résultats
		{
			if ( $self->{isDebut} )
			{
				$self->{itemsList}[ $self->{itemIdx} ]->{title} = $origtext;
				$self->{isDebut}                                = 0;
				$self->{isFin}                                 	= 1;
			}
		}
		else# partie en rapport à la page de l'élément
		{
			
			if ( $self->{tagDTdetected} == 1 )
			{
				#Title
				#<dt><label>Titre <img src="/design/img/flags/112.png"></label></dt><dd>&#37507;&#22818; Last Order </dd><dt><label>Titre <img src="/design/img/flags/77.png"></label></dt><dd>Gunnm Last Order</dd>
				if ($origtext =~ m/^Titre/)
				{
					$self->{titleDetected} =1;
				}
				#Volume
				#<dt><label>Volume:</label></dt>\n<dd>1/23</dd>
				elsif ($origtext =~ m/^Volume/)
				{
					$self->{volumeDetected} =1;
				}
				#Publisher
				#<dt><label>Editeur:</label></dt>\n<dd><a href="http://www.manga-sanctuary.com/bdd/editeurs/6-glenat.html" title="Glénat">Glénat</a></dd>
				elsif ($origtext =~ m/^Editeur/)
				{
					$self->{publisherDetected} =1;
				}
				#collection
				#<dt><label>Label:</label></dt>\n<dd>Kana Shonen</dd>
				elsif ($origtext =~ m/^Label/)
				{
					$self->{collectionDetected} =1;
				}
				#PublishDate
				#<dt><label>Date de sortie:</label></dt>\n<dd>31/10/2002</dd>
				elsif ($origtext =~ m/^Date de sortie/)
				{
					$self->{publishdateDetected} =1;
				}
				#cost
				#<dt><label>Prix:</label></dt>\n<dd>6.5 EUR</dd>
				elsif ($origtext =~ m/^Prix/)
				{
					$self->{costDetected} =1;
				}
				#type
				#<dt><label>Type:</label></dt>\n<dd>Manga</dd>
				elsif ($origtext =~ m/^Type/)
				{
					$self->{typeDetected} =1;
				}
				#category
				#<dt><label>Catégorie:</label></dt>\n<dd>Seinen</dd>
				elsif ($origtext =~ m/^Catégorie/)
				{
					$self->{categoryDetected} =1;
				}
				#Genres [NOTE: pas d'accès aux tags alors je le mets dans synopsis]
				#<dt><label>Genres:</label></dt>\n<dd>Action, SF</dd>
				elsif ($origtext =~ m/^Genres/)
				{
					$self->{genresDetected} =1;
				}
				#scenariste  [de la fiche série]
				#<dt><label>Scénariste</label></dt>
				elsif ($origtext =~ m/^Scénariste/)
				{
					$self->{scenaristeDetected} =1;
				}
				#dessinateur  [de la fiche série]
				#<dt><label>Dessinateur</label></dt>
				elsif ($origtext =~ m/^Dessinateur/)
				{
					$self->{dessinateurDetected} =1;
				}
			}

			if ( $self->{tagDDdetected} == 1 )
			{
				if ($self->{titleDetected} == 1)
				{
					$origtext =~ m/^\s*(.*?)\s*$/;
					if ($self->{titreFrancais} == 1)
					{
						#$self->{curInfo}->{title} =  $1; #Je désactive le titre car c'est le même que la série
						$self->{curInfo}->{series} =  $1;
					}
					else
					{
						$self->{curInfo}->{synopsis} .= "Titre original :".$1."\n";
					}
					$self->{titleDetected} = 0;
				}
				elsif ($self->{volumeDetected} == 1)
				{
					$origtext =~ m/^(\d*)\//;
					$self->{curInfo}->{volume} = $1;
					$self->{volumeDetected} =0;
				}
				elsif ($self->{publisherDetected} == 1)
				{
					$self->{curInfo}->{publisher} = $origtext;
					$self->{publisherDetected} =0;
				}
				elsif ($self->{collectionDetected} == 1)
				{
					$self->{curInfo}->{collection} = $origtext;
					$self->{collectionDetected} =0;
				}
				elsif ($self->{publishdateDetected} == 1)
				{
					$self->{curInfo}->{publishdate} = $origtext;
					$self->{publishdateDetected} =0;
				}
				elsif ($self->{costDetected} == 1)
				{
					$origtext =~ m/^\s*(\d*\.\d*)/;
					$self->{curInfo}->{cost} = $1;
					$self->{costDetected} =0;
				}
				elsif ($self->{typeDetected} == 1)
				{
					$self->{curInfo}->{type} = $origtext;
					$self->{typeDetected} =0;
				}
				elsif ($self->{categoryDetected} == 1)
				{
					$self->{curInfo}->{category} = $origtext;
					$self->{categoryDetected} =0;
				}
				elsif ($self->{genresDetected} == 1)
				{
					$origtext =~ m/^\s*(.*?)\s*$/;
					$self->{curInfo}->{synopsis} .= "Genres : ".$1."\n\n";
					$self->{genresDetected} =0;
				}
			}
			if ( $self->{tagH3detected} == 1 )
			{
				#Code détection synopsis
				# <h3><span>Synopsis</span></h3>
				if ($origtext =~ m/^Synopsis/)
				{
					$self->{synopsisDetected} =1;
					$self->{curInfo}->{synopsis} .= "Synopsis :\n"
				}
				#Code détection critiques
				#<h3>Critiques du staff</h3>
				elsif ($origtext =~ m/^Critiques du staff/)
				{
					$self->{critiquesDetected} =1;
					$self->{curInfo}->{synopsis} .= "\n\nCritiques du staff :\n";
				}
			#Réactions désactivées car pas super intéressant
			#	#Code détection reactions
			#	#<h3>Réactions</h3>
			#	elsif ($origtext =~ m/^Réactions/)
			#	{
			#		$self->{reactionsDetected} =1;
			#		$self->{curInfo}->{synopsis} .= "\n\nRéactions :\n";
			#	}
			}
			if ( $self->{tagPdetected} == 1 )
			{
				if ($self->{synopsisDetected} == 1)
				{
					$origtext =~ m/^\s*(.*?)\s*$/;
					$self->{curInfo}->{synopsis} .= $1."\n";
					$self->{genresDetected} =0;
				}elsif ($self->{critiquesDetected} == 1)
				{
					$origtext =~ m/^\s*(.*?)\s*$/;
					$self->{curInfo}->{synopsis} .= $1."\n";
					$self->{genresDetected} =0;
				}
			#Réactions désactivées car pas super intéressant			
			#	elsif ($self->{reactionsDetected} == 1)
			#	{
			#		$origtext =~ m/^\s*(.*?)\s*$/;
			#		$self->{curInfo}->{synopsis} .= $1."\n";
			#		$self->{genresDetected} =0;
			#	}
			}
			if ( $self->{tagAdetected} == 1 )
			{
				if ($self->{scenaristeDetected} == 1)
				{
					$self->{curInfo}->{writer} = $origtext;
					$self->{scenaristeDetected} =0;
				}
				elsif ($self->{dessinateurDetected} == 1)
				{
					$self->{curInfo}->{illustrator} = $origtext;
					$self->{dessinateurDetected} =0;
				}
			}
		}
	}

	sub new
	{
		my $proto = shift;
		my $class = ref($proto) || $proto;
		my $self  = $class->SUPER::new();
		bless( $self, $class );
#pour la recherche: 
#		$self->{hasField} = {
#			series => 1,
#			title  => 1,
#			volume => 1,
#		};
		$self->{hasField} = {
			title   => 1,
			type   => 1,
			format => 1,
		};



		$self->{itemIdx} = 0;
		$self->{downloadThumbnail} = 0;
		$self->{tagDTdetected} =0;
		$self->{tagDDdetected} =0;
		$self->{tagH3detected} =0;
		$self->{tagPdetected} =0;
		$self->{titleDetected} =0;
		$self->{titreFrancais} = 1;#défaut francais
		$self->{publisherDetected} =0;
		$self->{collectionDetected} =0;
		$self->{publishdateDetected} =0;
		$self->{costDetected} =0;
		$self->{typeDetected} =0;
		$self->{categoryDetected} =0;
		$self->{genresDetected} =0;
		$self->{synopsisDetected} =0;
		$self->{critiquesDetected} =0;
		$self->{reactionsDetected} =0;
		$self->{scenaristeDetected} =0;
		$self->{dessinateurDetected} =0;
		$self->{notationDetected} = 0;

		return $self;
	}

	sub preProcess
	{
		my ( $self, $html ) = @_;

		if ( $self->{parsingList} ) # partie en rapport à la page de résultats 
		{
			#keep only Volumes
			$html =~ m/<h3>Volumes\s\(\d+\)<\/h3>\s*(.*?)\s*<h3>Critiques/s;
			$html = $1;
		}
		else # partie en rapport à la page de l'élément
		{
			$html =~ m/<div id="contenu">\s*(<ul id="menu_fiche">\s*<li><a href="(http:\/\/www.manga-sanctuary.com.*?)">.*?)\s*<h3><span>Mes actions<\/span><\/h3>/s;
			$html = $1;
			
			#récupération des infos de la fiche série 
			my $response = $ua->get($2);
			$response->content =~ m/<h3><span>Staff<\/span><\/h3>\s*(.*?<\/dl>)/s;

			$html .= "\n\n <fiche série>\n\n".$1; 

		}
		
		return $html;
	}

	sub getSearchUrl
	{
		my ( $self, $word ) = @_;
		$word =~ s/\+/ /g;
		return ('http://www.manga-sanctuary.com/recherche/tout/', ['keywords' => $word]);

	}

	sub getItemUrl
	{
		my ( $self, $url ) = @_;
	#Je fais le pari que cette partie n'est pas utilisée
	#	my @array = split( /#/, $url );
	#	$self->{site_internal_id} = $array[1];

		return $url if $url =~ /^http:/;
		return "http://www.manga-sanctuary.com" . $url;
	}

	sub getNumberPasses
	{
		return 1;
	}

	sub getName
	{
		return "Manga-Sanctuary";
	}

	sub getAuthor
	{
		return 'Biggriffon';
	}

	sub getLang
	{
		return 'FR';
	}
}

1;