2007-02-24 20:36:27 +00:00
|
|
|
#import "PluginController.h"
|
|
|
|
#import "Plugin.h"
|
2015-04-13 07:39:24 +00:00
|
|
|
#import "CogPluginMulti.h"
|
2007-02-24 20:36:27 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
@implementation PluginController
|
|
|
|
|
2008-03-01 15:28:17 +00:00
|
|
|
@synthesize sources;
|
|
|
|
@synthesize containers;
|
|
|
|
@synthesize metadataReaders;
|
|
|
|
|
|
|
|
@synthesize propertiesReadersByExtension;
|
|
|
|
@synthesize propertiesReadersByMimeType;
|
|
|
|
|
|
|
|
@synthesize decodersByExtension;
|
|
|
|
@synthesize decodersByMimeType;
|
|
|
|
|
|
|
|
@synthesize configured;
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
static PluginController *sharedPluginController = nil;
|
|
|
|
|
2007-10-20 15:53:52 +00:00
|
|
|
+ (id<CogPluginController>)sharedPluginController
|
2007-02-24 20:36:27 +00:00
|
|
|
{
|
|
|
|
@synchronized(self) {
|
|
|
|
if (sharedPluginController == nil) {
|
2008-03-03 02:18:27 +00:00
|
|
|
sharedPluginController = [[self alloc] init];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-03 02:18:27 +00:00
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
return sharedPluginController;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (id)init {
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
2016-05-05 20:05:39 +00:00
|
|
|
self.sources = [[NSMutableDictionary alloc] init];
|
|
|
|
self.containers = [[NSMutableDictionary alloc] init];
|
2008-03-01 15:32:28 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
self.metadataReaders = [[NSMutableDictionary alloc] init];
|
2008-03-01 15:32:28 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
self.propertiesReadersByExtension = [[NSMutableDictionary alloc] init];
|
|
|
|
self.propertiesReadersByMimeType = [[NSMutableDictionary alloc] init];
|
2008-03-01 15:32:28 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
self.decodersByExtension = [[NSMutableDictionary alloc] init];
|
|
|
|
self.decodersByMimeType = [[NSMutableDictionary alloc] init];
|
2015-04-13 07:39:24 +00:00
|
|
|
|
2008-03-01 15:28:17 +00:00
|
|
|
[self setup];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setup
|
|
|
|
{
|
2008-03-01 15:28:17 +00:00
|
|
|
if (self.configured == NO) {
|
2008-03-01 15:32:28 +00:00
|
|
|
self.configured = YES;
|
2007-10-20 15:46:39 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bundleDidLoad:) name:NSBundleDidLoadNotification object:nil];
|
|
|
|
|
|
|
|
[self loadPlugins];
|
|
|
|
[self printPluginInfo];
|
|
|
|
}
|
|
|
|
}
|
2007-02-24 20:36:27 +00:00
|
|
|
|
2007-10-20 15:46:39 +00:00
|
|
|
- (void)bundleDidLoad:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
NSArray *classNames = [[notification userInfo] objectForKey:@"NSLoadedClasses"];
|
2021-12-28 01:46:09 +00:00
|
|
|
for (NSString *className in classNames)
|
|
|
|
{
|
|
|
|
Class bundleClass = NSClassFromString(className);
|
|
|
|
if ([bundleClass conformsToProtocol:@protocol(CogVersionCheck)]) {
|
|
|
|
DLog(@"Component has version check: %@", className);
|
|
|
|
if (![bundleClass shouldLoadForOSVersion:[[NSProcessInfo processInfo] operatingSystemVersion]])
|
|
|
|
{
|
|
|
|
DLog(@"Plugin fails OS version check, ignoring");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-03-01 15:04:46 +00:00
|
|
|
for (NSString *className in classNames)
|
2007-10-20 15:46:39 +00:00
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Class loaded: %@", className);
|
2007-10-20 15:46:39 +00:00
|
|
|
Class bundleClass = NSClassFromString(className);
|
|
|
|
if ([bundleClass conformsToProtocol:@protocol(CogContainer)]) {
|
|
|
|
[self setupContainer:className];
|
|
|
|
}
|
2009-03-01 04:12:47 +00:00
|
|
|
if ([bundleClass conformsToProtocol:@protocol(CogDecoder)]) {
|
2007-10-20 15:46:39 +00:00
|
|
|
[self setupDecoder:className];
|
|
|
|
}
|
2009-03-01 04:12:47 +00:00
|
|
|
if ([bundleClass conformsToProtocol:@protocol(CogMetadataReader)]) {
|
2007-10-20 15:46:39 +00:00
|
|
|
[self setupMetadataReader:className];
|
|
|
|
}
|
2009-03-01 04:12:47 +00:00
|
|
|
if ([bundleClass conformsToProtocol:@protocol(CogPropertiesReader)]) {
|
2007-10-20 15:46:39 +00:00
|
|
|
[self setupPropertiesReader:className];
|
|
|
|
}
|
2009-03-01 04:12:47 +00:00
|
|
|
if ([bundleClass conformsToProtocol:@protocol(CogSource)]) {
|
2007-10-20 15:46:39 +00:00
|
|
|
[self setupSource:className];
|
|
|
|
}
|
|
|
|
}
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadPluginsAtPath:(NSString *)path
|
|
|
|
{
|
|
|
|
|
2013-10-03 08:00:58 +00:00
|
|
|
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
|
2007-02-24 20:36:27 +00:00
|
|
|
|
2008-03-01 15:28:17 +00:00
|
|
|
for (NSString *pname in dirContents)
|
2007-02-24 20:36:27 +00:00
|
|
|
{
|
|
|
|
NSString *ppath;
|
|
|
|
ppath = [NSString pathWithComponents:[NSArray arrayWithObjects:path,pname,nil]];
|
|
|
|
|
|
|
|
if ([[pname pathExtension] isEqualToString:@"bundle"])
|
|
|
|
{
|
|
|
|
NSBundle *b = [NSBundle bundleWithPath:ppath];
|
2007-10-20 15:46:39 +00:00
|
|
|
[b load];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadPlugins
|
|
|
|
{
|
2021-12-24 09:01:21 +00:00
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *basePath = [[paths firstObject] stringByAppendingPathComponent:@"Cog"];
|
|
|
|
|
|
|
|
[self loadPluginsAtPath:[[NSBundle mainBundle] builtInPlugInsPath]];
|
|
|
|
[self loadPluginsAtPath:[basePath stringByAppendingPathComponent:@"Plugins"]];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 01:20:46 +00:00
|
|
|
- (void)setupContainer:(NSString *)className
|
|
|
|
{
|
|
|
|
Class container = NSClassFromString(className);
|
|
|
|
if (container && [container respondsToSelector:@selector(fileTypes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id fileType in [container fileTypes])
|
2007-10-09 01:20:46 +00:00
|
|
|
{
|
2015-04-13 07:39:24 +00:00
|
|
|
NSString *ext = [fileType lowercaseString];
|
|
|
|
NSMutableArray *containerSet;
|
|
|
|
if (![containers objectForKey:ext])
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
containerSet = [[NSMutableArray alloc] init];
|
2015-04-13 07:39:24 +00:00
|
|
|
[containers setObject:containerSet forKey:ext];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
containerSet = [containers objectForKey:ext];
|
|
|
|
[containerSet addObject:className];
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
- (void)setupDecoder:(NSString *)className
|
2007-02-24 20:36:27 +00:00
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
Class decoder = NSClassFromString(className);
|
|
|
|
if (decoder && [decoder respondsToSelector:@selector(fileTypes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id fileType in [decoder fileTypes])
|
2007-03-02 01:36:52 +00:00
|
|
|
{
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
NSString *ext = [fileType lowercaseString];
|
|
|
|
NSMutableArray *decoders;
|
|
|
|
if (![decodersByExtension objectForKey:ext])
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
decoders = [[NSMutableArray alloc] init];
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
[decodersByExtension setObject:decoders forKey:ext];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
decoders = [decodersByExtension objectForKey:ext];
|
|
|
|
[decoders addObject:className];
|
2007-10-14 18:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decoder && [decoder respondsToSelector:@selector(mimeTypes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id mimeType in [decoder mimeTypes])
|
2007-10-14 18:12:15 +00:00
|
|
|
{
|
2021-12-23 00:22:49 +00:00
|
|
|
NSString *mimetype = [mimeType lowercaseString];
|
|
|
|
NSMutableArray *decoders;
|
|
|
|
if (![decodersByMimeType objectForKey:mimetype])
|
|
|
|
{
|
|
|
|
decoders = [[NSMutableArray alloc] init];
|
|
|
|
[decodersByMimeType setObject:decoders forKey:mimetype];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
decoders = [decodersByMimeType objectForKey:mimetype];
|
|
|
|
[decoders addObject:className];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-24 20:36:27 +00:00
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
- (void)setupMetadataReader:(NSString *)className
|
|
|
|
{
|
|
|
|
Class metadataReader = NSClassFromString(className);
|
|
|
|
if (metadataReader && [metadataReader respondsToSelector:@selector(fileTypes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id fileType in [metadataReader fileTypes])
|
2007-03-02 01:36:52 +00:00
|
|
|
{
|
2015-04-13 07:39:24 +00:00
|
|
|
NSString *ext = [fileType lowercaseString];
|
|
|
|
NSMutableArray *readers;
|
|
|
|
if (![metadataReaders objectForKey:ext])
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
readers = [[NSMutableArray alloc] init];
|
2015-04-13 07:39:24 +00:00
|
|
|
[metadataReaders setObject:readers forKey:ext];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
readers = [metadataReaders objectForKey:ext];
|
|
|
|
[readers addObject:className];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
2007-03-02 01:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-24 20:36:27 +00:00
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
- (void)setupPropertiesReader:(NSString *)className
|
|
|
|
{
|
|
|
|
Class propertiesReader = NSClassFromString(className);
|
|
|
|
if (propertiesReader && [propertiesReader respondsToSelector:@selector(fileTypes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id fileType in [propertiesReader fileTypes])
|
2007-03-02 01:36:52 +00:00
|
|
|
{
|
2015-04-13 07:39:24 +00:00
|
|
|
NSString *ext = [fileType lowercaseString];
|
|
|
|
NSMutableArray *readers;
|
|
|
|
if (![propertiesReadersByExtension objectForKey:ext])
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
readers = [[NSMutableArray alloc] init];
|
2015-04-13 07:39:24 +00:00
|
|
|
[propertiesReadersByExtension setObject:readers forKey:ext];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
readers = [propertiesReadersByExtension objectForKey:ext];
|
|
|
|
[readers addObject:className];
|
2007-10-14 18:12:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (propertiesReader && [propertiesReader respondsToSelector:@selector(mimeTypes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id mimeType in [propertiesReader mimeTypes])
|
2007-10-14 18:12:15 +00:00
|
|
|
{
|
2021-12-23 00:22:49 +00:00
|
|
|
NSString *mimetype = [mimeType lowercaseString];
|
|
|
|
NSMutableArray *readers;
|
|
|
|
if (![propertiesReadersByMimeType objectForKey:mimetype])
|
|
|
|
{
|
|
|
|
readers = [[NSMutableArray alloc] init];
|
|
|
|
[propertiesReadersByMimeType setObject:readers forKey:mimetype];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
readers = [propertiesReadersByMimeType objectForKey:mimetype];
|
|
|
|
[readers addObject:className];
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-02 01:36:52 +00:00
|
|
|
- (void)setupSource:(NSString *)className
|
|
|
|
{
|
|
|
|
Class source = NSClassFromString(className);
|
|
|
|
if (source && [source respondsToSelector:@selector(schemes)]) {
|
2008-03-01 15:28:17 +00:00
|
|
|
for (id scheme in [source schemes])
|
2007-03-02 01:36:52 +00:00
|
|
|
{
|
|
|
|
[sources setObject:className forKey:scheme];
|
|
|
|
}
|
|
|
|
}
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)printPluginInfo
|
|
|
|
{
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"Sources: %@", self.sources);
|
|
|
|
ALog(@"Containers: %@", self.containers);
|
|
|
|
ALog(@"Metadata Readers: %@", self.metadataReaders);
|
2007-10-14 18:12:15 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"Properties Readers By Extension: %@", self.propertiesReadersByExtension);
|
|
|
|
ALog(@"Properties Readers By Mime Type: %@", self.propertiesReadersByMimeType);
|
2007-10-14 18:12:15 +00:00
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
ALog(@"Decoders by Extension: %@", self.decodersByExtension);
|
|
|
|
ALog(@"Decoders by Mime Type: %@", self.decodersByMimeType);
|
2007-02-24 20:36:27 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 01:20:46 +00:00
|
|
|
- (id<CogSource>) audioSourceForURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
NSString *scheme = [url scheme];
|
|
|
|
|
|
|
|
Class source = NSClassFromString([sources objectForKey:scheme]);
|
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
return [[source alloc] init];
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) urlsForContainerURL:(NSURL *)url
|
|
|
|
{
|
2016-06-19 19:57:18 +00:00
|
|
|
NSString *ext = [url pathExtension];
|
2015-04-13 07:39:24 +00:00
|
|
|
NSArray *containerSet = [containers objectForKey:[ext lowercaseString]];
|
|
|
|
NSString *classString;
|
|
|
|
if (containerSet) {
|
|
|
|
if ( [containerSet count] > 1 ) {
|
|
|
|
return [CogContainerMulti urlsForContainerURL:url containers:containerSet];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = [containerSet objectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nil;
|
|
|
|
}
|
2007-10-09 01:20:46 +00:00
|
|
|
|
2015-04-13 07:39:24 +00:00
|
|
|
Class container = NSClassFromString(classString);
|
2007-10-09 01:20:46 +00:00
|
|
|
|
|
|
|
return [container urlsForContainerURL:url];
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:12:15 +00:00
|
|
|
//Note: Source is assumed to already be opened.
|
|
|
|
- (id<CogDecoder>) audioDecoderForSource:(id <CogSource>)source
|
2007-10-09 01:20:46 +00:00
|
|
|
{
|
2016-06-19 19:57:18 +00:00
|
|
|
NSString *ext = [[source url] pathExtension];
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
NSArray *decoders = [decodersByExtension objectForKey:[ext lowercaseString]];
|
|
|
|
NSString *classString;
|
|
|
|
if (decoders) {
|
|
|
|
if ( [decoders count] > 1 ) {
|
2016-05-05 20:05:39 +00:00
|
|
|
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = [decoders objectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-12-23 00:22:49 +00:00
|
|
|
decoders = [decodersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
|
|
|
if (decoders) {
|
|
|
|
if ( [decoders count] > 1 ) {
|
|
|
|
return [[CogDecoderMulti alloc] initWithDecoders:decoders];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = [decoders objectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = @"SilenceDecoder";
|
|
|
|
}
|
2007-10-14 18:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Class decoder = NSClassFromString(classString);
|
2007-10-09 01:20:46 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
return [[decoder alloc] init];
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)metadataForURL:(NSURL *)url
|
|
|
|
{
|
2021-02-28 10:47:00 +00:00
|
|
|
NSString * urlScheme = [url scheme];
|
|
|
|
if ([urlScheme isEqualToString:@"http"] ||
|
|
|
|
[urlScheme isEqualToString:@"https"])
|
|
|
|
return nil;
|
|
|
|
|
2016-06-19 19:57:18 +00:00
|
|
|
NSString *ext = [url pathExtension];
|
2015-04-13 07:39:24 +00:00
|
|
|
NSArray *readers = [metadataReaders objectForKey:[ext lowercaseString]];
|
|
|
|
NSString *classString;
|
|
|
|
if (readers) {
|
|
|
|
if ( [readers count] > 1 ) {
|
|
|
|
return [CogMetadataReaderMulti metadataForURL:url readers:readers];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = [readers objectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return nil;
|
|
|
|
}
|
2007-10-09 01:20:46 +00:00
|
|
|
|
2015-04-13 07:39:24 +00:00
|
|
|
Class metadataReader = NSClassFromString(classString);
|
2007-10-09 01:20:46 +00:00
|
|
|
|
|
|
|
return [metadataReader metadataForURL:url];
|
|
|
|
}
|
|
|
|
|
2007-10-14 17:31:20 +00:00
|
|
|
|
|
|
|
//If no properties reader is defined, use the decoder's properties.
|
2007-10-09 01:20:46 +00:00
|
|
|
- (NSDictionary *)propertiesForURL:(NSURL *)url
|
|
|
|
{
|
2021-02-28 10:47:00 +00:00
|
|
|
NSString * urlScheme = [url scheme];
|
|
|
|
if ([urlScheme isEqualToString:@"http"] ||
|
|
|
|
[urlScheme isEqualToString:@"https"])
|
|
|
|
return nil;
|
|
|
|
|
2020-02-16 09:00:39 +00:00
|
|
|
NSDictionary *properties = nil;
|
2016-06-19 19:57:18 +00:00
|
|
|
NSString *ext = [url pathExtension];
|
2007-10-09 01:20:46 +00:00
|
|
|
|
|
|
|
id<CogSource> source = [self audioSourceForURL:url];
|
|
|
|
if (![source open:url])
|
|
|
|
return nil;
|
2015-04-13 07:39:24 +00:00
|
|
|
|
|
|
|
NSArray *readers = [propertiesReadersByExtension objectForKey:[ext lowercaseString]];
|
2020-02-16 09:00:39 +00:00
|
|
|
NSString *classString = nil;
|
2015-04-13 07:39:24 +00:00
|
|
|
if (readers)
|
|
|
|
{
|
|
|
|
if ( [readers count] > 1 ) {
|
2020-02-16 09:00:39 +00:00
|
|
|
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
|
|
|
if (properties != nil && [properties count])
|
|
|
|
return properties;
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = [readers objectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-12-23 00:22:49 +00:00
|
|
|
readers = [propertiesReadersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
|
|
|
if (readers)
|
|
|
|
{
|
|
|
|
if ( [readers count] > 1 ) {
|
|
|
|
properties = [CogPropertiesReaderMulti propertiesForSource:source readers:readers];
|
|
|
|
if (properties != nil && [properties count])
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
classString = [readers objectAtIndex:0];
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
2007-10-14 18:12:15 +00:00
|
|
|
|
2007-10-14 17:31:20 +00:00
|
|
|
if (classString)
|
|
|
|
{
|
|
|
|
Class propertiesReader = NSClassFromString(classString);
|
2007-03-02 01:36:52 +00:00
|
|
|
|
2020-02-16 09:00:39 +00:00
|
|
|
properties = [propertiesReader propertiesForSource:source];
|
|
|
|
if (properties != nil && [properties count])
|
|
|
|
return properties;
|
2007-10-14 17:31:20 +00:00
|
|
|
}
|
2020-02-16 09:00:39 +00:00
|
|
|
|
|
|
|
{
|
2007-10-14 18:12:15 +00:00
|
|
|
id<CogDecoder> decoder = [self audioDecoderForSource:source];
|
2007-10-14 17:31:20 +00:00
|
|
|
if (![decoder open:source])
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSDictionary *properties = [decoder properties];
|
|
|
|
|
|
|
|
[decoder close];
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
2007-10-09 01:20:46 +00:00
|
|
|
}
|
2007-03-02 01:36:52 +00:00
|
|
|
|
2013-10-03 08:00:58 +00:00
|
|
|
- (int)putMetadataInURL:(NSURL *)url
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
@end
|
|
|
|
|