Cog/Plugins/OpenMPT/OpenMPT/OMPTMetadataReader.mm
Christopher Snowhill 32a595222d [OpenMPT / vgmstream] Made libraries pre-built
Made the OpenMPT / legacy OpenMPT and mpg123 libraries pre-built.
Changed the OpenMPT and vgmstream plugins to import the libraries as
they are now. Made mpg123 embedded and imported by the main binary,
since it's now shared by two plugins.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-24 17:09:02 -07:00

98 lines
2.3 KiB
Text

//
// OMPTMetadataReader.m
// OpenMPT
//
// Created by Christopher Snowhill on 1/4/18.
// Copyright 2018 __LoSnoCo__. All rights reserved.
//
#import "OMPTMetadataReader.h"
#import "OMPTDecoder.h"
#import <libopenmpt/libopenmpt.hpp>
#import "Logging.H"
@implementation OMPTMetadataReader
+ (NSArray *)fileTypes {
return [OMPTDecoder fileTypes];
}
+ (NSArray *)mimeTypes {
return [OMPTDecoder 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];
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")
title = guess_encoding_of_string(mod->get_metadata(*key).c_str());
else if(*key == "artist")
artist = guess_encoding_of_string(mod->get_metadata(*key).c_str());
/*else if ( *key == "message" )
comment = guess_encoding_of_string(mod->get_metadata( *key ).c_str());*/
else if(*key == "date")
date = guess_encoding_of_string(mod->get_metadata(*key).c_str());
else if(*key == "type_long")
type = guess_encoding_of_string(mod->get_metadata(*key).c_str());
}
delete mod;
if(title == nil)
title = @"";
if(artist == nil)
artist = @"";
/*if (comment == nil)
comment = @"";*/
if(date == nil)
date = @"";
if(type == nil)
type = @"";
return @{ @"title": title, @"artist": artist, /*@"comment": comment,*/ @"year": @([date intValue]), @"codec": type };
} catch(std::exception & /*e*/) {
return 0;
}
}
@end