Debian Codegraph @

src/com/drew/metadata/mov/QuickTimeDescriptor.java

raw symbols SCIP
1 /*
2 * Copyright 2002-2019 Drew Noakes and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21 package com.drew.metadata.mov;
22
23 import com.drew.lang.Rational;
24 import com.drew.lang.annotations.NotNull;
25 import com.drew.metadata.TagDescriptor;
26
27 import java.util.ArrayList;
28 import java.util.Arrays;
29
30 import static com.drew.metadata.mov.QuickTimeDirectory.*;
31
32 /**
33 * @author Payton Garland
34 */
35 public class QuickTimeDescriptor extends TagDescriptor<QuickTimeDirectory> {
36
37 public QuickTimeDescriptor(@NotNull QuickTimeDirectory directory)
38 {
39 super(directory);
40 }
41
42 @Override
43 public String getDescription(int tagType)
44 {
45 switch (tagType) {
46 case TAG_MAJOR_BRAND:
47 return getMajorBrandDescription();
48 case TAG_COMPATIBLE_BRANDS:
49 return getCompatibleBrandsDescription();
50 case TAG_DURATION_SECONDS:
51 return getDurationDescription();
52 default:
53 return super.getDescription(tagType);
54 }
55 }
56
57 private String getMajorBrandDescription()
58 {
59 byte[] value = _directory.getByteArray(QuickTimeDirectory.TAG_MAJOR_BRAND);
60 if (value == null)
61 return null;
62 return QuickTimeDictionary.lookup(TAG_MAJOR_BRAND, new String(value));
63 }
64
65 private String getCompatibleBrandsDescription()
66 {
67 String[] values = _directory.getStringArray(QuickTimeDirectory.TAG_COMPATIBLE_BRANDS);
68 if (values == null)
69 return null;
70
71 ArrayList<String> compatibleBrandsValues = new ArrayList<String>();
72 for (String value : values) {
73 String compatibleBrandsValue = QuickTimeDictionary.lookup(TAG_MAJOR_BRAND, value);
74 compatibleBrandsValues.add(compatibleBrandsValue == null ? value : compatibleBrandsValue);
75 }
76 return Arrays.toString(compatibleBrandsValues.toArray());
77 }
78
79 private String getDurationDescription()
80 {
81 Rational duration = _directory.getRational(TAG_DURATION_SECONDS);
82 if (duration == null)
83 return null;
84
85 double value = duration.doubleValue();
86 Integer hours = (int)(value / (Math.pow(60, 2)));
87 Integer minutes = (int)((value / (Math.pow(60, 1))) - (hours * 60));
88 Integer seconds = (int)Math.ceil((value / (Math.pow(60, 0))) - (minutes * 60));
89 return String.format("%1$02d:%2$02d:%3$02d", hours, minutes, seconds);
90 }
91 }