Most file formats the player supports may or may not have UTF-8 safe strings in their metadata. This should not be assumed to be UTF-8, and when it is assumed, it results in nil NSString objects, which results in inline initializers crashing due to uncaught exceptions. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
62 lines
1.2 KiB
Objective-C
62 lines
1.2 KiB
Objective-C
//
|
|
// HVLMetadataReader.m
|
|
// Hively
|
|
//
|
|
// Created by Christopher Snowhill on 10/29/13.
|
|
// Copyright 2013 __NoWork, Inc__. All rights reserved.
|
|
//
|
|
|
|
#import "HVLMetadataReader.h"
|
|
#import "HVLDecoder.h"
|
|
|
|
@implementation HVLMetadataReader
|
|
|
|
+ (NSArray *)fileTypes {
|
|
return [HVLDecoder fileTypes];
|
|
}
|
|
|
|
+ (NSArray *)mimeTypes {
|
|
return [HVLDecoder mimeTypes];
|
|
}
|
|
|
|
+ (float)priority {
|
|
return 1.0f;
|
|
}
|
|
|
|
+ (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];
|
|
|
|
if(size > UINT_MAX)
|
|
return nil;
|
|
|
|
void *data = malloc(size);
|
|
[source read:data amount:size];
|
|
|
|
struct hvl_tune *tune = hvl_LoadTune(data, (uint32_t)size, 44100, 2);
|
|
free(data);
|
|
if(!tune)
|
|
return nil;
|
|
|
|
NSString *title = [guess_encoding_of_string(tune->ht_Name) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
|
|
hvl_FreeTune(tune);
|
|
|
|
if(title == nil) {
|
|
title = @"";
|
|
}
|
|
|
|
return @{@"title": title};
|
|
}
|
|
|
|
@end
|