~oivanenko/photostock-helper/db-gladeless

« back to all changes in this revision

Viewing changes to lib/PSH/Photostock/Abstract.pm

  • Committer: oivanenko
  • Date: 2020-01-19 08:11:11 UTC
  • Revision ID: oivanenko@gmail.com-20200119081111-o24szv2pp0aat4wf
* some new stock checks
* Title words counter

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
 
73
73
    my $success = $exifTool->ExtractInfo( out_str( $artifact->full_filename ));
74
74
    #my $info = $exifTool->GetInfo( { Group0 => ['File', 'EXIF', 'ExifIFD', 'XMP-exif'] } );
75
 
        my $info = $exifTool->GetInfo(['FileType', 'ColorSpace', 'ImageWidth', 'ImageHeight'], 
 
75
        my $info = $exifTool->GetInfo(['FileType', 'ColorSpaceData', 'ImageWidth', 'ImageHeight'], 
76
76
                {Verbose => 5,
77
 
                Group0 => ['File']});
 
77
                Group0 => ['File', 'ICC_Profile']});
78
78
        #intercn(sprintf('groups=%s', Dumper([Image::ExifTool::GetAllGroups(0)])));
79
79
        #intercn(sprintf('tags=%s', Dumper([$exifTool->GetFoundTags()])));
80
80
        
81
81
        #intercn(Dumper([$exifTool->GetGroups()]));
82
82
        #intercn(Dumper($info));
 
83
        #intercn(sprintf('$info->{ColorSpaceData}=[%s]', $info->{ColorSpaceData}));
83
84
        
84
85
        interc(sprintf(get_strres('Checking_Artifact_X_X'), $self->title, $artifact->title));
85
 
        #intercn(sprintf('$info->{ColorSpace}=%s', $info->{ColorSpace}));
86
86
        
87
87
        foreach my $row (@{$checks_rows}){
88
 
                my $check_value = uc($row->{check_value});
 
88
                my $check_value = $row->{check_value};
89
89
                
90
90
                #intercn(Dumper($row));
91
91
                #intercn(sprintf('$check_value=%s', $check_value));
97
97
                        $result=0;
98
98
                        last;
99
99
                }
 
100
                        
 
101
                if ( ($row->{check_type} eq 'colorspace')
 
102
                        and ($info->{ColorSpaceData} !~ /$check_value/)){
 
103
                                
 
104
                        intercn;
 
105
                        intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
 
106
                                $info->{ColorSpaceData}, ' equal', $row->{check_value}, $artifact->full_filename));
 
107
                        $result=0;
 
108
                        last;
 
109
        
 
110
                }
100
111
                
101
 
                if ($row->{check_type} eq 'min_resolution'){
 
112
                if(scalar(grep {$row->{check_type} eq $_} qw(min_resolution max_resolution))){
 
113
                        
102
114
                        my $resolution = ceil($info->{ImageWidth} * $info->{ImageHeight} / 1024 /1024);
103
 
                        
104
 
                        #intercn($resolution);
105
 
                        
106
 
                        unless($resolution > $row->{check_value}){
107
 
                                intercn;
108
 
                                intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
109
 
                                $resolution, get_strres('greater_than'), uc($row->{check_value}), $artifact->full_filename));
110
 
                                $result=0;
111
 
                                last;
 
115
                
 
116
                        if ($row->{check_type} eq 'min_resolution'){
 
117
                                
 
118
                                #intercn($resolution);
 
119
                                
 
120
                                unless($resolution > $row->{check_value}){
 
121
                                        intercn;
 
122
                                        intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
 
123
                                        $resolution, get_strres('greater_than'), $row->{check_value}, $artifact->full_filename));
 
124
                                        $result=0;
 
125
                                        last;
 
126
                                }
 
127
                        }
 
128
                
 
129
                        if ($row->{check_type} eq 'max_resolution'){
 
130
                                
 
131
                                #intercn($resolution);
 
132
                                
 
133
                                unless($resolution < $row->{check_value}){
 
134
                                        intercn;
 
135
                                        intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
 
136
                                        $resolution, get_strres('less_than'), $row->{check_value}, $artifact->full_filename));
 
137
                                        $result=0;
 
138
                                        last;
 
139
                                }
112
140
                        }
113
141
                }
114
142
                
142
170
                         }
143
171
                }
