Read mkv cover arts.
This commit is contained in:
1 parent
9c17c7c754
commit
45619d646a
4 files changed
+82
-24
No files matched your search
+4
-4
@@ -20,14 +20,14 @@ typedef enum MP42TagArtworkType_e {
|
||||
|
||||
@interface MP42Image : NSObject <NSSecureCoding, NSCopying>
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type;
|
||||
- (instancetype)initWithURL:(NSURL *)url type:(MP42TagArtworkType)type;
|
||||
- (instancetype)initWithImage:(NSImage *)image;
|
||||
- (instancetype)initWithData:(NSData *)data type:(NSInteger)type;
|
||||
- (instancetype)initWithBytes:(const void*)bytes length:(NSUInteger)length type:(NSInteger)type;
|
||||
- (instancetype)initWithData:(NSData *)data type:(MP42TagArtworkType)type;
|
||||
- (instancetype)initWithBytes:(const void *)bytes length:(NSUInteger)length type:(MP42TagArtworkType)type;
|
||||
|
||||
@property(atomic, readonly) NSImage *image;
|
||||
@property(atomic, readonly) NSURL *url;
|
||||
@property(atomic, readonly) NSData *data;
|
||||
@property(atomic, readonly) NSInteger type;
|
||||
@property(atomic, readonly) MP42TagArtworkType type;
|
||||
|
||||
@end
|
||||
+4
-4
@@ -23,7 +23,7 @@
|
||||
NSData *_data;
|
||||
NSString *_uuid;
|
||||
|
||||
NSInteger _type;
|
||||
MP42TagArtworkType _type;
|
||||
}
|
||||
|
||||
@synthesize url = _url;
|
||||
@@ -31,7 +31,7 @@
|
||||
@synthesize type = _type;
|
||||
@synthesize uuid = _uuid;
|
||||
|
||||
- (instancetype)initWithURL:(NSURL *)url type:(NSInteger)type
|
||||
- (instancetype)initWithURL:(NSURL *)url type:(MP42TagArtworkType)type
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_url = url;
|
||||
@@ -49,7 +49,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithData:(NSData *)data type:(NSInteger)type
|
||||
- (instancetype)initWithData:(NSData *)data type:(MP42TagArtworkType)type
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_data = [data copy];
|
||||
@@ -59,7 +59,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithBytes:(const void*)bytes length:(NSUInteger)length type:(NSInteger)type
|
||||
- (instancetype)initWithBytes:(const void*)bytes length:(NSUInteger)length type:(MP42TagArtworkType)type
|
||||
{
|
||||
if (self = [super init]) {
|
||||
_data = [[NSData alloc] initWithBytes:bytes length:length];
|
||||
|
||||
+2
-2
@@ -700,7 +700,7 @@
|
||||
}
|
||||
if (tags->artwork) {
|
||||
for (uint32_t i = 0; i < tags->artworkCount; i++) {
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithBytes:tags->artwork[i].data length:tags->artwork[i].size type:tags->artwork[i].type];
|
||||
MP42Image *artwork = [[MP42Image alloc] initWithBytes:tags->artwork[i].data length:tags->artwork[i].size type:(MP42TagArtworkType)tags->artwork[i].type];
|
||||
[self addMetadataItemWithImage:artwork identifier:MP42MetadataKeyCoverArt];
|
||||
}
|
||||
}
|
||||
@@ -1058,7 +1058,7 @@
|
||||
|
||||
newArtwork.data = (void *)artwork.data.bytes;
|
||||
newArtwork.size = artwork.data.length;
|
||||
newArtwork.type = artwork.type;
|
||||
newArtwork.type = (MP4TagArtworkType)artwork.type;
|
||||
}
|
||||
else {
|
||||
|
||||
|
||||
+72
-14
@@ -62,7 +62,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc {
|
||||
- (void)dealloc {
|
||||
[queue release], queue = nil;
|
||||
[ss release], ss = nil;
|
||||
|
||||
@@ -70,6 +70,41 @@
|
||||
}
|
||||
@end
|
||||
|
||||
static int readData(struct StdIoStream *ioStream, uint64_t pos, uint8_t **data, uint32_t dataSize)
|
||||
{
|
||||
if (fseeko(ioStream->fp, pos, SEEK_SET)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"fseeko(): %s\n", strerror(errno));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t rd = fread(*data, 1, dataSize, ioStream->fp);
|
||||
|
||||
if (rd != dataSize) {
|
||||
if (rd == 0) {
|
||||
if (feof(ioStream->fp)) {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Unexpected EOF while reading frame\n");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Error reading frame: %s\n",strerror(errno));
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"Short read while reading frame\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, uint64_t FilePos, uint8_t** frame, uint32_t *FrameSize)
|
||||
{
|
||||
uint8_t *packet = NULL;
|
||||
@@ -86,8 +121,9 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
|
||||
packet = malloc(iSize + trackInfo->CompMethodPrivateSize);
|
||||
memcpy(packet, trackInfo->CompMethodPrivate, trackInfo->CompMethodPrivateSize);
|
||||
}
|
||||
else
|
||||
else {
|
||||
packet = malloc(iSize);
|
||||
}
|
||||
|
||||
if (packet == NULL) {
|
||||
fprintf(stderr,"Out of memory\n");
|
||||
@@ -316,7 +352,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addMetadataItemWithString:(NSString *)value identifier:(NSString *)identifier metadata:(MP42Metadata *)metadata
|
||||
- (void)addMetadataItem:(id)value identifier:(NSString *)identifier metadata:(MP42Metadata *)metadata
|
||||
{
|
||||
MP42MetadataItem *item = [MP42MetadataItem metadataItemWithIdentifier:identifier
|
||||
value:value
|
||||
@@ -331,7 +367,7 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
|
||||
|
||||
SegmentInfo *segInfo = mkv_GetFileInfo(_matroskaFile);
|
||||
if (segInfo->Title) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:segInfo->Title] identifier:MP42MetadataKeyName metadata:mkvMetadata];
|
||||
[self addMetadataItem:[NSString stringWithUTF8String:segInfo->Title] identifier:MP42MetadataKeyName metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
Tag *tags;
|
||||
@@ -342,43 +378,65 @@ static int readMkvPacket(struct StdIoStream *ioStream, TrackInfo *trackInfo, ui
|
||||
for (unsigned int xi = 0; xi < tags->nSimpleTags; xi++) {
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "TITLE")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyName metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyName metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "DATE_RELEASED")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyReleaseDate metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyReleaseDate metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "COMMENT")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyUserComment metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyUserComment metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "DIRECTOR")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyDirector metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyDirector metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "COPYRIGHT")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyCopyright metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyCopyright metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "ARTIST")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyArtist metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyArtist metadata:mkvMetadata];
|
||||
}
|
||||
|
||||
if (!strcmp(tags->SimpleTags[xi].Name, "ENCODER")) {
|
||||
[self addMetadataItemWithString:[NSString stringWithUTF8String:tags->SimpleTags[xi].Value] identifier:MP42MetadataKeyEncodingTool metadata:mkvMetadata];
|
||||
[self addMetadataItem:@(tags->SimpleTags[xi].Value) identifier:MP42MetadataKeyEncodingTool metadata:mkvMetadata];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*Attachment *attachments;
|
||||
Attachment *attachments;
|
||||
mkv_GetAttachments(_matroskaFile, &attachments, &count);
|
||||
|
||||
if (count) {
|
||||
for (unsigned int xi = 0; xi < count; xi++) {
|
||||
NSLog(@"%s", attachments[xi].Name);
|
||||
Attachment *attachment = &attachments[xi];
|
||||
|
||||
if (attachment->Name && attachment->MimeType && attachment->Length > 0) {
|
||||
if (!strcmp(attachment->MimeType, "image/jpeg") || !strcmp(attachment->MimeType, "image/png")) {
|
||||
uint8_t *data = malloc(attachment->Length);
|
||||
|
||||
if (readData(_ioStream, attachment->Position, &data, attachment->Length)) {
|
||||
MP42TagArtworkType type = MP42_ART_JPEG;
|
||||
|
||||
if (!strcmp(attachment->MimeType, "image/png")) {
|
||||
type = MP42_ART_PNG;
|
||||
}
|
||||
|
||||
MP42Image *image = [[MP42Image alloc] initWithBytes:data length:attachment->Length type:type];
|
||||
|
||||
[self addMetadataItem:image identifier:MP42MetadataKeyCoverArt metadata:mkvMetadata];
|
||||
|
||||
[image release];
|
||||
}
|
||||
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
return (mkvMetadata.items.count) ? mkvMetadata : nil;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user