2014-12-08 06:26:31 +00:00
|
|
|
//
|
|
|
|
// SidMetadataReader.mm
|
|
|
|
// sidplay
|
|
|
|
//
|
|
|
|
// Created by Christopher Snowhill on 12/8/14.
|
|
|
|
// Copyright 2014 __NoWork, Inc__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "SidMetadataReader.h"
|
|
|
|
#import "SidDecoder.h"
|
|
|
|
|
|
|
|
#import "Logging.H"
|
|
|
|
|
|
|
|
@implementation SidMetadataReader
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)fileTypes {
|
2014-12-08 06:26:31 +00:00
|
|
|
return [SidDecoder fileTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)mimeTypes {
|
2014-12-08 06:26:31 +00:00
|
|
|
return [SidDecoder mimeTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (float)priority {
|
|
|
|
return 0.5f;
|
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;
|
|
|
|
|
|
|
|
[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];
|
|
|
|
|
|
|
|
SidTune *tune = new SidTune((const uint_least8_t *)data, (uint_least32_t)size);
|
|
|
|
|
2022-02-11 12:19:27 +00:00
|
|
|
if(!tune->getStatus()) {
|
|
|
|
delete tune;
|
2022-02-07 05:49:27 +00:00
|
|
|
return 0;
|
2022-02-11 12:19:27 +00:00
|
|
|
}
|
2022-02-07 05:49:27 +00:00
|
|
|
|
|
|
|
const SidTuneInfo *info = tune->getInfo();
|
|
|
|
|
|
|
|
unsigned int count = info->numberOfInfoStrings();
|
2022-05-24 08:07:55 +00:00
|
|
|
NSString *title = count >= 1 ? [guess_encoding_of_string(info->infoString(0)) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] : @"";
|
2022-02-07 05:49:27 +00:00
|
|
|
NSString *titletag = info->songs() > 1 ? @"album" : @"title";
|
2022-05-24 08:07:55 +00:00
|
|
|
NSString *artist = count >= 2 ? [guess_encoding_of_string(info->infoString(1)) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] : @"";
|
2022-02-07 05:49:27 +00:00
|
|
|
|
2022-02-11 12:19:27 +00:00
|
|
|
delete tune;
|
|
|
|
|
2022-02-09 03:42:03 +00:00
|
|
|
return @{titletag: title, @"artist": artist};
|
2014-12-08 06:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|