Skip to content

Instantly share code, notes, and snippets.

@atr000
Created February 8, 2010 06:03
Show Gist options
  • Save atr000/297925 to your computer and use it in GitHub Desktop.
Save atr000/297925 to your computer and use it in GitHub Desktop.
#include <id3/tag.h>
#include <id3/misc_support.h>
#import <UniversalDetector/UniversalDetector.h>
#import <Cocoa/Cocoa.h>
static void ut(NSMutableDictionary *t, NSString *n, NSString *a, NSString *al)
{
if (n) [t setObject:n forKey:@"Name"];
if (a) [t setObject:a forKey:@"Artist"];
if (al) [t setObject:al forKey:@"Album"];
}
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *error;
NSPropertyListFormat format;
NSData *lib = [NSData dataWithContentsOfFile:@"/Library.xml"];
NSDictionary *inDict = (NSDictionary *)[NSPropertyListSerialization propertyListFromData:lib
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format
errorDescription:&error];
NSDictionary *t = [inDict objectForKey:@"Tracks"];
NSEnumerator *e = [t keyEnumerator];
NSString *en;
while (en = [e nextObject]) {
NSMutableDictionary *track = [t objectForKey:en];
// printf("%d\n", (int)[[track objectForKey:@"Track ID"] intValue]);
NSString *on=[track objectForKey:@"Name"],*oa=[track objectForKey:@"Artist"],*oal=[track objectForKey:@"Album"];
NSString *qs = [NSString stringWithFormat:@"name: %@ artist: %@ album: %@?\n",on,
oa,oal];
if ([qs canBeConvertedToEncoding:NSASCIIStringEncoding] || ![[track objectForKey:@"Location"] hasSuffix:@"mp3"]) continue;
char res[10];
printf([qs UTF8String]);
scanf("%s",res);
if (res[0]=='y') continue;
char *sn,*sa,*sal;
NSStringEncoding enc = NSShiftJISStringEncoding;
NSString *nsn=nil, *nsa=nil, *nsal=nil;
[[NSData dataWithContentsOfURL:[NSURL URLWithString:[track objectForKey:@"Location"]]] writeToFile:@"/tmp/t.mp3" atomically:NO];
ID3_Tag tag("/tmp/t.mp3");
sn = ID3_GetTitle(&tag);
sa = ID3_GetArtist(&tag);
sal = ID3_GetAlbum(&tag);
if (on&&sn) nsn = [NSString stringWithCString:sn encoding:enc];
if (oa&&sa) nsa = [NSString stringWithCString:sa encoding:enc];
if (oal&&sal) nsal = [NSString stringWithCString:sal encoding:enc];
qs = [NSString stringWithFormat:@"name: %@ artist: %@ album: %@?\n",nsn,nsa,nsal];
printf([qs UTF8String]);
scanf("%s",res);
if (res[0]=='y') {ut(track,nsn,nsa,nsal); continue;}
enc = NSUTF8StringEncoding;
if (on&&sn) nsn = [NSString stringWithCString:sn encoding:enc];
if (oa&&sa) nsa = [NSString stringWithCString:sa encoding:enc];
if (oal&&sal) nsal = [NSString stringWithCString:sal encoding:enc];
qs = [NSString stringWithFormat:@"name: %@ artist: %@ album: %@?\n",nsn,nsa,nsal];
printf([qs UTF8String]);
scanf("%s",res);
if (res[0]=='y') {ut(track,nsn,nsa,nsal); continue;}
[pool release];
pool = [[NSAutoreleasePool alloc] init];
}
NSData *xmlData = [NSPropertyListSerialization dataFromPropertyList:inDict
format:NSPropertyListXMLFormat_v1_0
errorDescription:nil];
if(xmlData)
{
[xmlData writeToFile:@"/up.xml" atomically:NO];
}
[pool release];
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment