Rework the way MP42Metadata work.

This commit is contained in:
Damiano Galassi committed 2016-10-10 10:31:37 +02:00
1 parent b524eab915
commit 747ffcc790
12 files changed
+897 -1015

No files matched your search

+9 -8
View File
@@ -372,7 +372,8 @@
if ([artworkData isKindOfClass:[NSData class]]) {
NSImage *image = [[NSImage alloc] initWithData:artworkData];
[self.metadata.artworks addObject:[[[MP42Image alloc] initWithImage:image] autorelease]];
// FIXME
//[self.metadata.artworks addObject:[[[MP42Image alloc] initWithImage:image] autorelease]];
[image release];
}
}
@@ -459,7 +460,7 @@
for (NSString *itunesKey in itunesMetadataDict.allKeys) {
items = [AVMetadataItem metadataItemsFromArray:itunesMetadata withKey:itunesKey keySpace:nil];
if (items.count) {
self.metadata[itunesMetadataDict[itunesKey]] = items.lastObject.value;
[self.metadata setTag:items.lastObject.value forKey:itunesMetadataDict[itunesKey]];
}
}
@@ -473,27 +474,27 @@
format:nil error:NULL];
NSString *value;
if ([value = [self stringFromArray:dma[@"cast"] key:@"name"] length]) {
self.metadata[MP42MetadataKeyCast] = value;
[self.metadata setTag:value forKey:MP42MetadataKeyCast];
}
if ([value = [self stringFromArray:dma[@"directors"] key:@"name"] length]) {
self.metadata[MP42MetadataKeyDirector] = value;
[self.metadata setTag:value forKey:MP42MetadataKeyDirector];
}
if ([value = [self stringFromArray:dma[@"codirectors"] key:@"name"] length]) {
self.metadata[MP42MetadataKeyCodirector] = value;
[self.metadata setTag:value forKey:MP42MetadataKeyCodirector];
}
if ([value = [self stringFromArray:dma[@"producers"] key:@"name"] length]) {
self.metadata[MP42MetadataKeyProducer] = value;
[self.metadata setTag:value forKey:MP42MetadataKeyProducer];
}
if ([value = [self stringFromArray:dma[@"screenwriters"] key:@"name"] length]) {
self.metadata[MP42MetadataKeyScreenwriters] = value;
[self.metadata setTag:value forKey:MP42MetadataKeyScreenwriters];
}
if ([value = dma[@"studio"] length]) {
self.metadata[MP42MetadataKeyStudio] = value;
[self.metadata setTag:value forKey:MP42MetadataKeyStudio];
}
}
}
+1 -3
View File
@@ -861,9 +861,7 @@ static void logCallback(MP4LogLevel loglevel, const char *fmt, va_list ap) {
[tracksToUpdate release];
// Update metadata
if (self.metadata.isEdited) {
[self.metadata writeMetadataWithFileHandle:self.fileHandle];
}
[self.metadata writeMetadataWithFileHandle:self.fileHandle];
// Close the mp4 file handle
if (![self stopWriting]) {
+2 -2
View File
@@ -10,8 +10,8 @@ NS_ASSUME_NONNULL_BEGIN
@interface MP42Metadata (Private)
- (instancetype) initWithFileHandle:(MP42FileHandle)fileHandle;
- (BOOL) writeMetadataWithFileHandle: (MP42FileHandle) fileHandle;
- (instancetype)initWithFileHandle:(MP42FileHandle)fileHandle;
- (void)writeMetadataWithFileHandle:(MP42FileHandle)fileHandle;
@end
+26 -139
View File
@@ -7,118 +7,10 @@
//
#import <Foundation/Foundation.h>
#import "MP42MetadataItem.h"
NS_ASSUME_NONNULL_BEGIN
@class MP42Image;
// Common Metadata keys
extern NSString *const MP42MetadataKeyName;
extern NSString *const MP42MetadataKeyTrackSubTitle;
extern NSString *const MP42MetadataKeyAlbum;
extern NSString *const MP42MetadataKeyAlbumArtist;
extern NSString *const MP42MetadataKeyArtist;
extern NSString *const MP42MetadataKeyGrouping;
extern NSString *const MP42MetadataKeyUserComment;
extern NSString *const MP42MetadataKeyUserGenre;
extern NSString *const MP42MetadataKeyReleaseDate;
extern NSString *const MP42MetadataKeyTrackNumber;
extern NSString *const MP42MetadataKeyDiscNumber;
extern NSString *const MP42MetadataKeyBeatsPerMin;
extern NSString *const MP42MetadataKeyKeywords;
extern NSString *const MP42MetadataKeyCategory;
extern NSString *const MP42MetadataKeyCredits;
extern NSString *const MP42MetadataKeyThanks;
extern NSString *const MP42MetadataKeyCopyright;
extern NSString *const MP42MetadataKeyDescription;
extern NSString *const MP42MetadataKeyLongDescription;
extern NSString *const MP42MetadataKeySeriesDescription;
extern NSString *const MP42MetadataKeySongDescription;
extern NSString *const MP42MetadataKeyRating;
extern NSString *const MP42MetadataKeyRatingAnnotation;
extern NSString *const MP42MetadataKeyContentRating;
// Encoding Metadata keys
extern NSString *const MP42MetadataKeyEncodedBy;
extern NSString *const MP42MetadataKeyEncodingTool;
// TODO
extern NSString *const MP42MetadataKeyCoverArt;
extern NSString *const MP42MetadataKeyMediaKind;
extern NSString *const MP42MetadataKeyGapless;
extern NSString *const MP42MetadataKeyHDVideo;
extern NSString *const MP42MetadataKeyiTunesU;
extern NSString *const MP42MetadataKeyPodcast;
// Movie and TV Show Specific keys
extern NSString *const MP42MetadataKeyStudio;
extern NSString *const MP42MetadataKeyCast;
extern NSString *const MP42MetadataKeyDirector;
extern NSString *const MP42MetadataKeyCodirector;
extern NSString *const MP42MetadataKeyProducer;
extern NSString *const MP42MetadataKeyExecProducer;
extern NSString *const MP42MetadataKeyScreenwriters;
// TV Show Specific Metadata keys
extern NSString *const MP42MetadataKeyTVShow;
extern NSString *const MP42MetadataKeyTVEpisodeNumber;
extern NSString *const MP42MetadataKeyTVNetwork;
extern NSString *const MP42MetadataKeyTVEpisodeID;
extern NSString *const MP42MetadataKeyTVSeason;
// Songs Specific Metadata Keys
extern NSString *const MP42MetadataKeyArtDirector;
extern NSString *const MP42MetadataKeyComposer;
extern NSString *const MP42MetadataKeyArranger;
extern NSString *const MP42MetadataKeyAuthor;
extern NSString *const MP42MetadataKeyLyrics;
extern NSString *const MP42MetadataKeyAcknowledgement;
extern NSString *const MP42MetadataKeyConductor;
extern NSString *const MP42MetadataKeyLinerNotes;
extern NSString *const MP42MetadataKeyRecordCompany;
extern NSString *const MP42MetadataKeyOriginalArtist;
extern NSString *const MP42MetadataKeyPhonogramRights;
extern NSString *const MP42MetadataKeySongProducer;
extern NSString *const MP42MetadataKeyPerformer;
extern NSString *const MP42MetadataKeyPublisher;
extern NSString *const MP42MetadataKeySoundEngineer;
extern NSString *const MP42MetadataKeySoloist;
extern NSString *const MP42MetadataKeyDiscCompilation;
// Classic Music Specific Metadata Keys
extern NSString *const MP42MetadataKeyWorkName;
extern NSString *const MP42MetadataKeyMovementName;
extern NSString *const MP42MetadataKeyMovementNumber;
extern NSString *const MP42MetadataKeyMovementCount;
extern NSString *const MP42MetadataKeyShowWorkAndMovement;
// iTunes Store Metadata keys
extern NSString *const MP42MetadataKeyXID;
extern NSString *const MP42MetadataKeyArtistID;
extern NSString *const MP42MetadataKeyComposerID;
extern NSString *const MP42MetadataKeyContentID;
extern NSString *const MP42MetadataKeyGenreID;
extern NSString *const MP42MetadataKeyPlaylistID;
extern NSString *const MP42MetadataKeyAppleID;
extern NSString *const MP42MetadataKeyAccountKind;
extern NSString *const MP42MetadataKeyAccountCountry;
extern NSString *const MP42MetadataKeyPurchasedDate;
extern NSString *const MP42MetadataKeyOnlineExtras;
// Sort Metadata Keys
extern NSString *const MP42MetadataKeySortName;
extern NSString *const MP42MetadataKeySortArtist;
extern NSString *const MP42MetadataKeySortAlbumArtist;
extern NSString *const MP42MetadataKeySortAlbum;
extern NSString *const MP42MetadataKeySortComposer;
extern NSString *const MP42MetadataKeySortTVShow;
@interface MP42Metadata : NSObject <NSSecureCoding, NSCopying>
/**
@@ -128,53 +20,48 @@ extern NSString *const MP42MetadataKeySortTVShow;
*
* @return The receiver, initialized with the resource specified by URL.
*/
- (instancetype)initWithFileURL:(NSURL *)URL;
- (instancetype)initWithURL:(NSURL *)URL;
/**
* Returns the complete list of available metadata.
*/
+ (NSArray<NSString *> *) availableMetadata;
@property (nonatomic, class, readonly)NSArray<NSString *> *availableMetadata;
/**
* Returns the complete list of writable metadata.
*/
+ (NSArray<NSString *> *) writableMetadata;
@property (nonatomic, class, readonly)NSArray<NSString *> *writableMetadata;
/**
* Returns the list of the available genres.
- (void)addMetadataItem:(MP42MetadataItem *)item;
- (void)removeMetadataItem:(MP42MetadataItem *)item;
@property (nonatomic, readonly) NSArray<MP42MetadataItem *> *items;
/*!
@abstract Filters an array of AVMetadataItems according to identifier.
@param identifier
The identifier that must be matched for a metadata item to be copied to the output array. Items are considered a match not only when their identifiers are equal to the specified identifier, and also when their identifiers conform to the specified identifier.
@result An instance of NSArray containing the metadata items of the target NSArray that match the specified identifier.
*/
- (NSArray<NSString *> *) availableGenres;
- (NSArray<MP42MetadataItem *> *)metadataItemsFilteredByIdentifier:(NSString *)identifier;
/*!
@abstract Filters an array of AVMetadataItems according a data type mask.
@param dataType
The identifier that must be matched for a metadata item to be copied to the output array. Items are considered a match not only when their identifiers are equal to the specified identifier, and also when their identifiers conform to the specified identifier.
@result An instance of NSArray containing the metadata items of the target NSArray that match the specified identifier.
*/
- (NSArray<MP42MetadataItem *> *)metadataItemsFilteredByDataType:(MP42MetadataItemDataType)dataType;
- (void)removeTagForKey:(NSString *)aKey;
- (BOOL)setTag:(id)value forKey:(NSString *)key;
- (nullable id)objectForKeyedSubscript:(NSString *)key;
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key;
@property(nonatomic, readonly) NSMutableDictionary<NSString *, id> *tagsDict;
@property (nonatomic, readwrite, copy) NSString *presetName;
/**
* Merges the tags of the passed MP42Metadata instance.
*
* @param metadata the instance to marge.
Merges the tags of the passed MP42Metadata instance
@param metadata the instance to merge.
*/
- (void)mergeMetadata:(MP42Metadata *)metadata;
@property(nonatomic, readwrite) uint8_t mediaKind;
@property(nonatomic, readwrite) uint8_t contentRating;
@property(nonatomic, readwrite) uint8_t hdVideo;
@property(nonatomic, readwrite) uint8_t gapless;
@property(nonatomic, readwrite) uint8_t podcast;
@property(nonatomic, readwrite, getter=isEdited) BOOL edited;
@property(nonatomic, readwrite) BOOL isArtworkEdited;
@property(nonatomic, readwrite, copy) NSString *presetName;
@property(nonatomic, readwrite, retain) NSMutableArray<MP42Image *> *artworks;
@end
NS_ASSUME_NONNULL_END
+528 -843
View File
File diff suppressed because it is too large. Load diff
+115
View File
@@ -0,0 +1,115 @@
//
// MP42MetadataFormat.h
// MP42Foundation
//
// Created by Damiano Galassi on 07/10/2016.
// Copyright © 2016 Damiano Galassi. All rights reserved.
//
#import <Foundation/Foundation.h>
// Common Metadata keys
extern NSString *const MP42MetadataKeyName;
extern NSString *const MP42MetadataKeyTrackSubTitle;
extern NSString *const MP42MetadataKeyAlbum;
extern NSString *const MP42MetadataKeyAlbumArtist;
extern NSString *const MP42MetadataKeyArtist;
extern NSString *const MP42MetadataKeyGrouping;
extern NSString *const MP42MetadataKeyUserComment;
extern NSString *const MP42MetadataKeyUserGenre;
extern NSString *const MP42MetadataKeyReleaseDate;
extern NSString *const MP42MetadataKeyTrackNumber;
extern NSString *const MP42MetadataKeyDiscNumber;
extern NSString *const MP42MetadataKeyBeatsPerMin;
extern NSString *const MP42MetadataKeyKeywords;
extern NSString *const MP42MetadataKeyCategory;
extern NSString *const MP42MetadataKeyCredits;
extern NSString *const MP42MetadataKeyThanks;
extern NSString *const MP42MetadataKeyCopyright;
extern NSString *const MP42MetadataKeyDescription;
extern NSString *const MP42MetadataKeyLongDescription;
extern NSString *const MP42MetadataKeySeriesDescription;
extern NSString *const MP42MetadataKeySongDescription;
extern NSString *const MP42MetadataKeyRating;
extern NSString *const MP42MetadataKeyRatingAnnotation;
extern NSString *const MP42MetadataKeyContentRating;
extern NSString *const MP42MetadataKeyCoverArt;
extern NSString *const MP42MetadataKeyMediaKind;
extern NSString *const MP42MetadataKeyGapless;
extern NSString *const MP42MetadataKeyHDVideo;
extern NSString *const MP42MetadataKeyiTunesU;
extern NSString *const MP42MetadataKeyPodcast;
// Encoding Metadata keys
extern NSString *const MP42MetadataKeyEncodedBy;
extern NSString *const MP42MetadataKeyEncodingTool;
// Movie and TV Show Specific keys
extern NSString *const MP42MetadataKeyStudio;
extern NSString *const MP42MetadataKeyCast;
extern NSString *const MP42MetadataKeyDirector;
extern NSString *const MP42MetadataKeyCodirector;
extern NSString *const MP42MetadataKeyProducer;
extern NSString *const MP42MetadataKeyExecProducer;
extern NSString *const MP42MetadataKeyScreenwriters;
// TV Show Specific Metadata keys
extern NSString *const MP42MetadataKeyTVShow;
extern NSString *const MP42MetadataKeyTVEpisodeNumber;
extern NSString *const MP42MetadataKeyTVNetwork;
extern NSString *const MP42MetadataKeyTVEpisodeID;
extern NSString *const MP42MetadataKeyTVSeason;
// Songs Specific Metadata Keys
extern NSString *const MP42MetadataKeyArtDirector;
extern NSString *const MP42MetadataKeyComposer;
extern NSString *const MP42MetadataKeyArranger;
extern NSString *const MP42MetadataKeyAuthor;
extern NSString *const MP42MetadataKeyLyrics;
extern NSString *const MP42MetadataKeyAcknowledgement;
extern NSString *const MP42MetadataKeyConductor;
extern NSString *const MP42MetadataKeyLinerNotes;
extern NSString *const MP42MetadataKeyRecordCompany;
extern NSString *const MP42MetadataKeyOriginalArtist;
extern NSString *const MP42MetadataKeyPhonogramRights;
extern NSString *const MP42MetadataKeySongProducer;
extern NSString *const MP42MetadataKeyPerformer;
extern NSString *const MP42MetadataKeyPublisher;
extern NSString *const MP42MetadataKeySoundEngineer;
extern NSString *const MP42MetadataKeySoloist;
extern NSString *const MP42MetadataKeyDiscCompilation;
// Classic Music Specific Metadata Keys
extern NSString *const MP42MetadataKeyWorkName;
extern NSString *const MP42MetadataKeyMovementName;
extern NSString *const MP42MetadataKeyMovementNumber;
extern NSString *const MP42MetadataKeyMovementCount;
extern NSString *const MP42MetadataKeyShowWorkAndMovement;
// iTunes Store Metadata keys
extern NSString *const MP42MetadataKeyXID;
extern NSString *const MP42MetadataKeyArtistID;
extern NSString *const MP42MetadataKeyComposerID;
extern NSString *const MP42MetadataKeyContentID;
extern NSString *const MP42MetadataKeyGenreID;
extern NSString *const MP42MetadataKeyPlaylistID;
extern NSString *const MP42MetadataKeyAppleID;
extern NSString *const MP42MetadataKeyAccountKind;
extern NSString *const MP42MetadataKeyAccountCountry;
extern NSString *const MP42MetadataKeyPurchasedDate;
extern NSString *const MP42MetadataKeyOnlineExtras;
// Sort Metadata Keys
extern NSString *const MP42MetadataKeySortName;
extern NSString *const MP42MetadataKeySortArtist;
extern NSString *const MP42MetadataKeySortAlbumArtist;
extern NSString *const MP42MetadataKeySortAlbum;
extern NSString *const MP42MetadataKeySortComposer;
extern NSString *const MP42MetadataKeySortTVShow;
+107
View File
@@ -0,0 +1,107 @@
//
// MP42MetadataFormat.m
// MP42Foundation
//
// Created by Damiano Galassi on 07/10/2016.
// Copyright © 2016 Damiano Galassi. All rights reserved.
//
#import "MP42MetadataFormat.h"
NSString *const MP42MetadataKeyName = @"Name";
NSString *const MP42MetadataKeyTrackSubTitle = @"Track Sub-Title";
NSString *const MP42MetadataKeyAlbum = @"Album";
NSString *const MP42MetadataKeyAlbumArtist = @"Album Artist";
NSString *const MP42MetadataKeyArtist = @"Artist";
NSString *const MP42MetadataKeyGrouping = @"Grouping";
NSString *const MP42MetadataKeyUserComment = @"Comments";
NSString *const MP42MetadataKeyUserGenre = @"Genre";
NSString *const MP42MetadataKeyReleaseDate = @"Release Date";
NSString *const MP42MetadataKeyTrackNumber = @"Track #";
NSString *const MP42MetadataKeyDiscNumber = @"Disk #";
NSString *const MP42MetadataKeyBeatsPerMin = @"Tempo";
NSString *const MP42MetadataKeyKeywords = @"Keywords";
NSString *const MP42MetadataKeyCategory = @"Category";
NSString *const MP42MetadataKeyCredits = @"Credits";
NSString *const MP42MetadataKeyThanks = @"Thanks";
NSString *const MP42MetadataKeyCopyright = @"Copyright";
NSString *const MP42MetadataKeyDescription = @"Description";
NSString *const MP42MetadataKeyLongDescription = @"Long Description";
NSString *const MP42MetadataKeySeriesDescription = @"Series Description";
NSString *const MP42MetadataKeySongDescription = @"Song Description";
NSString *const MP42MetadataKeyRating = @"Rating";
NSString *const MP42MetadataKeyRatingAnnotation = @"Rating Annotation";
NSString *const MP42MetadataKeyContentRating = @"Content Rating";
NSString *const MP42MetadataKeyEncodedBy = @"Encoded By";
NSString *const MP42MetadataKeyEncodingTool = @"Encoding Tool";
NSString *const MP42MetadataKeyCoverArt = @"Cover Art";
NSString *const MP42MetadataKeyMediaKind = @"Media Kind";
NSString *const MP42MetadataKeyGapless = @"Gapless";
NSString *const MP42MetadataKeyHDVideo = @"HD Video";
NSString *const MP42MetadataKeyiTunesU = @"iTunes U";
NSString *const MP42MetadataKeyPodcast = @"Podcast";
NSString *const MP42MetadataKeyStudio = @"Studio";
NSString *const MP42MetadataKeyCast = @"Cast";
NSString *const MP42MetadataKeyDirector = @"Director";
NSString *const MP42MetadataKeyCodirector = @"Codirector";
NSString *const MP42MetadataKeyProducer = @"Producers";
NSString *const MP42MetadataKeyExecProducer = @"Executive Producer";
NSString *const MP42MetadataKeyScreenwriters = @"Screenwriters";
NSString *const MP42MetadataKeyTVShow = @"TV Show";
NSString *const MP42MetadataKeyTVEpisodeNumber = @"TV Episode #";
NSString *const MP42MetadataKeyTVNetwork = @"TV Network";
NSString *const MP42MetadataKeyTVEpisodeID = @"TV Episode ID";
NSString *const MP42MetadataKeyTVSeason = @"TV Season";
NSString *const MP42MetadataKeyArtDirector = @"Art Director";
NSString *const MP42MetadataKeyComposer = @"Composer";
NSString *const MP42MetadataKeyArranger = @"Arranger";
NSString *const MP42MetadataKeyAuthor = @"Lyricist";
NSString *const MP42MetadataKeyLyrics = @"Lyrics";
NSString *const MP42MetadataKeyAcknowledgement = @"Acknowledgement";
NSString *const MP42MetadataKeyConductor = @"Conductor";
NSString *const MP42MetadataKeyLinerNotes = @"Linear Notes";
NSString *const MP42MetadataKeyRecordCompany = @"Record Company";
NSString *const MP42MetadataKeyOriginalArtist = @"Original Artist";
NSString *const MP42MetadataKeyPhonogramRights = @"Phonogram Rights";
NSString *const MP42MetadataKeySongProducer = @"Song Producer";
NSString *const MP42MetadataKeyPerformer = @"Performer";
NSString *const MP42MetadataKeyPublisher = @"Publisher";
NSString *const MP42MetadataKeySoundEngineer = @"Sound Engineer";
NSString *const MP42MetadataKeySoloist = @"Soloist";
NSString *const MP42MetadataKeyDiscCompilation = @"Compilation";
NSString *const MP42MetadataKeyWorkName = @"Work Name";
NSString *const MP42MetadataKeyMovementName = @"Movement Name";
NSString *const MP42MetadataKeyMovementNumber = @"Movement Number";
NSString *const MP42MetadataKeyMovementCount = @"Movement Count";
NSString *const MP42MetadataKeyShowWorkAndMovement = @"Show Work And Movement";
NSString *const MP42MetadataKeyXID = @"XID";
NSString *const MP42MetadataKeyArtistID = @"artist ID";
NSString *const MP42MetadataKeyComposerID = @"composer ID";
NSString *const MP42MetadataKeyContentID = @"content ID";
NSString *const MP42MetadataKeyGenreID = @"genre ID";
NSString *const MP42MetadataKeyPlaylistID = @"playlist ID";
NSString *const MP42MetadataKeyAppleID = @"iTunes Account";
NSString *const MP42MetadataKeyAccountKind = @"iTunes Account Type";
NSString *const MP42MetadataKeyAccountCountry = @"iTunes Country";
NSString *const MP42MetadataKeyPurchasedDate = @"Purchase Date";
NSString *const MP42MetadataKeyOnlineExtras = @"Online Extras";
NSString *const MP42MetadataKeySortName = @"Sort Name";
NSString *const MP42MetadataKeySortArtist = @"Sort Artist";
NSString *const MP42MetadataKeySortAlbumArtist = @"Sort Album Artist";
NSString *const MP42MetadataKeySortAlbum = @"Sort Album";
NSString *const MP42MetadataKeySortComposer = @"Sort Composer";
NSString *const MP42MetadataKeySortTVShow = @"Sort TV Show";
+17 -6
View File
@@ -7,16 +7,21 @@
//
#import <Foundation/Foundation.h>
#import "MP42MetadataFormat.h"
NS_ASSUME_NONNULL_BEGIN
@class MP42Image;
typedef NS_ENUM(NSUInteger, MP42MetadataItemDataType) {
MP42MetadataItemDataTypeString,
MP42MetadataItemDataTypeBool,
MP42MetadataItemDataTypeInteger,
MP42MetadataItemDataTypeDate,
MP42MetadataItemDataTypePlist,
MP42MetadataItemDataTypeImage,
MP42MetadataItemDataTypeUnspecied = 1 << 0,
MP42MetadataItemDataTypeString = 1 << 1,
MP42MetadataItemDataTypeStringArray = 1 << 2,
MP42MetadataItemDataTypeBool = 1 << 3,
MP42MetadataItemDataTypeInteger = 1 << 4,
MP42MetadataItemDataTypeIntegerArray = 1 << 5,
MP42MetadataItemDataTypeDate = 1 << 6,
MP42MetadataItemDataTypeImage = 1 << 7,
};
@interface MP42MetadataItem : NSObject
@@ -51,6 +56,12 @@ typedef NS_ENUM(NSUInteger, MP42MetadataItemDataType) {
/* provides the value of the metadata item as an NSDate. If the metadata item's value can't be coerced to a date, @"dateValue" will be nil. */
@property (nonatomic, readonly, nullable) NSDate *dateValue;
/* provides the value of the metadata item as an NSArray. If the metadata item's value can't be coerced to a array, @"arrayValue" will be nil. */
@property (nonatomic, readonly, nullable) NSArray *arrayValue;
/* provides the value of the metadata item as an NSArray. If the metadata item's value can't be coerced to a array, @"arrayValue" will be nil. */
@property (nonatomic, readonly, nullable) MP42Image *imageValue;
/* provides the raw bytes of the value of the metadata item */
@property (nonatomic, readonly, nullable) NSData *dataValue;
+64
View File
@@ -7,6 +7,8 @@
//
#import "MP42MetadataItem.h"
#import "MP42Metadata.h"
#import "MP42Image.h"
@implementation MP42MetadataItem
@@ -40,6 +42,36 @@
@implementation MP42MetadataItem (MP42MetadataItemTypeCoercion)
- (NSString *)stringFromStringArray:(NSArray<NSString *> *)array {
NSMutableString *result = [NSMutableString string];
for (NSString *text in array) {
if (result.length) {
[result appendString:@", "];
}
[result appendString:text];
}
return [result copy];
}
- (NSString *)stringFromIntegerArray:(NSArray<NSNumber *> *)array {
NSMutableString *result = [NSMutableString string];
for (NSNumber *number in array) {
if (result.length) {
[result appendString:@"/"];
}
[result appendString:number.stringValue];
}
return [result copy];
}
- (NSString *)stringValue
{
switch (_dataType) {
@@ -53,6 +85,10 @@
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
return [formatter stringFromDate:(NSDate *)_value];
}
case MP42MetadataItemDataTypeStringArray:
return [self stringFromStringArray:(NSArray *)_value];
case MP42MetadataItemDataTypeIntegerArray:
return [self stringFromIntegerArray:(NSArray *)_value];
default:
return nil;
}
@@ -81,9 +117,37 @@
}
}
- (NSArray *)arrayValue
{
switch (_dataType) {
case MP42MetadataItemDataTypeIntegerArray:
case MP42MetadataItemDataTypeStringArray:
return (NSArray *)_value;
default:
return nil;
}
}
- (MP42Image *)imageValue
{
switch (_dataType) {
case MP42MetadataItemDataTypeImage:
return (MP42Image *)_value;
default:
return nil;
}
}
- (NSData *)dataValue
{
return nil;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"<MP42MetadataItem: %@>", _value];
}
@end
+4 -4
View File
@@ -323,7 +323,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
SegmentInfo *segInfo = mkv_GetFileInfo(_matroskaFile);
if (segInfo->Title) {
[mkvMetadata setTag:[NSString stringWithUTF8String:segInfo->Title] forKey:MP42MetadataKeyName];
//[mkvMetadata setTag:[NSString stringWithUTF8String:segInfo->Title] forKey:MP42MetadataKeyName];
}
Tag *tags;
@@ -334,7 +334,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
unsigned int xi = 0;
for (xi = 0; xi < tags->nSimpleTags; xi++) {
if (!strcmp(tags->SimpleTags[xi].Name, "TITLE"))
/*if (!strcmp(tags->SimpleTags[xi].Name, "TITLE"))
[mkvMetadata setTag:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] forKey:MP42MetadataKeyName];
if (!strcmp(tags->SimpleTags[xi].Name, "DATE_RELEASED"))
@@ -353,12 +353,12 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
[mkvMetadata setTag:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] forKey:MP42MetadataKeyArtist];
if (!strcmp(tags->SimpleTags[xi].Name, "ENCODER"))
[mkvMetadata setTag:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] forKey:MP42MetadataKeyEncodingTool];
[mkvMetadata setTag:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] forKey:MP42MetadataKeyEncodingTool];*/
}
}
if (mkvMetadata.tagsDict.count) {
if (mkvMetadata.items.count) {
return mkvMetadata;
}
else {
+8 -6
View File
@@ -49,12 +49,13 @@
}
- (MP42Metadata *) metadata:(MP42Metadata *)metadata forNode:(NSXMLElement *)node {
metadata.mediaKind = 9; // movie
// FIXME
//metadata.mediaKind = 9; // movie
NSArray *tag;
NSError *err;
// initial fields from general movie search
tag = [node nodesForXPath:@"./title" error:&err];
if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyName];
/*if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyName];
tag = [node nodesForXPath:@"./year" error:&err];
if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyReleaseDate];
tag = [node nodesForXPath:@"./outline" error:&err];
@@ -75,18 +76,19 @@
// additional fields from detailed movie info
NSString *joined;
joined = [self nodes:node forXPath:@"./cast/actor/@name" joinedBy:@","];
if (joined) [metadata setTag:joined forKey:MP42MetadataKeyCast];
if (joined) [metadata setTag:joined forKey:MP42MetadataKeyCast];*/
return metadata;
}
- (MP42Metadata *) metadata2:(MP42Metadata *)metadata forNode:(NSXMLElement *)node {
metadata.mediaKind = 9; // movie
//FIXME
//metadata.mediaKind = 9; // movie
NSArray *tag;
NSError *err;
// initial fields from general movie search
tag = [node nodesForXPath:@"./content_id" error:&err];
if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyContentID];
/*if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyContentID];
tag = [node nodesForXPath:@"./genre" error:&err];
if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyUserGenre];
tag = [node nodesForXPath:@"./name" error:&err];
@@ -116,7 +118,7 @@
if ([tag count]) [metadata setTag:[[tag objectAtIndex:0] stringValue] forKey:MP42MetadataKeyLongDescription];
joined = [self nodes:node forXPath:@"./categories/category" joinedBy:@","];
if (joined) [metadata setTag:joined forKey:MP42MetadataKeyCategory];
if (joined) [metadata setTag:joined forKey:MP42MetadataKeyCategory];*/
return metadata;
}