package GCExport::GCExportTellico; ################################################### # # Copyright 2005-2010 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 GCExport::GCExportBase; { package GCExport::GCExporterTellico; use base qw(GCExport::GCExportBaseClass); use GCUtils; sub new { my $proto = shift; my $class = ref($proto) || $proto; my $self = $class->SUPER::new(); bless ($self, $class); $self->checkModule('MIME::Base64'); $self->checkModule('Digest::MD5'); #List of collections: http://www.periapsis.org/tellico/doc/collection-type-values.html # [ entryTitle, type, extra fields ] $self->{models} = { GCbooks => ['Books', '2', ''], GCfilms => ['Videos', '3', ''], GCmusics => ['Music', '4', ''], GCcoins => ['Coin', '8', ''], GCgames => ['Games', '11', ''] }; return $self; } sub getName { my $self = shift; return "Tellico"; } sub getModels { my $self = shift; my @models = keys %{$self->{models}}; return \@models; } sub needsUTF8 { my $self = shift; return 1; } sub getOptions { my $self = shift; return []; } sub wantsFieldsSelection { return 0; } sub preProcess { my $self = shift; $self->{imagesInfos} = {}; return 1; } sub getHeader { my ($self, $number) = @_; my $result; my $model = $self->{model}; my $title = $model->getDescription; my $info = $self->{models}->{$model->getName}; $result = ' '.$info->[2].' '; return $result; } sub transformData { my ($self, $data) = @_; $data =~ s/&/&/g; return $data; } sub transformList { my ($self, $list, $tag) = @_; my $result = ''; if (ref($list) eq 'ARRAY') { foreach (@{$list}) { $result .= " <$tag>".$self->transformData($_->[0]) ."\n"; } } else { foreach (split ',', $list) { s/;.*$//; $result .= " <$tag>".$self->transformData($_)."\n"; } } return $result; } sub encodeImage { my ($self, $file) = @_; my $image = GCUtils::getDisplayedImage($file, $self->{options}->{defaultImage}, $self->{original}); (my $suffix = $image) =~ s/.*?\.([^.]*)$/$1/; $suffix = 'jpeg' if $suffix eq 'jpg'; open PIC, "<$image" or return (undef,undef,undef); my $data = do {local $/; }; close PIC; my $pictureId = Digest::MD5::md5_hex($data).'.'.$suffix; my %infos; $infos{id} = $pictureId; $infos{format} = uc $suffix; $infos{width} = 120; $infos{height} = 160; $infos{data} = MIME::Base64::encode_base64($data); return \%infos; } sub getItem { my ($self, $item, $number) = @_; my $methodName = 'get'.$self->{model}->getName.'Item'; return $self->$methodName($item); } sub getGCfilmsItem { my ($self, $movie, $number) = @_; my $result; #(my $synopsis = $movie->{synopsis}) =~ s/
/\n/gm; #(my $comments = $movie->{comment}) =~ s/
/\n/gm; use integer; my $rating = $movie->{rating} / 2; no integer; my $age = $movie->{age}; my $certification; if ($age == 1) { $certification = 'U (USA)'; } elsif ($age == 2) { $certification = 'G (USA)'; } elsif ($age <= 5) { $certification = 'PG (USA)'; } elsif ($age <= 13) { $certification = 'PG-13 (USA)'; } elsif ($age <= 17) { $certification = 'R (USA)'; } my $imageInfos = $self->encodeImage($movie->{image}); $self->{imagesInfos}->{$imageInfos->{id}} = $imageInfos; my $year = GCPreProcess::extractYear($movie->{date}); $result = ' '.$self->transformData($movie->{title}).' '.$self->transformData($movie->{format}).' '.$year.' '.$certification.' '; $result .= $self->transformList($movie->{genre}, 'genre'); $result .= ' '.$self->transformData($movie->{country}).' '; foreach (split ',', $movie->{actors}) { $result .= " ".$self->transformData($_)."\n"; } $result .= ' '.$self->transformData($movie->{director}).' '; $result .= $self->transformList($movie->{audio}, 'language'); $result .= ' '.$self->transformData($movie->{time}).' '.$self->transformData($movie->{synopsis}).' '.$rating.' '.$self->transformData($movie->{comments}).' '; if (($movie->{borrower}) && ($movie->{borrower} ne 'none')) { $result .= ' true '; } $result .= ' '.$imageInfos->{id}.' '; $result .= ' '; return $result; } sub getGCgamesItem { my ($self, $item, $number) = @_; my $result; use integer; my $rating = $item->{rating} / 2; no integer; my $imageInfos = $self->encodeImage($item->{boxpic}); $self->{imagesInfos}->{$imageInfos->{id}} = $imageInfos; my $year = GCPreProcess::extractYear($item->{released}); $result = ' '.$self->transformData($item->{name}).' '.$self->transformData($item->{platform}).' '.$self->transformData($item->{description}).' '.$year.' '.$self->transformData($item->{added}).' '; $result .= $self->transformList($item->{genre}, 'genre'); $result .= ' '.$self->transformData($item->{editor}).' '.$rating.' '; if (($item->{borrower}) && ($item->{borrower} ne 'none')) { $result .= ' true '; } if ($item->{completion} >= 100) { $result .= ' true '; } $result .= ' '.$imageInfos->{id}.' '; $result .= ' '; return $result; } sub getGCbooksItem { my ($self, $item, $number) = @_; my $result; use integer; my $rating = $item->{rating} / 2; no integer; my $imageInfos = $self->encodeImage($item->{cover}); $self->{imagesInfos}->{$imageInfos->{id}} = $imageInfos; my $year = GCPreProcess::extractYear($item->{publication}); $result = ' '.$self->transformData($item->{title}).' '.$self->transformData($item->{isbn}).' '.$self->transformData($item->{serie}).' '.$self->transformData($item->{edition}).' '.$self->transformData($item->{format}).' '.$self->transformData($item->{description}).' '.$self->transformData($item->{pages}).' '.$self->transformData($item->{acquisition}).' '.$year.' '.$self->transformData($item->{publisher}).' '; $result .= $self->transformList($item->{authors}, 'author'); $result .= ' '; $result .= $self->transformList($item->{language}, 'language'); $result .= ' '; $result .= $self->transformList($item->{genre}, 'genre'); $result .= ' '.$rating.' '; if (($item->{borrower}) && ($item->{borrower} ne 'none')) { $result .= ' true '; } if ($item->{read}) { $result .= ' true '; } $result .= ' '.$imageInfos->{id}.' '; $result .= ' '; return $result; } sub getGCmusicsItem { my ($self, $item, $number) = @_; my $result; use integer; my $rating = $item->{rating} / 2; no integer; my $imageInfos = $self->encodeImage($item->{cover}); $self->{imagesInfos}->{$imageInfos->{id}} = $imageInfos; my $year = GCPreProcess::extractYear($item->{release}); $result = ' '.$self->transformData($item->{title}).' '.$self->transformData($item->{format}).' '.$year.' '.$self->transformData($item->{comment}).' '; $result .= $self->transformList($item->{artist}, 'artist'); $result .= ' '; $result .= $self->transformList($item->{genre}, 'genre'); $result .= ' '.$rating.' '; foreach (@{$item->{tracks}}) { $result .= ' '.$self->transformData($_->[1]).' '.$self->transformData($item->{artist}).' '.$self->transformData($_->[2]).' ' } $result .= ' '; if (($item->{borrower}) && ($item->{borrower} ne 'none')) { $result .= ' true '; } $result .= ' '.$imageInfos->{id}.' '; $result .= ' '; return $result; } sub getGCcoinsItem { my ($self, $item, $number) = @_; my $result; my $frontInfos = $self->encodeImage($item->{front}); $self->{imagesInfos}->{$frontInfos->{id}} = $frontInfos; my $backInfos = $self->encodeImage($item->{back}); $self->{imagesInfos}->{$backInfos->{id}} = $backInfos; $result = ' '.$self->transformData($item->{name}).' '.$self->transformData($item->{currency}).' '.$self->transformData($item->{value}).' '.$self->transformData($item->{year}).' '.$self->transformData($item->{country}).' '.(($item->{type} eq 'coin') ? 'true' : 'false').' '.$self->transformData($item->{added}).' '.$self->transformData($item->{estimate}).' '.$self->transformData($item->{location}).' '.$self->transformData($item->{comments}).' '.$frontInfos->{id}.' '.$backInfos->{id}.' '; return $result; } sub getFooter { my $self = shift; my $result; $result = ' '; foreach (values %{$self->{imagesInfos}}) { $result .= ' '. $_->{data}.''; } $result .='
'; return $result; } # postProcess # Called after all processing. Use it if you need to perform extra stuff on the header. # $header is a reference to the header string. sub postProcess { my ($self, $header, $body) = @_; # Your code here # As header is a reference, it can be modified on place with $$header } # getEndInfo # Used to display some information to user when export is ended. # To localize your message, use $self->{options}->{lang}. # Returns a string that will be displayed in a message box. sub getEndInfo { my $self = shift; my $message; # Your code here # Don't do put anything in message if you don't want information to be displayed. return $message; } } 1;