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>
|
|
|
|
|
|
|
|
@implementation DumbMetadataReader
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
|
|
|
return [DumbDecoder fileTypes];
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:56:23 +00:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return [DumbDecoder mimeTypes];
|
|
|
|
}
|
|
|
|
|
2007-10-13 02:26:28 +00:00
|
|
|
+ (NSDictionary *)metadataForURL:(NSURL *)url
|
|
|
|
{
|
2013-10-04 15:14:47 +00:00
|
|
|
id audioSourceClass = NSClassFromString(@"AudioSource");
|
|
|
|
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
|
|
|
|
|
|
|
|
if (![source open:url])
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (![source seekable])
|
|
|
|
return 0;
|
2007-10-13 02:26:28 +00:00
|
|
|
|
2013-10-04 15:14:47 +00:00
|
|
|
DUMBFILE * df = dumbfile_open_ex(source, &dfs);
|
|
|
|
if (!df)
|
|
|
|
{
|
|
|
|
NSLog(@"EX Failed");
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2007-10-13 02:26:28 +00:00
|
|
|
DUH *duh;
|
|
|
|
NSString *ext = [[[url path] pathExtension] lowercaseString];
|
2013-10-04 15:14:47 +00:00
|
|
|
duh = dumb_read_any_quick(df, [ext isEqualToString:@"mod"] ? 0 : 1, 0);
|
|
|
|
|
|
|
|
dumbfile_close(df);
|
|
|
|
|
2007-10-13 02:26:28 +00:00
|
|
|
if (!duh)
|
|
|
|
{
|
|
|
|
NSLog(@"Failed to create duh");
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Some titles are all spaces?!
|
|
|
|
NSString *title = [[NSString stringWithUTF8String: duh_get_tag(duh, "TITLE")] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
unload_duh(duh);
|
2008-02-10 15:40:01 +00:00
|
|
|
|
|
|
|
if (title == nil) {
|
|
|
|
title = @"";
|
|
|
|
}
|
2007-10-13 02:26:28 +00:00
|
|
|
|
|
|
|
return [NSDictionary dictionaryWithObject:title forKey:@"title"];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|