cog/Plugins/Dumb/DumbMetadataReader.m

76 lines
1.5 KiB
Matlab
Raw Normal View History

2007-10-13 02:26:28 +00:00
//
// DumbMetadataReader.m
// Dumb
//
// Created by Vincent Spader on 10/12/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "DumbMetadataReader.h"
#import "DumbDecoder.h"
#import <Dumb/dumb.h>
#import "Logging.H"
2007-10-13 02:26:28 +00:00
@implementation DumbMetadataReader
+ (NSArray *)fileTypes {
2007-10-13 02:26:28 +00:00
return [DumbDecoder fileTypes];
}
+ (NSArray *)mimeTypes {
2007-10-14 18:56:23 +00:00
return [DumbDecoder mimeTypes];
}
+ (float)priority {
return 1.0f;
}
+ (NSDictionary *)metadataForURL:(NSURL *)url {
id audioSourceClass = NSClassFromString(@"AudioSource");
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
if(![source open:url])
return 0;
if(![source seekable])
return 0;
[source seek:0 whence:SEEK_END];
long size = [source tell];
[source seek:0 whence:SEEK_SET];
void *data = malloc(size);
[source read:data amount:size];
DUMBFILE *df = dumbfile_open_memory_and_free(data, size);
if(!df) {
ALog(@"Open failed for file: %@", [url absoluteString]);
return NO;
}
2007-10-13 02:26:28 +00:00
DUH *duh;
NSString *ext = [[url pathExtension] lowercaseString];
duh = dumb_read_any_quick(df, [ext isEqualToString:@"mod"] ? 0 : 1, 0);
dumbfile_close(df);
if(!duh) {
ALog(@"Failed to create duh");
2007-10-13 02:26:28 +00:00
return nil;
}
// Some titles are all spaces?!
NSString *title = [[NSString stringWithUTF8String:duh_get_tag(duh, "TITLE")] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
2007-10-13 02:26:28 +00:00
unload_duh(duh);
if(title == nil) {
title = @"";
}
2007-10-13 02:26:28 +00:00
return [NSDictionary dictionaryWithObject:title forKey:@"title"];
}
@end