Debian Codegraph @

src/com/drew/metadata/mp4/Mp4Descriptor.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.mp4;
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.mp4.Mp4Directory.*;
31
32 public class Mp4Descriptor extends TagDescriptor<Mp4Directory> {
33
34 public Mp4Descriptor(@NotNull Mp4Directory directory)
35 {
36 super(directory);
37 }
38
39 @Override
40 public String getDescription(int tagType)
41 {
42 switch (tagType) {
43 case TAG_MAJOR_BRAND:
44 return getMajorBrandDescription();
45 case TAG_COMPATIBLE_BRANDS:
46 return getCompatibleBrandsDescription();
47 case TAG_DURATION_SECONDS:
48 return getDurationDescription();
49 default:
50 return _directory.getString(tagType);
51 }
52 }
53
54 private String getMajorBrandDescription()
55 {
56 byte[] value = _directory.getByteArray(Mp4Directory.TAG_MAJOR_BRAND);
57 if (value == null)
58 return null;
59 return Mp4Dictionary.lookup(TAG_MAJOR_BRAND, new String(value));
60 }
61
62 private String getCompatibleBrandsDescription()
63 {
64 String[] values = _directory.getStringArray(Mp4Directory.TAG_COMPATIBLE_BRANDS);
65 if (values == null)
66 return null;
67
68 ArrayList<String> compatibleBrandsValues = new ArrayList<String>();
69 for (String value : values) {
70 String compatibleBrandsValue = Mp4Dictionary.lookup(TAG_MAJOR_BRAND, value);
71 compatibleBrandsValues.add(compatibleBrandsValue == null ? value : compatibleBrandsValue);
72 }
73 return Arrays.toString(compatibleBrandsValues.toArray());
74 }
75
76 private String getDurationDescription()
77 {
78 Rational duration = _directory.getRational(TAG_DURATION_SECONDS);
79 if (duration == null)
80 return null;
81
82 double value = duration.doubleValue();
83 Integer hours = (int)(value / (Math.pow(60, 2)));
84 Integer minutes = (int)((value / (Math.pow(60, 1))) - (hours * 60));
85 Integer seconds = (int)Math.ceil((value / (Math.pow(60, 0))) - (minutes * 60));
86 return String.format("%1$02d:%2$02d:%3$02d", hours, minutes, seconds);
87 }
88 }