summaryrefslogtreecommitdiff
path: root/lib/gcstar/GCImport/GCImportDVDProfiler.pm
blob: 6f47d7b991511b03fc39f2d3e1dbd7f3cbfd1350 (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
package GCImport::GCImportDVDProfiler;

###################################################
#
#  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 GCImport::GCImportBase;

{
    package GCImport::GCImporterDVDProfiler;

    use base qw(GCImport::GCImportBaseClass);
    
    use XML::Simple;    
        
    sub new
    {
        my $proto = shift;
        my $class = ref($proto) || $proto;
        my $self  = $class->SUPER::new();
        bless ($self, $class);
        
        return $self;
    }

    sub getName
    {
        return "DVDProfiler (.xml)";
    }
    
    sub getOptions
    {
        my $self = shift;
        my @options;
        return \@options;
    }
    
    sub getFilePatterns
    {
       return (['DVDProfiler (.xml)', '*.xml']);
    }
    
    #Return supported models name
    sub getModels
    {
        return ['GCfilms'];
    }

    # Ignored for the moment
    sub wantsFieldsSelection
    {
        return 0;
    }
    sub getEndInfo
    {
        return "";
    }
    
    sub getItemsArray
    {
	my ($self, $file) = @_;
	my $xml;
	my $data;
	# creer un objet
	$xml = XML::Simple->new; # sans keyAttr les dvd seront dans une liste ou chaque dvd sera identifie par l'emplacement qu'il a dans cette liste
	$data = $xml->XMLin ("$file");

	
	my @result; 
	my $film;
	
	foreach $film(@{$data->{DVD}}){
		my $item;
		
		$item->{title} = $film->{Title};
		$item->{date} = $film->{ProductionYear};
		$item->{time} = $film->{RunningTime}.' mn';
		$item->{synopsis} = $film->{Overview};
		####### DIRECTOR #########
		my $director;
		
		if (ref ($film->{Credits}->{Credit}) eq "ARRAY") {
			foreach $director(@{$film->{Credits}->{Credit}}){
				if (($director->{CreditType}) eq 'Direction') {
					$item->{director} .= $director->{FirstName}.' '.$director->{LastName}.', ';
					
				}
			}
		}
		else {
			if (($film->{Credits}->{Credit}->{CreditType}) eq 'Direction') {
					$item->{director} .= $film->{Credits}->{Credit}->{FirstName}.' '.$film->{Credits}->{Credit}->{LastName};
				}
		}
		###### END DIRECTOR ######
		
		####### ACTORS #########
		my $actor;
		if (ref ($film->{Actors}->{Actor}) eq "ARRAY") {
			foreach $actor(@{$film->{Actors}->{Actor}}){
				$item->{actors} .= $actor->{FirstName}.' '.$actor->{LastName}.' '.'('.$actor->{Role}.')'.', ';
				
			}
			}
		else {
		$item->{actors} .= $film->{Actors}->{Actor}->{'FirstName'}.' '.$film->{Actors}->{Actor}->{LastName}.' '.'('.$film->{Actors}->{Actor}->{Role}.')';
		}
		###### END ACTORS ######
		
		####### AUDIO #########
		my $audio;
		if (ref ($film->{Audio}->{AudioFormat}) eq "ARRAY"){
			foreach $audio(@{$film->{Audio}->{AudioFormat}}){
				$item->{audio} .= $audio->{AudioLanguage}.', ';
				
				}
		}
		else  {
			$item->{audio} .= $film->{Audio}->{AudioFormat}->{'AudioLanguage'};
		}
		###### END AUDIO ######
		####### SUBT #########
		my $subt;
		if (ref ($film->{Subtitles}->{Subtitle}) eq "ARRAY"){
			foreach $subt(@{$film->{Subtitles}->{Subtitle}}){
				$item->{subt} .= $subt.', ';
				
			}
		}
		else {
			$item->{subt} = $film->{Subtitles}->{Subtitle};
		}
		####### END SUBT #########
		####### TYPE #########
		my $type;
		if (ref ($film->{Genres}->{Genre}) eq "ARRAY"){
			foreach $type(@{$film->{Genres}->{Genre}}){
				$item->{type} .= $type.',';
				
			}
		}
		else {
			$item->{type} = $film->{Genres}->{Genre};
		}
		####### END TYPE #########
		
		#$item->{original} = $film->{Title};
		#$item->{subt} = $film->{Subtitles}->{Subtitle};
		#$item->{borrower} = $film->{Title};
		#$item->{lendDate} = $film->{Title};
		#$item->{history} = $film->{Title};
		#$item->{seen} = $film->{Title};# non par defaut ?
		#$item->{comment} = $film->{Title};
		#$item->{image} = $film->{Title};
		#$item->{country} = $film->{Title};
		#$item->{number} = $film->{CollectionNumber};
		#$item->{rating} = $film->{Title};# note par defaut
		#$item->{format} = $film->{Title};#DVD par d�faut ?
		#$item->{webPage} = $film->{Title};
		#$item->{place} = $film->{Title};
		$item->{director} =~ s/, $//;
		$item->{actors} =~ s/, $//;
		$item->{audio} =~ s/, $//;
		$item->{subt} =~ s/, $//;
		$item->{type} =~ s/, $//;
		push @result, $item;
	}
	return \@result;

	}
}

1;