2007-10-13 01:36:55 +00:00
|
|
|
//
|
|
|
|
// GameMetadataReader.m
|
|
|
|
// GME
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 10/12/07.
|
|
|
|
// Copyright 2007 __MyCompanyName__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "GameMetadataReader.h"
|
|
|
|
|
2007-10-20 03:17:43 +00:00
|
|
|
#import "GameDecoder.h"
|
2007-10-13 01:36:55 +00:00
|
|
|
|
|
|
|
#import <GME/gme.h>
|
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2007-10-13 01:36:55 +00:00
|
|
|
@implementation GameMetadataReader
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
2007-10-20 03:17:43 +00:00
|
|
|
return [GameDecoder fileTypes];
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 18:56:23 +00:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
2007-10-20 03:17:43 +00:00
|
|
|
return [GameDecoder mimeTypes];
|
2007-10-14 18:56:23 +00:00
|
|
|
}
|
|
|
|
|
2007-10-13 01:36:55 +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 01:36:55 +00:00
|
|
|
|
|
|
|
NSString *ext = [[[url path] pathExtension] lowercaseString];
|
|
|
|
|
|
|
|
gme_type_t type = gme_identify_extension([ext UTF8String]);
|
|
|
|
if (!type)
|
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: No type!");
|
2007-10-13 01:36:55 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
Music_Emu* emu;
|
|
|
|
emu = gme_new_emu(type, gme_info_only);
|
|
|
|
if (!emu)
|
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: No new emu!");
|
2007-10-13 01:36:55 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2013-10-04 15:14:47 +00:00
|
|
|
[source seek:0 whence:SEEK_END];
|
|
|
|
long size = [source tell];
|
|
|
|
[source seek:0 whence:SEEK_SET];
|
|
|
|
|
2007-10-13 01:36:55 +00:00
|
|
|
gme_err_t error;
|
2013-10-04 15:14:47 +00:00
|
|
|
error = gme_load_custom(emu, readCallback, size, source);
|
|
|
|
if (error)
|
2007-10-13 01:36:55 +00:00
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: ERROR Loding file!");
|
2007-10-13 01:36:55 +00:00
|
|
|
return NO;
|
|
|
|
}
|
2013-10-04 15:14:47 +00:00
|
|
|
|
2008-03-13 00:44:41 +00:00
|
|
|
int track_num;
|
|
|
|
if ([[url fragment] length] == 0)
|
|
|
|
track_num = 0;
|
|
|
|
else
|
2009-03-07 10:20:30 +00:00
|
|
|
track_num = [[url fragment] intValue];
|
2007-10-13 01:36:55 +00:00
|
|
|
|
2013-09-28 03:24:23 +00:00
|
|
|
gme_info_t * info;
|
2007-10-13 01:36:55 +00:00
|
|
|
error = gme_track_info( emu, &info, track_num );
|
|
|
|
if (error)
|
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: Unable to get track info");
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gme_delete(emu);
|
|
|
|
|
2013-10-11 12:48:19 +00:00
|
|
|
NSString *title = [NSString stringWithUTF8String: info->song];
|
|
|
|
if (!title || ![title length])
|
|
|
|
{
|
|
|
|
// this is needed to distinguish between different tracks in NSF, for example
|
|
|
|
// otherwise they will all be displayed as 'blahblah.nsf' in playlist
|
|
|
|
title = [[url lastPathComponent] stringByAppendingFormat:@" [%d]", track_num];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
|
2013-09-28 03:24:23 +00:00
|
|
|
[NSString stringWithUTF8String: info->system], @"genre",
|
|
|
|
[NSString stringWithUTF8String: info->game], @"album",
|
2013-10-11 12:48:19 +00:00
|
|
|
title, @"title",
|
2013-09-28 03:24:23 +00:00
|
|
|
[NSString stringWithUTF8String: info->author], @"artist",
|
2009-03-07 10:20:30 +00:00
|
|
|
[NSNumber numberWithInt:track_num+1], @"track",
|
2007-10-13 01:36:55 +00:00
|
|
|
nil];
|
2013-09-28 03:24:23 +00:00
|
|
|
|
|
|
|
gme_free_info( info );
|
|
|
|
|
|
|
|
return dict;
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|