Skip to contentMethod: accept(MetadataWithPath)
1: /*
2: * *********************************************************************************************************************
3: *
4: * blueMarine II: Semantic Media Centre
5: * http://tidalwave.it/projects/bluemarine2
6: *
7: * Copyright (C) 2015 - 2021 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *********************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
12: * the License. You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
17: * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations under the License.
19: *
20: * *********************************************************************************************************************
21: *
22: * git clone https://bitbucket.org/tidalwave/bluemarine2-src
23: * git clone https://github.com/tidalwave-it/bluemarine2-src
24: *
25: * *********************************************************************************************************************
26: */
27: package it.tidalwave.bluemarine2.mediascanner.impl.tika;
28:
29: import javax.annotation.Nonnull;
30: import java.util.ArrayList;
31: import java.util.List;
32: import java.util.Properties;
33: import java.util.SortedMap;
34: import java.util.TreeMap;
35: import java.util.concurrent.atomic.AtomicInteger;
36: import java.util.function.Consumer;
37: import java.io.IOException;
38: import java.io.Reader;
39: import java.nio.file.Files;
40: import java.nio.file.Path;
41: import com.healthmarketscience.jackcess.RuntimeIOException;
42: import lombok.Getter;
43: import lombok.extern.slf4j.Slf4j;
44:
45: /***********************************************************************************************************************
46: *
47: * This is more a tool required by the author at a certain point than effective code of BM, but it can be thought as a
48: * test.
49: *
50: * @author Fabrizio Giudici
51: *
52: **********************************************************************************************************************/
53: @Slf4j
54: public class LensChecker implements Consumer<MetadataWithPath>
55: {
56: private final Properties nameNormalisationMap = new Properties();
57:
58: @Getter
59: private final SortedMap<String, AtomicInteger> statistics = new TreeMap<>();
60:
61: /*******************************************************************************************************************
62: *
63: ******************************************************************************************************************/
64: public LensChecker()
65: {
66: try (final Reader r = Files.newBufferedReader(Path.of("src/main/resources/Lens.properties")))
67: {
68: nameNormalisationMap.load(r);
69: }
70: catch (IOException e)
71: {
72: throw new RuntimeIOException(e);
73: }
74: }
75:
76: /*******************************************************************************************************************
77: *
78: ******************************************************************************************************************/
79: @Override
80: public void accept (@Nonnull final MetadataWithPath metadata)
81: {
82: try
83: {
84: final List<String> errors = new ArrayList<>();
85: String lensModel = metadata.getMeta().get("aux:Lens"); // .get("Exif SubIFD:Lens Model");
86: String lensInfo = metadata.getMeta().get("exifEX:LensModel"); // ("Exif SubIFD:Lens Specification")
87:
88:• if (lensInfo == null)
89: {
90: lensInfo = metadata.getMeta().get("aux:LensInfo");
91: }
92:
93:• if (lensModel == null)
94: {
95: errors.add("Null lensModel");
96: }
97:• else if (lensInfo == null)
98: {
99: errors.add("Null lensInfo");
100: }
101:• else if (!lensInfo.equals(lensModel))
102: {
103: final String mapped = (String)nameNormalisationMap.get(lensInfo);
104:
105:• if (mapped == null)
106: {
107: errors.add("Unmapped: " + lensInfo + " vs " + lensModel);
108: }
109:• else if (!mapped.equals(lensModel))
110: {
111: errors.add("Mismatch: " + lensInfo + " vs " + lensModel);
112: }
113: }
114:
115:• if (lensModel == null)
116: {
117: lensModel = "*missing*";
118: }
119:
120: statistics.computeIfAbsent(lensModel, __ -> new AtomicInteger(0)).incrementAndGet();
121:
122:• if (!errors.isEmpty())
123: {
124: log.debug(" LENS: {}: {}", metadata.getPath().getFileName().toString(), errors);
125: }
126:
127: // log.debug(" {} LENS {} --- {}", metadata.getPath().getFileName().toString(), lensModel, lensInfo);
128: }
129: catch (Exception e)
130: {
131: log.warn(" {}", e.toString());
132: }
133: }
134: }