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

#################################################################################
# 
#  Created by Rob Maas rob@progob.nl | http://www.robmaas.eu (2008)
#	
# 
#  This file is strongly based op the already existing DVDProfiler
#  import class. It is also my first perl script :-)
#
#  Since MyMovies has some different fields then GCStar, there are some work
#  arounds to get as much of the original data.
#
#  If the field ExtraFeatures is filled, it will appear in the General tab in 
#  the synopsis.
#
#  The rating system will be calculated back to the Dutch rating system.
#
#  If data was imported from IMDB, the webpage button will link to the specific
#  movie site on IMDB.
#
#  Cause GCstar hasn´t (yet?) a real EAN field, the EAN code is placed on the
#  details tab under comments.
#
#  Special thanks goes to Tian who helped me with some array trouble :-P and
#  for creating this software.
#
#################################################################################

use strict;
use GCImport::GCImportBase;

{
    package GCImport::GCImporterMyMovies;

    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 "MyMovies (.xml)";
    }
    
    sub getOptions
    {
        my $self = shift;
        my @options;
        return \@options;
    }
    
    sub getFilePatterns
    {
       return (['MyMovies (.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;
	# Creates an object / Skip empty ellements
	$xml = new XML::Simple(suppressempty => 1);
	$data = $xml->XMLin ("$file");
	
	my @result; 
	my $film;

	# For each "Title" in the XML file
	foreach $film(@{$data->{Title}}){
		my $item;
		
		#General fields			   		
		$item->{title} = $film->{LocalTitle};
		$item->{original} = $film->{OriginalTitle};
		$item->{date} = $film->{ProductionYear};
		$item->{time} = $film->{RunningTime}.' min';
		$item->{synopsis} = $film->{Description};
		
		#Extra's on the disc
		if ($film->{ExtraFeatures}->{content}){
			$item->{synopsis} .= "\n\nEXTRA\n";
			$item->{synopsis} .= $film->{ExtraFeatures}->{content};
		}
		
		#Based on the Dutch ratings!
		
		$item->{age} = 
		   ($film->{ParentalRating}->{Value} == 1) ? 1
		 : ($film->{ParentalRating}->{Value} == 2) ? 2
		 : ($film->{ParentalRating}->{Value} == 3) ? 5
		 : ($film->{ParentalRating}->{Value} == 4) ? 12
		 :                                           16;
	
		if ($film->{DataProvider} eq 'IMDB.com'){
			$item->{webPage} = 'http://www.imdb.com/title/'.$film->{DataProviderId};
		}	
		$item->{country} = $film->{Country};
		
		###### GENRE #########
		my $type;
		if (ref ($film->{Genres}->{Genre}) eq "ARRAY"){
			foreach $type(@{$film->{Genres}->{Genre}}){				
				$item->{genre} .= $type.',';
			}
		}		
		else{
			$item->{genre} = $film->{Genres}->{Genre};
		}
		###### END GENRE #########	
		####### DIRECTOR AND ACTORS #########
		my $actor;
		if (ref ($film->{Persons}->{Person}) eq "ARRAY") {
			foreach $actor(@{$film->{Persons}->{Person}}){
				if ($actor->{Type} eq 'Director'){
					$item->{director} = $actor->{Name};
				}
				else{
					$item->{actors}.= $actor->{Name}.' ('.$actor->{Role}.'), ';
				}
			}
		}
		else{
			$item->{actors}.= $film->{Persons}->{Person}->{Name}.' ('.$film->{Persons}->{Person}->{Role}.')';
		}
		###### END DIRECTOR AND ACTORS ######
	
		##DETAIL
		$item->{format} = $film->{Type};
		$item->{video} = $film->{VideoStandard};
		$item->{added} = $film->{Added};
		$item->{identifier} = $film->{CollectionNumber};

		#Temporately cause a real barcode field is missing
		if (length($film->{Barcode}) gt 0){
			$item->{comment} = 'EAN: '.$film->{Barcode};
		}
			
		###### AUDIO #########
		my $audio;
		my @audioTracks;
		if (ref ($film->{AudioTracks}->{AudioTrack}) eq "ARRAY"){
			foreach $audio(@{$film->{AudioTracks}->{AudioTrack}}){
				push @audioTracks, [$audio->{Language}, $audio->{Type}.' '.$audio->{Channels}];
			}
			$item->{audio} = \@audioTracks;
		}
		else{
			$item->{audio} = [[$audio->{Language}, $audio->{Type}]];
		}
		###### END AUDIO #########
		###### SUBTITLES #########
		my $subt;
		if (ref ($film->{Subtitles}->{Subtitle}) eq "ARRAY"){
			foreach $subt(@{$film->{Subtitles}->{Subtitle}}){
				$item->{subt} .= $subt->{Language}.',';
			}
		}
		else{
			$item->{subt} = $subt->{Language};
		}
		###### END SUBTITLES #########
	
		#$item->{borrower} = $film->{Title};
		#$item->{lendDate} = $film->{Title};
		#$item->{history} = $film->{Title};
		#$item->{seen} = $film->{Title};# non par defaut ?
		#$item->{image} = $film->{Title};
		#$item->{number} = $film->{CollectionNumber};
		#$item->{rating} = $film->{Title};# note par defaut
		#$item->{place} = $film->{Title};	
		
		$item->{director} =~ s/, $//;
		$item->{actors} =~ s/, $//;
		$item->{audio} =~ s/, $//;
		$item->{subt} =~ s/, $//;
		$item->{genre} =~ s/, $//;
		push @result, $item;
	}
	return \@result;

	}
}

1;