Catalog metadata: check xmp title/description to set title

This commit is contained in:
Thibault Deckers 2020-04-02 10:09:57 +09:00
parent e13db0dc43
commit 805b0ef51f
5 changed files with 30 additions and 10 deletions

View file

@ -43,6 +43,10 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
private static final String XMP_DC_SCHEMA_NS = "http://purl.org/dc/elements/1.1/";
private static final String XMP_SUBJECT_PROP_NAME = "dc:subject";
private static final String XMP_TITLE_PROP_NAME = "dc:title";
private static final String XMP_DESCRIPTION_PROP_NAME = "dc:description";
private static final String XMP_GENERIC_LANG = "";
private static final String XMP_SPECIFIC_LANG = "en-US";
private static final Pattern videoLocationPattern = Pattern.compile("([+-][.0-9]+)([+-][.0-9]+)/?");
private Context context;
@ -207,6 +211,13 @@ public class MetadataHandler implements MethodChannel.MethodCallHandler {
}
metadataMap.put("xmpSubjects", sb.toString());
}
if (xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, XMP_TITLE_PROP_NAME)) {
XMPProperty item = xmpMeta.getLocalizedText(XMP_DC_SCHEMA_NS, XMP_TITLE_PROP_NAME, XMP_GENERIC_LANG, XMP_SPECIFIC_LANG);
metadataMap.put("xmpTitleDescription", item.getValue());
} else if (xmpMeta.doesPropertyExist(XMP_DC_SCHEMA_NS, XMP_DESCRIPTION_PROP_NAME)) {
XMPProperty item = xmpMeta.getLocalizedText(XMP_DC_SCHEMA_NS, XMP_DESCRIPTION_PROP_NAME, XMP_GENERIC_LANG, XMP_SPECIFIC_LANG);
metadataMap.put("xmpTitleDescription", item.getValue());
}
} catch (XMPException e) {
e.printStackTrace();
}

View file

@ -21,7 +21,7 @@ class ImageEntry {
int height;
int orientationDegrees;
final int sizeBytes;
String title;
String sourceTitle;
final int dateModifiedSecs;
final int sourceDateTakenMillis;
final String bucketDisplayName;
@ -41,7 +41,7 @@ class ImageEntry {
this.height,
this.orientationDegrees,
this.sizeBytes,
this.title,
this.sourceTitle,
this.dateModifiedSecs,
this.sourceDateTakenMillis,
this.bucketDisplayName,
@ -60,7 +60,7 @@ class ImageEntry {
height: map['height'] as int,
orientationDegrees: map['orientationDegrees'] as int,
sizeBytes: map['sizeBytes'] as int,
title: map['title'] as String,
sourceTitle: map['title'] as String,
dateModifiedSecs: map['dateModifiedSecs'] as int,
sourceDateTakenMillis: map['sourceDateTakenMillis'] as int,
bucketDisplayName: map['bucketDisplayName'] as String,
@ -78,7 +78,7 @@ class ImageEntry {
'height': height,
'orientationDegrees': orientationDegrees,
'sizeBytes': sizeBytes,
'title': title,
'title': sourceTitle,
'dateModifiedSecs': dateModifiedSecs,
'sourceDateTakenMillis': sourceDateTakenMillis,
'bucketDisplayName': bucketDisplayName,
@ -157,6 +157,11 @@ class ImageEntry {
List<String> get xmpSubjects => catalogMetadata?.xmpSubjects?.split(';')?.where((tag) => tag.isNotEmpty)?.toList() ?? [];
String get title {
if (catalogMetadata != null && catalogMetadata.xmpTitleDescription.isNotEmpty) return catalogMetadata.xmpTitleDescription;
return sourceTitle;
}
Future<void> catalog() async {
if (isCatalogued) return;
catalogMetadata = await MetadataService.getCatalogMetadata(this);
@ -223,8 +228,8 @@ class ImageEntry {
if (path is String) this.path = path;
final contentId = newFields['contentId'];
if (contentId is int) this.contentId = contentId;
final title = newFields['title'];
if (title is String) this.title = title;
final sourceTitle = newFields['sourceTitle'];
if (sourceTitle is String) this.sourceTitle = sourceTitle;
metadataChangeNotifier.notifyListeners();
return true;
}

View file

@ -3,7 +3,7 @@ import 'package:geocoder/model.dart';
class CatalogMetadata {
final int contentId, dateMillis, videoRotation;
final String xmpSubjects;
final String xmpSubjects, xmpTitleDescription;
final double latitude, longitude;
Address address;
@ -12,6 +12,7 @@ class CatalogMetadata {
this.dateMillis,
this.videoRotation,
this.xmpSubjects,
this.xmpTitleDescription,
double latitude,
double longitude,
})
@ -25,6 +26,7 @@ class CatalogMetadata {
dateMillis: map['dateMillis'] ?? 0,
videoRotation: map['videoRotation'] ?? 0,
xmpSubjects: map['xmpSubjects'] ?? '',
xmpTitleDescription: map['xmpTitleDescription'] ?? '',
latitude: map['latitude'],
longitude: map['longitude'],
);
@ -35,13 +37,14 @@ class CatalogMetadata {
'dateMillis': dateMillis,
'videoRotation': videoRotation,
'xmpSubjects': xmpSubjects,
'xmpTitleDescription': xmpTitleDescription,
'latitude': latitude,
'longitude': longitude,
};
@override
String toString() {
return 'CatalogMetadata{contentId=$contentId, dateMillis=$dateMillis, videoRotation=$videoRotation, latitude=$latitude, longitude=$longitude, xmpSubjects=$xmpSubjects}';
return 'CatalogMetadata{contentId=$contentId, dateMillis=$dateMillis, videoRotation=$videoRotation, latitude=$latitude, longitude=$longitude, xmpSubjects=$xmpSubjects, xmpTitleDescription=$xmpTitleDescription}';
}
}

View file

@ -23,7 +23,7 @@ class MetadataDb {
_database = openDatabase(
await path,
onCreate: (db, version) async {
await db.execute('CREATE TABLE $metadataTable(contentId INTEGER PRIMARY KEY, dateMillis INTEGER, videoRotation INTEGER, xmpSubjects TEXT, latitude REAL, longitude REAL)');
await db.execute('CREATE TABLE $metadataTable(contentId INTEGER PRIMARY KEY, dateMillis INTEGER, videoRotation INTEGER, xmpSubjects TEXT, xmpTitleDescription TEXT, latitude REAL, longitude REAL)');
await db.execute('CREATE TABLE $addressTable(contentId INTEGER PRIMARY KEY, addressLine TEXT, countryName TEXT, adminArea TEXT, locality TEXT)');
await db.execute('CREATE TABLE $favouriteTable(contentId INTEGER PRIMARY KEY, path TEXT)');
},

View file

@ -31,7 +31,8 @@ class MetadataService {
// 'dateMillis': date taken in milliseconds since Epoch (long)
// 'latitude': latitude (double)
// 'longitude': longitude (double)
// 'xmpSubjects': space separated XMP subjects (string)
// 'xmpSubjects': ';' separated XMP subjects (string)
// 'xmpTitleDescription': XMP title or XMP description (string)
final result = await platform.invokeMethod('getCatalogMetadata', <String, dynamic>{
'mimeType': entry.mimeType,
'path': entry.path,