2021-12-26 11:29:43 +00:00
|
|
|
//
|
|
|
|
// OMPTMetadataReader.m
|
|
|
|
// OpenMPT
|
|
|
|
//
|
|
|
|
// Created by Christopher Snowhill on 1/4/18.
|
|
|
|
// Copyright 2018 __LoSnoCo__. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "OMPTMetadataReader.h"
|
|
|
|
#import "OMPTDecoder.h"
|
|
|
|
|
2022-01-07 07:53:39 +00:00
|
|
|
#import <libOpenMPTOld/libopenmpt.hpp>
|
2021-12-26 11:29:43 +00:00
|
|
|
|
|
|
|
#import "Logging.H"
|
|
|
|
|
|
|
|
@implementation OMPTOldMetadataReader
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)fileTypes {
|
2021-12-26 11:29:43 +00:00
|
|
|
return [OMPTOldDecoder fileTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (NSArray *)mimeTypes {
|
2021-12-26 11:29:43 +00:00
|
|
|
return [OMPTOldDecoder mimeTypes];
|
|
|
|
}
|
|
|
|
|
2022-02-07 05:49:27 +00:00
|
|
|
+ (float)priority {
|
|
|
|
return [OMPTOldDecoder priority];
|
2021-12-26 11:29:43 +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];
|
|
|
|
|
|
|
|
std::vector<char> data(static_cast<std::size_t>(size));
|
|
|
|
|
|
|
|
[source read:data.data() amount:size];
|
|
|
|
|
|
|
|
int track_num;
|
|
|
|
if([[url fragment] length] == 0)
|
|
|
|
track_num = 0;
|
|
|
|
else
|
|
|
|
track_num = [[url fragment] intValue];
|
|
|
|
|
|
|
|
try {
|
|
|
|
std::map<std::string, std::string> ctls;
|
|
|
|
openmpt::module *mod = new openmpt::module(data, std::clog, ctls);
|
|
|
|
|
|
|
|
NSString *title = nil;
|
|
|
|
NSString *artist = nil;
|
|
|
|
// NSString * comment = nil;
|
|
|
|
NSString *date = nil;
|
|
|
|
NSString *type = nil;
|
|
|
|
|
|
|
|
std::vector<std::string> keys = mod->get_metadata_keys();
|
|
|
|
|
|
|
|
for(std::vector<std::string>::iterator key = keys.begin(); key != keys.end(); ++key) {
|
|
|
|
if(*key == "title")
|
2022-05-24 08:07:55 +00:00
|
|
|
title = guess_encoding_of_string(mod->get_metadata(*key).c_str());
|
2022-02-07 05:49:27 +00:00
|
|
|
else if(*key == "artist")
|
2022-05-24 08:07:55 +00:00
|
|
|
artist = guess_encoding_of_string(mod->get_metadata(*key).c_str());
|
2022-02-07 05:49:27 +00:00
|
|
|
/*else if ( *key == "message" )
|
2022-05-24 08:07:55 +00:00
|
|
|
comment = guess_encoding_of_string(mod->get_metadata( *key ).c_str());*/
|
2022-02-07 05:49:27 +00:00
|
|
|
else if(*key == "date")
|
2022-05-24 08:07:55 +00:00
|
|
|
date = guess_encoding_of_string(mod->get_metadata(*key).c_str());
|
2022-02-07 05:49:27 +00:00
|
|
|
else if(*key == "type_long")
|
2022-05-24 08:07:55 +00:00
|
|
|
type = guess_encoding_of_string(mod->get_metadata(*key).c_str());
|
2022-02-07 05:49:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete mod;
|
|
|
|
|
|
|
|
if(title == nil)
|
|
|
|
title = @"";
|
|
|
|
if(artist == nil)
|
|
|
|
artist = @"";
|
|
|
|
/*if (comment == nil)
|
|
|
|
comment = @"";*/
|
|
|
|
if(date == nil)
|
|
|
|
date = @"";
|
|
|
|
if(type == nil)
|
|
|
|
type = @"";
|
|
|
|
|
2022-06-17 13:39:02 +00:00
|
|
|
return @{ @"title": title, @"artist": artist, /*@"comment": comment,*/ @"year": @([date intValue]), @"codec": type };
|
2022-02-07 05:49:27 +00:00
|
|
|
} catch(std::exception & /*e*/) {
|
|
|
|
return 0;
|
|
|
|
}
|
2021-12-26 11:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|