cog/Plugins/TagLib/TagLibMetadataReader.m

82 lines
1.9 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/fileref.h>
#import <TagLib/tag.h>
@implementation TagLibMetadataReader
+ (NSDictionary *)metadataForURL:(NSURL *)url
{
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
int lYear = 0, lTrack = 0;
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
if (!f.isNull())
{
const TagLib::Tag *tag = f.tag();
if (tag)
{
TagLib::String pArtist, pTitle, pAlbum, pGenre, pComment;
pArtist = tag->artist();
pTitle = tag->title();;
pAlbum = tag->album();
pGenre = tag->genre();
pComment = tag->comment();
lYear = tag->year();
lTrack = tag->track();
if (!pArtist.isNull())
lArtist = [NSString stringWithUTF8String:pArtist.toCString(true)];
else
lArtist = @"";
if (!pAlbum.isNull())
lAlbum = [NSString stringWithUTF8String:pAlbum.toCString(true)];
else
lAlbum = @"";
if (!pTitle.isNull())
lTitle = [NSString stringWithUTF8String:pTitle.toCString(true)];
else
lTitle = @"";
if (!pGenre.isNull())
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
else
lGenre = @"";
}
}
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