From 286268e5ac0c7b2c1c69a01b837fc5a3561291fa Mon Sep 17 00:00:00 2001 From: vspader Date: Sat, 13 Oct 2007 01:36:55 +0000 Subject: [PATCH] Added metadata reader for game music files. --- Plugins/GME/GME.xcodeproj/project.pbxproj | 8 +++ Plugins/GME/GameMetadataReader.h | 17 ++++++ Plugins/GME/GameMetadataReader.m | 72 +++++++++++++++++++++++ Plugins/GME/GamePlugin.m | 2 + 4 files changed, 99 insertions(+) create mode 100644 Plugins/GME/GameMetadataReader.h create mode 100644 Plugins/GME/GameMetadataReader.m diff --git a/Plugins/GME/GME.xcodeproj/project.pbxproj b/Plugins/GME/GME.xcodeproj/project.pbxproj index f9ae09e82..161914835 100644 --- a/Plugins/GME/GME.xcodeproj/project.pbxproj +++ b/Plugins/GME/GME.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 17C8F3C30CBED649008D969D /* GME.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 17C8F3370CBED393008D969D /* GME.framework */; }; 17C8F3E00CBEDBE0008D969D /* GamePlugin.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17C8F3DE0CBEDBE0008D969D /* GamePlugin.h */; }; 17C8F3E10CBEDBE0008D969D /* GamePlugin.m in Sources */ = {isa = PBXBuildFile; fileRef = 17C8F3DF0CBEDBE0008D969D /* GamePlugin.m */; }; + 17DA34BA0CC052030003F6B2 /* GameMetadataReader.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 17DA34B80CC052030003F6B2 /* GameMetadataReader.h */; }; + 17DA34BB0CC052030003F6B2 /* GameMetadataReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 17DA34B90CC052030003F6B2 /* GameMetadataReader.m */; }; 8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; }; 8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -52,6 +54,7 @@ 17C8F3450CBED3BE008D969D /* GamePropertiesReader.h in CopyFiles */, 17C8F3480CBED3C7008D969D /* Plugin.h in CopyFiles */, 17C8F3E00CBEDBE0008D969D /* GamePlugin.h in CopyFiles */, + 17DA34BA0CC052030003F6B2 /* GameMetadataReader.h in CopyFiles */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -72,6 +75,8 @@ 17C8F3470CBED3C7008D969D /* Plugin.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Plugin.h; path = ../../Audio/Plugin.h; sourceTree = SOURCE_ROOT; }; 17C8F3DE0CBEDBE0008D969D /* GamePlugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GamePlugin.h; sourceTree = ""; }; 17C8F3DF0CBEDBE0008D969D /* GamePlugin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GamePlugin.m; sourceTree = ""; }; + 17DA34B80CC052030003F6B2 /* GameMetadataReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameMetadataReader.h; sourceTree = ""; }; + 17DA34B90CC052030003F6B2 /* GameMetadataReader.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameMetadataReader.m; sourceTree = ""; }; 32DBCF630370AF2F00C91783 /* GME_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GME_Prefix.pch; sourceTree = ""; }; 8D5B49B6048680CD000E48DA /* GME.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GME.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; 8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = Info.plist; sourceTree = ""; }; @@ -133,6 +138,8 @@ 17C8F33E0CBED3BE008D969D /* GameDecoder.m */, 17C8F33F0CBED3BE008D969D /* GamePropertiesReader.h */, 17C8F3400CBED3BE008D969D /* GamePropertiesReader.m */, + 17DA34B80CC052030003F6B2 /* GameMetadataReader.h */, + 17DA34B90CC052030003F6B2 /* GameMetadataReader.m */, ); name = Classes; sourceTree = ""; @@ -254,6 +261,7 @@ 17C8F3440CBED3BE008D969D /* GameDecoder.m in Sources */, 17C8F3460CBED3BE008D969D /* GamePropertiesReader.m in Sources */, 17C8F3E10CBEDBE0008D969D /* GamePlugin.m in Sources */, + 17DA34BB0CC052030003F6B2 /* GameMetadataReader.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Plugins/GME/GameMetadataReader.h b/Plugins/GME/GameMetadataReader.h new file mode 100644 index 000000000..15081961a --- /dev/null +++ b/Plugins/GME/GameMetadataReader.h @@ -0,0 +1,17 @@ +// +// GameMetadataReader.h +// GME +// +// Created by Vincent Spader on 10/12/07. +// Copyright 2007 __MyCompanyName__. All rights reserved. +// + +#import + +#import "Plugin.h" + +@interface GameMetadataReader : NSObject { + +} + +@end diff --git a/Plugins/GME/GameMetadataReader.m b/Plugins/GME/GameMetadataReader.m new file mode 100644 index 000000000..208800bb6 --- /dev/null +++ b/Plugins/GME/GameMetadataReader.m @@ -0,0 +1,72 @@ +// +// GameMetadataReader.m +// GME +// +// Created by Vincent Spader on 10/12/07. +// Copyright 2007 __MyCompanyName__. All rights reserved. +// + +#import "GameMetadataReader.h" + +#import "GameContainer.h" + +#import + +@implementation GameMetadataReader + ++ (NSArray *)fileTypes +{ + return [GameContainer fileTypes]; +} + ++ (NSDictionary *)metadataForURL:(NSURL *)url +{ + if (![url isFileURL]) + return nil; + + NSString *ext = [[[url path] pathExtension] lowercaseString]; + + gme_type_t type = gme_identify_extension([ext UTF8String]); + if (!type) + { + NSLog(@"No type!"); + return NO; + } + + Music_Emu* emu; + emu = gme_new_emu(type, gme_info_only); + if (!emu) + { + NSLog(@"No new emu!"); + return NO; + } + + gme_err_t error; + error = gme_load_file(emu, [[url path] UTF8String]); + if (error) + { + NSLog(@"ERROR Loding file!"); + return NO; + } + + int track_num = [[url fragment] intValue]; //What if theres no fragment? Assuming we get 0. + + track_info_t info; + error = gme_track_info( emu, &info, track_num ); + if (error) + { + NSLog(@"Unable to get track info"); + } + + gme_delete(emu); + + return [NSDictionary dictionaryWithObjectsAndKeys: + [NSString stringWithUTF8String: info.system], @"genre", + [NSString stringWithUTF8String: info.game], @"album", + [NSString stringWithUTF8String: info.song], @"title", + [NSString stringWithUTF8String: info.author], @"artist", + [NSNumber numberWithInt:track_num], @"track", + nil]; +} + +@end diff --git a/Plugins/GME/GamePlugin.m b/Plugins/GME/GamePlugin.m index b3b71d866..4e3ebe7e4 100644 --- a/Plugins/GME/GamePlugin.m +++ b/Plugins/GME/GamePlugin.m @@ -11,6 +11,7 @@ #import "GameContainer.h" #import "GameDecoder.h" #import "GamePropertiesReader.h" +#import "GameMetadataReader.h" @implementation GamePlugin @@ -20,6 +21,7 @@ kCogContainer, [GameContainer className], kCogDecoder, [GameDecoder className], kCogPropertiesReader, [GamePropertiesReader className], + kCogMetadataReader, [GameMetadataReader className], nil]; }