cog/Plugins/TagLib/TagLibMetadataReader.m

86 lines
2.0 KiB
Matlab
Raw Normal View History

//
// TagLibMetadataReader.m
// TagLib
//
// Created by Vincent Spader on 2/24/07.
// Copyright 2007 __MyCompanyName__. All rights reserved.
//
#import "TagLibMetadataReader.h"
#import "TagLib/tag_c.h"
@implementation TagLibMetadataReader
+ (NSDictionary *)metadataForURL:(NSURL *)url
{
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
int lYear = 0, lTrack = 0;
TagLib_File *tagFile = taglib_file_new((const char *)[[url path] UTF8String]);
if (tagFile)
{
TagLib_Tag *tag = taglib_file_tag(tagFile);
if (tag)
{
char *pArtist, *pTitle, *pAlbum, *pGenre, *pComment;
pArtist = taglib_tag_artist(tag);
pTitle = taglib_tag_title(tag);
pAlbum = taglib_tag_album(tag);
pGenre = taglib_tag_genre(tag);
pComment = taglib_tag_comment(tag);
lYear = taglib_tag_year(tag);
lTrack = taglib_tag_track(tag);
if (pArtist != NULL)
lArtist = [NSString stringWithUTF8String:(char *)pArtist];
else
lArtist = @"";
if (pAlbum != NULL)
lAlbum = [NSString stringWithUTF8String:(char *)pAlbum];
else
lAlbum = @"";
if (pTitle != NULL)
lTitle = [NSString stringWithUTF8String:(char *)pTitle];
else
lTitle = @"";
if (pGenre != NULL)
lGenre = [NSString stringWithUTF8String:(char *)pGenre];
else
lGenre = @"";
taglib_tag_free_strings();
}
taglib_file_free(tagFile);
}
return [NSDictionary dictionaryWithObjectsAndKeys:
lArtist, @"artist",
lTitle, @"title",
lAlbum, @"album",
lGenre, @"genre",
[[NSNumber numberWithInt: lYear] stringValue], @"year",
[NSNumber numberWithInt: lTrack], @"track",
nil];
}
+ (NSArray *)fileTypes
{
//May be a way to get a list of supported formats
2007-10-16 22:45:09 +00:00
return [NSArray arrayWithObjects:@"ogg", @"mpc", @"flac", @"m4a", @"mp3", nil];
2007-10-14 18:56:23 +00:00
}
+ (NSArray *)mimeTypes
{
2007-10-16 22:45:09 +00:00
return [NSArray arrayWithObjects:@"application/ogg", @"application/x-ogg", @"audio/x-vorbis+ogg", @"audio/x-musepack", @"audio/x-flac", @"audio/x-m4a", @"audio/mpeg", @"audio/x-mp3", nil];
}
@end