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
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)fileTypes {
|
2007-10-20 03:17:43 +00:00
|
|
|
return [GameDecoder fileTypes];
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)mimeTypes {
|
2007-10-20 03:17:43 +00:00
|
|
|
return [GameDecoder mimeTypes];
|
2007-10-14 18:56:23 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (float)priority {
|
|
|
|
return 1.0f;
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (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;
|
2007-10-13 01:36:55 +00:00
|
|
|
|
2016-06-19 19:57:18 +00:00
|
|
|
NSString *ext = [[url pathExtension] lowercaseString];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-13 01:36:55 +00:00
|
|
|
gme_type_t type = gme_identify_extension([ext UTF8String]);
|
2022-02-07 05:49:27 +00:00
|
|
|
if(!type) {
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: No type!");
|
2021-01-27 02:45:02 +00:00
|
|
|
return nil;
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
Music_Emu *emu;
|
2007-10-13 01:36:55 +00:00
|
|
|
emu = gme_new_emu(type, gme_info_only);
|
2022-02-07 05:49:27 +00:00
|
|
|
if(!emu) {
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: No new emu!");
|
2021-01-27 02:45:02 +00:00
|
|
|
return nil;
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
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;
|
2016-05-05 20:05:39 +00:00
|
|
|
error = gme_load_custom(emu, readCallback, size, (__bridge void *)(source));
|
2022-02-07 05:49:27 +00:00
|
|
|
if(error) {
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"GME: ERROR Loding file!");
|
2021-01-27 02:45:02 +00:00
|
|
|
return nil;
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
NSURL *m3uurl = [url URLByDeletingPathExtension];
|
|
|
|
m3uurl = [m3uurl URLByAppendingPathExtension:@"m3u"];
|
|
|
|
id<CogSource> m3usrc = [audioSourceClass audioSourceForURL:m3uurl];
|
|
|
|
if([m3usrc open:m3uurl]) {
|
|
|
|
if([m3usrc seekable]) {
|
|
|
|
[m3usrc seek:0 whence:SEEK_END];
|
|
|
|
long size = [m3usrc tell];
|
|
|
|
[m3usrc seek:0 whence:SEEK_SET];
|
|
|
|
|
|
|
|
void *data = malloc(size);
|
|
|
|
[m3usrc read:data amount:size];
|
|
|
|
|
|
|
|
gme_load_m3u_data(emu, data, size);
|
|
|
|
free(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-13 00:44:41 +00:00
|
|
|
int track_num;
|
2022-02-07 05:49:27 +00:00
|
|
|
if([[url fragment] length] == 0)
|
2008-03-13 00:44:41 +00:00
|
|
|
track_num = 0;
|
|
|
|
else
|
2009-03-07 10:20:30 +00:00
|
|
|
track_num = [[url fragment] intValue];
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
gme_info_t *info;
|
|
|
|
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
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2007-10-13 01:36:55 +00:00
|
|
|
gme_delete(emu);
|
|
|
|
|
2022-02-07 05:49:27 +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];
|
|
|
|
}
|
|
|
|
|
2022-02-09 03:42:03 +00:00
|
|
|
NSDictionary *dict = @{@"genre": [NSString stringWithUTF8String:info->system],
|
|
|
|
@"album": [NSString stringWithUTF8String:info->game],
|
|
|
|
@"title": title,
|
|
|
|
@"artist": [NSString stringWithUTF8String:info->author],
|
|
|
|
@"track": [NSNumber numberWithInt:track_num + 1]};
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
gme_free_info(info);
|
|
|
|
|
|
|
|
return dict;
|
2007-10-13 01:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|