144
172
                
 
173
                if ($row->{check_type} eq 'max_title_chars'){
 
174
                        my $chars = length( $artifact->title );
 
175
                        
 
176
                        #intercn(Dumper([@words]));
 
177
                        
 
178
                         if( $chars > $row->{check_value}){
 
179
                                 intercn;
 
180
                                 intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
 
181
                                 $chars, get_strres('less_than'), $row->{check_value}, $artifact->title));
 
182
                                 $result=0;
 
183
                                 last;
 
184
                         }
 
185
                }
 
186
                
 
187
                if(scalar(grep {$row->{check_type} eq $_} qw(max_keywords min_keywords))){
 
188
                        my $keywords = scalar(@{$artifact->keywords});
 
189
                        
 
190
                        #intercn(Dumper([@words]));
 
191
                
 
192
                        if (($row->{check_type} eq 'min_keywords')
 
193
                                and ($keywords < $row->{check_value}) ){
 
194
                                 intercn;
 
195
                                 intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
 
196
                                 $keywords, get_strres('greater_than'), $row->{check_value}, $artifact->title));
 
197
                                 $result=0;
 
198
                                 last;
 
199
                        }
 
200
                
 
201
                        if (($row->{check_type} eq 'max_keywords')
 
202
                                and ($keywords > $row->{check_value}) ){
 
203
                                 intercn;
 
204
                                 intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
 
205
                                 $keywords, get_strres('less_than'), $row->{check_value}, $artifact->title));
 
206
                                 $result=0;
 
207
                                 last;
 
208
                        }
 
209
                }
 
210
                
145
211
                #scalar(grep {$row->{check_type} eq $_} qw(min_quality colorspace))
146
212
                #       and
147
213
                
148
214
                #intercn(Dumper());
149
215
                
150
 
                if( scalar(grep {$row->{check_type} eq $_} qw(min_quality colorspace))){
 
216
                if( scalar(grep {$row->{check_type} eq $_} qw(min_quality))){
151
217
                        if (can_load(modules => { 'Image::Magick' => undef})){
152
218
                        
153
219
                                my $image=Image::Magick->new;
169
235
                                                last;
170
236
                                        }
171
237
                                }
172
 
                        
173
 
                                if ( ($row->{check_type} eq 'colorspace')){
174
 
                                                
175
 
                                        my $colorspace = $image->Get('colorspace');
176
 
                                        
177
 
                                        unless($colorspace =~ /$check_value/){
178
 
                                                
179
 
                                                intercn;
180
 
                                                intercn(sprintf(get_strres('Check_Failed_X_X_X_X'), $row->{check_type}, 
181
 
                                                        $colorspace, ' equal', uc($row->{check_value}), $artifact->full_filename));
182
 
                                                $result=0;
183
 
                                                last;
184
 
                                        }
185
 
                                }
186
238
                        }
187
239
                        else{
 
240
                                intercn;
188
241
                                intercn('Image::Magick not found, check <'.$row->{check_type}.'> skipped.');
189
242
                        }
190
243
                }
208
261
        foreach my $artifact (@$artifacts){
209
262
                #intercn(sprintf('Artifact=%s', $artifact->title));
210
263
                
 
264
                my $local_action_id;
 
265
                
211
266
                my $checks_rows = PSH::DB::get_stock_checks_rows($self->id, 'Image');
212
267
                
213
268
                if ((not @{$checks_rows}) or $self->checks_passed($artifact, $checks_rows)){
221
276
                                        $artifact->id, 
222
277
                                        10 # Ready for upload
223
278
                                );
 
279
                                
 
280
                                if ($artifact_id and PSH::DB::insert_artifact_actions($artifact_id, $action_id)){
 
281
                                        #Add new artifact to current batch
 
282
                                        
 
283
                                        $local_action_id = $action_id;
 
284
                                }
224
285
                        }
225
286
                        else{
226
287
                                # It is artifact from this stock
230
291
                        #intercn(sprintf('$artifact_id=%s', $artifact_id));
231
292
                        
232
293
                        if ($artifact_id
233
 
                                and PSH::DB::insert_artifact_actions($artifact_id, $action_id)
234
 
                                and $self->send_artifact($artifact, $action_id, $artifact_id, $skip_upload)){
 
294
                                and $self->send_artifact($artifact, $local_action_id, $artifact_id, $skip_upload)){
235
295
                                
236
 
                                push (@result, $artifact);
 
296
                                if($local_action_id){
 
297
                                        #Exclude existed in stock pic from new batch
 
298
                                        push (@result, $artifact);
 
299
                                }
237
300
                                
238
301
                        }
239
302
                }