Skip to content

Commit

Permalink
Improve Quicktime Metadata Atom handling
Browse files Browse the repository at this point in the history
  • Loading branch information
nagix committed Mar 23, 2018
1 parent fc8aeb3 commit 716dbf5
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 70 deletions.
35 changes: 31 additions & 4 deletions Source/com/drew/metadata/mov/metadata/QuickTimeDataHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,37 @@ protected void processKeys(@NotNull SequentialByteArrayReader reader) throws IOE
@Override
protected void processData(@NotNull byte[] payload, @NotNull SequentialByteArrayReader reader) throws IOException
{
// 4 bytes: type indicator
int type = reader.getInt32();
// 4 bytes: locale indicator
reader.skip(8);
String value = new String(reader.getBytes(payload.length - 8));
directory.setString(QuickTimeMetadataDirectory._tagIntegerMap.get(keys.get(currentIndex)), value);
reader.skip(4);
Integer tag = QuickTimeMetadataDirectory._tagIntegerMap.get(keys.get(currentIndex));
if (tag != null) {
int length = payload.length - 8;
switch (type) {
case 1:
directory.setString(tag, reader.getString(length, "UTF-8"));
break;
case 13:
case 14:
case 27:
directory.setByteArray(tag, reader.getBytes(length));
break;
case 22:
byte[] buf = new byte[4];
reader.getBytes(buf, 4 - length, length);
directory.setInt(tag, new SequentialByteArrayReader(buf).getInt32());
break;
case 23:
directory.setFloat(tag, reader.getFloat32());
break;
case 30:
int[] value = new int[length / 4];
for (int i = 0; i < value.length; i++) {
value[i] = reader.getInt32();
}
directory.setIntArray(tag, value);
break;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.drew.metadata.mov.QuickTimeDescriptor;
import com.drew.metadata.mov.QuickTimeDirectory;

import static com.drew.metadata.mov.metadata.QuickTimeMetadataDirectory.*;

/**
* @author Payton Garland
*/
Expand All @@ -36,6 +38,27 @@ public QuickTimeMetadataDescriptor(QuickTimeDirectory directory)
@Override
public String getDescription(int tagType)
{
return super.getDescription(tagType);
switch (tagType) {
case TAG_ARTWORK:
return getArtworkDescription();
case TAG_LOCATION_ROLE:
return getLocationRoleDescription();
default:
return super.getDescription(tagType);
}
}

private String getArtworkDescription()
{
return getByteLengthDescription(TAG_ARTWORK);
}

private String getLocationRoleDescription()
{
return getIndexedDescription(TAG_LOCATION_ROLE, 0,
"Shooting location",
"Real location",
"Fictional location"
);
}
}
165 changes: 100 additions & 65 deletions Source/com/drew/metadata/mov/metadata/QuickTimeMetadataDirectory.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@ public class QuickTimeMetadataDirectory extends QuickTimeDirectory
// User Metadata Types Holder (0x0500 - 0x05FF)
// https://developer.apple.com/library/content/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW43
// https://sno.phy.queensu.ca/~phil/exiftool/TagNames/QuickTime.html#Meta
public static final int TAG_ALBUM = 0x0500;
public static final int TAG_ARTIST = 0x0501;
public static final int TAG_ARTWORK = 0x0502;
public static final int TAG_AUTHOR = 0x0503;
public static final int TAG_COMMENT = 0x0504;
public static final int TAG_COPYRIGHT = 0x0505;
public static final int TAG_CREATION_DATE = 0x0506;
public static final int TAG_DESCRIPTION = 0x0507;
public static final int TAG_DIRECTOR = 0x0508;
public static final int TAG_TITLE = 0x0509;
public static final int TAG_GENRE = 0x050A;
public static final int TAG_INFORMATION = 0x050B;
public static final int TAG_KEYWORDS = 0x050C;
public static final int TAG_LOCATION_ISO6709 = 0x050D;
public static final int TAG_PRODUCER = 0x050E;
public static final int TAG_PUBLISHER = 0x050F;
public static final int TAG_SOFTWARE = 0x0510;
public static final int TAG_YEAR = 0x0511;
public static final int TAG_COLLECTION_USER = 0x0512;
public static final int TAG_RATING_USER = 0x0513;
public static final int TAG_LOCATION_NAME = 0x0514;
public static final int TAG_LOCATION_BODY = 0x0515;
public static final int TAG_LOCATION_NOTE = 0x0516;
public static final int TAG_LOCATION_ROLE = 0x0517;
public static final int TAG_LOCATION_DATE = 0x0518;
public static final int TAG_DIRECTION_FACING = 0x0519;
public static final int TAG_DIRECTION_MOTION = 0x051A;
public static final int TAG_DISPLAY_NAME = 0x051B;
public static final int TAG_CONTENT_IDENTIFIER = 0x051C;
public static final int TAG_MAKE = 0x051D;
public static final int TAG_MODEL = 0x051E;
public static final int TAG_ORIGINATING_SIGNATURE = 0x051F;
public static final int TAG_PIXEL_DENSITY = 0x0520;

public QuickTimeMetadataDirectory()
{
Expand All @@ -50,38 +83,39 @@ public QuickTimeMetadataDirectory()

static
{
_tagIntegerMap.put("com.apple.quicktime.album", 0x0500);
_tagIntegerMap.put("com.apple.quicktime.artist", 0x0501);
_tagIntegerMap.put("com.apple.quicktime.artwork", 0x0502);
_tagIntegerMap.put("com.apple.quicktime.author", 0x0503);
_tagIntegerMap.put("com.apple.quicktime.comment", 0x0504);
_tagIntegerMap.put("com.apple.quicktime.copyright", 0x0505);
_tagIntegerMap.put("com.apple.quicktime.creationdate", 0x0506);
_tagIntegerMap.put("com.apple.quicktime.description", 0x0507);
_tagIntegerMap.put("com.apple.quicktime.director", 0x0508);
_tagIntegerMap.put("com.apple.quicktime.title", 0x0509);
_tagIntegerMap.put("com.apple.quicktime.genre", 0x050A);
_tagIntegerMap.put("com.apple.quicktime.information", 0x050B);
_tagIntegerMap.put("com.apple.quicktime.keywords", 0x050C);
_tagIntegerMap.put("com.apple.quicktime.location.ISO6709", 0x050D);
_tagIntegerMap.put("com.apple.quicktime.producer", 0x050E);
_tagIntegerMap.put("com.apple.quicktime.publisher", 0x050F);
_tagIntegerMap.put("com.apple.quicktime.software", 0x0510);
_tagIntegerMap.put("com.apple.quicktime.year", 0x0511);
_tagIntegerMap.put("com.apple.quicktime.collection.user", 0x0512);
_tagIntegerMap.put("com.apple.quicktime.rating.user", 0x0513);
_tagIntegerMap.put("com.apple.quicktime.location.name", 0x0514);
_tagIntegerMap.put("com.apple.quicktime.location.body", 0x0515);
_tagIntegerMap.put("com.apple.quicktime.location.note", 0x0516);
_tagIntegerMap.put("com.apple.quicktime.location.role", 0x0517);
_tagIntegerMap.put("com.apple.quicktime.location.date", 0x0518);
_tagIntegerMap.put("com.apple.quicktime.direction.facing", 0x0519);
_tagIntegerMap.put("com.apple.quicktime.direction.motion", 0x051A);
_tagIntegerMap.put("com.apple.quicktime.displayname", 0x051B);
_tagIntegerMap.put("com.apple.quicktime.content.identifier", 0x051C);
_tagIntegerMap.put("com.apple.quicktime.make", 0x051D);
_tagIntegerMap.put("com.apple.quicktime.model", 0x051E);
_tagIntegerMap.put("com.apple.photos.originating.signature", 0x051F);
_tagIntegerMap.put("com.apple.quicktime.album", TAG_ALBUM);
_tagIntegerMap.put("com.apple.quicktime.artist", TAG_ARTIST);
_tagIntegerMap.put("com.apple.quicktime.artwork", TAG_ARTWORK);
_tagIntegerMap.put("com.apple.quicktime.author", TAG_AUTHOR);
_tagIntegerMap.put("com.apple.quicktime.comment", TAG_COMMENT);
_tagIntegerMap.put("com.apple.quicktime.copyright", TAG_COPYRIGHT);
_tagIntegerMap.put("com.apple.quicktime.creationdate", TAG_CREATION_DATE);
_tagIntegerMap.put("com.apple.quicktime.description", TAG_DESCRIPTION);
_tagIntegerMap.put("com.apple.quicktime.director", TAG_DIRECTOR);
_tagIntegerMap.put("com.apple.quicktime.title", TAG_TITLE);
_tagIntegerMap.put("com.apple.quicktime.genre", TAG_GENRE);
_tagIntegerMap.put("com.apple.quicktime.information", TAG_INFORMATION);
_tagIntegerMap.put("com.apple.quicktime.keywords", TAG_KEYWORDS);
_tagIntegerMap.put("com.apple.quicktime.location.ISO6709", TAG_LOCATION_ISO6709);
_tagIntegerMap.put("com.apple.quicktime.producer", TAG_PRODUCER);
_tagIntegerMap.put("com.apple.quicktime.publisher", TAG_PUBLISHER);
_tagIntegerMap.put("com.apple.quicktime.software", TAG_SOFTWARE);
_tagIntegerMap.put("com.apple.quicktime.year", TAG_YEAR);
_tagIntegerMap.put("com.apple.quicktime.collection.user", TAG_COLLECTION_USER);
_tagIntegerMap.put("com.apple.quicktime.rating.user", TAG_RATING_USER);
_tagIntegerMap.put("com.apple.quicktime.location.name", TAG_LOCATION_NAME);
_tagIntegerMap.put("com.apple.quicktime.location.body", TAG_LOCATION_BODY);
_tagIntegerMap.put("com.apple.quicktime.location.note", TAG_LOCATION_NOTE);
_tagIntegerMap.put("com.apple.quicktime.location.role", TAG_LOCATION_ROLE);
_tagIntegerMap.put("com.apple.quicktime.location.date", TAG_LOCATION_DATE);
_tagIntegerMap.put("com.apple.quicktime.direction.facing", TAG_DIRECTION_FACING);
_tagIntegerMap.put("com.apple.quicktime.direction.motion", TAG_DIRECTION_MOTION);
_tagIntegerMap.put("com.apple.quicktime.displayname", TAG_DISPLAY_NAME);
_tagIntegerMap.put("com.apple.quicktime.content.identifier", TAG_CONTENT_IDENTIFIER);
_tagIntegerMap.put("com.apple.quicktime.make", TAG_MAKE);
_tagIntegerMap.put("com.apple.quicktime.model", TAG_MODEL);
_tagIntegerMap.put("com.apple.photos.originating.signature", TAG_ORIGINATING_SIGNATURE);
_tagIntegerMap.put("com.apple.quicktime.pixeldensity", TAG_PIXEL_DENSITY);

_tagIntegerMap.put("----", 0x0400);
_tagIntegerMap.put("@PST", 0x0401);
Expand Down Expand Up @@ -166,39 +200,40 @@ public QuickTimeMetadataDirectory()
_tagIntegerMap.put("�trk", 0x0450);
_tagIntegerMap.put("�wrt", 0x0451);

_tagNameMap.put(0x0500, "Album");
_tagNameMap.put(0x0501, "Artist");
_tagNameMap.put(0x0502, "Artwork");
_tagNameMap.put(0x0503, "Author");
_tagNameMap.put(0x0504, "Comment");
_tagNameMap.put(0x0505, "Copyright");
_tagNameMap.put(0x0506, "Creation Date");
_tagNameMap.put(0x0507, "Description");
_tagNameMap.put(0x0508, "Director");
_tagNameMap.put(0x0509, "Title");
_tagNameMap.put(0x050A, "Genre");
_tagNameMap.put(0x050B, "Information");
_tagNameMap.put(0x050C, "Keywords");
_tagNameMap.put(0x050D, "ISO 6709");
_tagNameMap.put(0x050E, "Producer");
_tagNameMap.put(0x050F, "Publisher");
_tagNameMap.put(0x0510, "Software");
_tagNameMap.put(0x0511, "Year");
_tagNameMap.put(0x0512, "Collection User");
_tagNameMap.put(0x0513, "Rating User");
_tagNameMap.put(0x0514, "Location Name");
_tagNameMap.put(0x0515, "Location Body");
_tagNameMap.put(0x0516, "Location Note");
_tagNameMap.put(0x0517, "Location Role");
_tagNameMap.put(0x0518, "Location Date");
_tagNameMap.put(0x0519, "Direction Facing");
_tagNameMap.put(0x051A, "Direction Motion");
_tagNameMap.put(0x051B, "Display Name");
_tagNameMap.put(0x051C, "Content Identifier");
_tagNameMap.put(0x051D, "Make");
_tagNameMap.put(0x051E, "Model");
_tagNameMap.put(0x051F, "Originating Signature");

_tagNameMap.put(TAG_ALBUM, "Album");
_tagNameMap.put(TAG_ARTIST, "Artist");
_tagNameMap.put(TAG_ARTWORK, "Artwork");
_tagNameMap.put(TAG_AUTHOR, "Author");
_tagNameMap.put(TAG_COMMENT, "Comment");
_tagNameMap.put(TAG_COPYRIGHT, "Copyright");
_tagNameMap.put(TAG_CREATION_DATE, "Creation Date");
_tagNameMap.put(TAG_DESCRIPTION, "Description");
_tagNameMap.put(TAG_DIRECTOR, "Director");
_tagNameMap.put(TAG_TITLE, "Title");
_tagNameMap.put(TAG_GENRE, "Genre");
_tagNameMap.put(TAG_INFORMATION, "Information");
_tagNameMap.put(TAG_KEYWORDS, "Keywords");
_tagNameMap.put(TAG_LOCATION_ISO6709, "ISO 6709");
_tagNameMap.put(TAG_PRODUCER, "Producer");
_tagNameMap.put(TAG_PUBLISHER, "Publisher");
_tagNameMap.put(TAG_SOFTWARE, "Software");
_tagNameMap.put(TAG_YEAR, "Year");
_tagNameMap.put(TAG_COLLECTION_USER, "Collection User");
_tagNameMap.put(TAG_RATING_USER, "Rating User");
_tagNameMap.put(TAG_LOCATION_NAME, "Location Name");
_tagNameMap.put(TAG_LOCATION_BODY, "Location Body");
_tagNameMap.put(TAG_LOCATION_NOTE, "Location Note");
_tagNameMap.put(TAG_LOCATION_ROLE, "Location Role");
_tagNameMap.put(TAG_LOCATION_DATE, "Location Date");
_tagNameMap.put(TAG_DIRECTION_FACING, "Direction Facing");
_tagNameMap.put(TAG_DIRECTION_MOTION, "Direction Motion");
_tagNameMap.put(TAG_DISPLAY_NAME, "Display Name");
_tagNameMap.put(TAG_CONTENT_IDENTIFIER, "Content Identifier");
_tagNameMap.put(TAG_MAKE, "Make");
_tagNameMap.put(TAG_MODEL, "Model");
_tagNameMap.put(TAG_ORIGINATING_SIGNATURE, "Originating Signature");
_tagNameMap.put(TAG_PIXEL_DENSITY, "Pixel Density");

_tagNameMap.put(0x0400, "iTunes Info");
_tagNameMap.put(0x0401, "Parent Short Title");
_tagNameMap.put(0x0402, "Parent Product ID");
Expand Down

0 comments on commit 716dbf5

Please sign in to comment.