cog/Plugins/TagLib/TagLibMetadataWriter.m

77 lines
1.8 KiB
Matlab
Raw Normal View History

2008-12-15 10:27:28 +00:00
//
// TagLibMetadataWriter.m
// TagLib
//
// Created by Safari on 08/11/17.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "TagLibMetadataWriter.h"
2021-01-27 02:12:07 +00:00
#import <taglib/fileref.h>
#import <taglib/tag.h>
2008-12-15 10:27:28 +00:00
#import "Logging.h"
2008-12-15 10:27:28 +00:00
@implementation TagLibMetadataWriter
+ (int)putMetadataInURL:(NSURL *)url tagData:(NSDictionary *)tagData {
2008-12-15 10:27:28 +00:00
NSString *lArtist = @"", *lTitle = @"", *lAlbum = @"", *lGenre = @"";
// int lYear = 0, lTrack = 0;
2008-12-15 10:27:28 +00:00
TagLib::FileRef f((const char *)[[url path] UTF8String], false);
if(!f.isNull()) {
2008-12-15 10:27:28 +00:00
const TagLib::Tag *tag = f.tag();
if(tag) {
2008-12-15 10:27:28 +00:00
const TagLib::String pArtist, pTitle, pAlbum, pGenre, pComment;
2008-12-15 10:27:28 +00:00
lArtist = [tagData valueForKey:@"artist"];
lTitle = [tagData valueForKey:@"title"];
lAlbum = [tagData valueForKey:@"album"];
lGenre = [tagData valueForKey:@"genre"];
2008-12-15 10:27:28 +00:00
f.tag()->setTitle([lTitle UTF8String]);
f.tag()->setArtist([lArtist UTF8String]);
}
/*
NSArray *keys = @[@"key1", @"key2", @"key3"];
NSArray *objects = @[@"value1", @"value2", @"value3"];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
for (id key in dictionary)
{
DLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);
}
pArtist = tag->artist();
pTitle = tag->title();;
pAlbum = tag->album();
pGenre = tag->genre();
pComment = tag->comment();
lYear = tag->year();
lTrack = tag->track();
lDisc = tag->disc();
if (!pArtist.isNull())
lArtist = [NSString stringWithUTF8String:pArtist.toCString(true)];
if (!pAlbum.isNull())
lAlbum = [NSString stringWithUTF8String:pAlbum.toCString(true)];
if (!pTitle.isNull())
lTitle = [NSString stringWithUTF8String:pTitle.toCString(true)];
if (!pGenre.isNull())
lGenre = [NSString stringWithUTF8String:pGenre.toCString(true)];
*/
2008-12-15 10:27:28 +00:00
}
return 0;
}
@end