Permalink
Browse files

Merge https://github.com/k7d/EyeTunes

  • Loading branch information...
2 parents 4d050c5 + b67ad1c commit 9ab5355cfe9934ca4749a91c1b03fc1477392c17 @kgn committed Jun 23, 2011
Showing with 135 additions and 36 deletions.
  1. +3 −0 ETEyeTunes.h
  2. +110 −27 ETEyeTunes.m
  3. +15 −9 EyeTunes.xcodeproj/project.pbxproj
  4. +7 −0 main.m
View
@@ -111,6 +111,9 @@
- (void)stop;
- (id)addTrack:(NSURL *)fromLocation toPlaylist:(ETPlaylist *)playlist;
+- (void)deleteTrack:(ETTrack *)track;
+
+- (ETPlaylist*)addPlaylistWithName:(NSString*)name;
// TODO: - (id)convertTrack:(id)trackReference;
// TODO: - (void)refresh:(id)fileTrack;
View
@@ -479,55 +479,62 @@ - (id)addTrack:(NSURL *)fromLocation toPlaylist:(ETPlaylist *)playlist;
NSMutableArray *trackList = nil;
AliasHandle alias = [EyeTunes newAliasHandleWithPath:[fromLocation path]];
+
+ AEBuildError buildError;
- if (!playlist)
- {
- gizmo = @"'----':@@";
- }
- else
- {
+ if (!playlist) {
+ gizmo = @"'----':alis(@@)";
+ err = AEBuildAppleEvent(iTunesSignature, // class
+ ET_ADD_FILE, // ID
+ typeApplSignature, // address type
+ &iTunesSignature, // address data
+ sizeof(iTunesSignature), // address length
+ kAutoGenerateReturnID, // return ID
+ kAnyTransactionID, //transaction ID
+ &getEvent, // result
+ &buildError, // error
+ [gizmo UTF8String], // params format
+ alias);
+ } else {
gizmo = [NSString stringWithFormat:@"'----':alis(@@), insh:(@)"];
+ err = AEBuildAppleEvent(iTunesSignature, // class
+ ET_ADD_FILE, // ID
+ typeApplSignature, // address type
+ &iTunesSignature, // address data
+ sizeof(iTunesSignature), // address length
+ kAutoGenerateReturnID, // return ID
+ kAnyTransactionID, //transaction ID
+ &getEvent, // result
+ &buildError, // error
+ [gizmo UTF8String], // params format
+ alias, // ... (var args)
+ [playlist descriptor]);
}
- AEBuildError buildError;
-
- err = AEBuildAppleEvent(iTunesSignature, // class
- ET_ADD_FILE, // ID
- typeApplSignature, // address type
- &iTunesSignature, // address data
- sizeof(iTunesSignature), // address length
- kAutoGenerateReturnID, // return ID
- kAnyTransactionID, //transaction ID
- &getEvent, // result
- &buildError, // error
- [gizmo UTF8String], // params format
- alias, // ... (var args)
- [playlist descriptor]);
-
DisposeHandle((Handle)alias);
- if (err != noErr) {
- ETLog(@"Error creating Apple Event: %d", err);
+ if (err != noErr) {
+ ETLog(@"Error creating AppleEvent: %d | %s | %s", err, GetMacOSStatusErrorString(err), GetMacOSStatusCommentString(err));
return nil;
}
err = AESendMessage(&getEvent, &replyEvent, kAEWaitReply + kAENeverInteract, kAEDefaultTimeout);
if (err != noErr) {
- ETLog(@"Error sending AppleEvent: %d", err);
+ ETLog(@"Error sending AppleEvent: %d | %s | %s", err, GetMacOSStatusErrorString(err), GetMacOSStatusCommentString(err));
goto cleanup_get_event;
}
/* Read Results */
err = AEGetParamDesc(&replyEvent, keyDirectObject, typeAEList, &replyList);
if (err != noErr) {
- ETLog(@"Error extracting from reply event: %d", err);
+ ETLog(@"Error extracting from reply event: %d | %s | %s", err, GetMacOSStatusErrorString(err), GetMacOSStatusCommentString(err));
goto cleanup_reply_event;
}
long items, i;
err = AECountItems(&replyList, &items);
if (err != noErr) {
- ETLog(@"Unable to access Reply List: %d", err);
+ ETLog(@"Unable to access Reply List: %d | %s | %s", err, GetMacOSStatusErrorString(err), GetMacOSStatusCommentString(err));
goto cleanup_reply_list;
}
@@ -540,7 +547,7 @@ - (id)addTrack:(NSURL *)fromLocation toPlaylist:(ETPlaylist *)playlist;
0,
&trackDesc);
if (err != noErr) {
- ETLog(@"Error rextracting from List: %d", err);
+ ETLog(@"Error rextracting from List: %d | %s | %s", err, GetMacOSStatusErrorString(err), GetMacOSStatusCommentString(err));
goto cleanup_reply_list;
}
[trackList addObject:[[[ETTrack alloc] initWithDescriptor:&trackDesc] autorelease]];
@@ -779,4 +786,80 @@ - (BOOL) versionLessThan:(unsigned int)version
return !!(currentVersion < version);
}
+- (ETPlaylist*)addPlaylistWithName:(NSString*)name
+{
+ OSErr err;
+ AppleEvent getEvent, replyEvent;
+ AEDescList replyObject;
+ ETPlaylist* playlist;
+ NSString *gizmo = [NSString stringWithFormat:@"kocl:type('cPly'), prdt: {pnam:'utxt'(\"%@\")}", name];
+
+ AEBuildError buildError;
+ err = AEBuildAppleEvent(kAECoreSuite, // class
+ kAECreateElement, // ID
+ typeApplSignature, // address type
+ &targetApplCode, // address data
+ sizeof(targetApplCode), // address length
+ kAutoGenerateReturnID, // return ID
+ kAnyTransactionID, //transaction ID
+ &getEvent, // result
+ &buildError, // error
+ [gizmo UTF8String]);
+
+ if (err != noErr) {
+ ETLog(@"Error creating Apple Event: %d", err);
+ return nil;
+ }
+
+ err = AESendMessage(&getEvent, &replyEvent, kAEWaitReply + kAENeverInteract, kAEDefaultTimeout);
+ if (err != noErr) {
+ ETLog(@"Error sending AppleEvent: %d", err);
+ goto cleanup_get_event;
+ }
+
+ err = AEGetParamDesc(&replyEvent, keyDirectObject, typeWildCard, &replyObject);
+ if (err != noErr) {
+ ETLog(@"Error extracting from reply event: %d", err);
+ goto cleanup_reply_event;
+ }
+
+ playlist = [[[ETPlaylist alloc] initWithDescriptor:&replyObject] autorelease];
+
+cleanup_reply_event:
+ AEDisposeDesc(&replyEvent);
+cleanup_get_event:
+ AEDisposeDesc(&getEvent);
+
+ return playlist;
+}
+
+
+- (void)deleteTrack:(ETTrack *)track {
+ OSErr err;
+ AppleEvent cmdEvent;
+
+ err = AEBuildAppleEvent(kAECoreSuite, // class
+ kAEDelete, // ID
+ typeApplSignature,
+ &iTunesSignature,
+ sizeof(iTunesSignature),
+ kAutoGenerateReturnID,
+ kAnyTransactionID,
+ &cmdEvent,
+ NULL,
+ "'----':@",
+ [track descriptor]);
+
+ if (err != noErr) {
+ ETLog(@"Error creating Apple Event: %d", err);
+ return;
+ }
+
+ err = AESendMessage(&cmdEvent, NULL, kAENoReply | kAENeverInteract, kAEDefaultTimeout);
+ if (err != noErr) {
+ ETLog(@"Error sending AppleEvent: %d", err);
+ }
+ AEDisposeDesc(&cmdEvent);
+}
+
@end
@@ -48,6 +48,10 @@
0396209A0C0DE71600786326 /* NSString+LongLongValue.m in Sources */ = {isa = PBXBuildFile; fileRef = 039620980C0DE71600786326 /* NSString+LongLongValue.m */; };
039620AC0C0DE78200786326 /* EyeTunes.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* EyeTunes.framework */; };
039620C80C0DE7CC00786326 /* EyeTunes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8DC2EF5B0486A6940098B216 /* EyeTunes.framework */; };
+ 638ADA371325160700B02DFB /* ETRootUserPlaylist.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2AB89A0E97A88800178457 /* ETRootUserPlaylist.m */; };
+ 638ADA391325160700B02DFB /* ETUserPlaylistEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = DD233EAB0E66FCC4004B210F /* ETUserPlaylistEnumerator.m */; };
+ 638ADA3D1325160700B02DFB /* ETPlaylistCache.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEBCBB70E8D0DAD00219086 /* ETPlaylistCache.m */; };
+ 638ADA3F1325160700B02DFB /* NSNumber+ETPlaylistNameSorting.m in Sources */ = {isa = PBXBuildFile; fileRef = DDEBCD330E8D245000219086 /* NSNumber+ETPlaylistNameSorting.m */; };
8DC2EF530486A6940098B216 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C1666FE841158C02AAC07 /* InfoPlist.strings */; };
DD233EB70E66FD45004B210F /* ETUserPlaylistEnumerator.m in Sources */ = {isa = PBXBuildFile; fileRef = DD233EAB0E66FCC4004B210F /* ETUserPlaylistEnumerator.m */; };
DD233EB80E66FD45004B210F /* ETUserPlaylistEnumerator.h in Headers */ = {isa = PBXBuildFile; fileRef = DD233EAA0E66FCC4004B210F /* ETUserPlaylistEnumerator.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -423,15 +427,19 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
- 037310E30C15D98E004AAA53 /* NSString+LongLongValue.m in Sources */,
037310CB0C15D92A004AAA53 /* ETEyeTunes.m in Sources */,
- 031B486908843CF90086F24B /* main.m in Sources */,
035B70BB0885537800D0B89E /* ETTrack.m in Sources */,
032CE8540886594100F33185 /* ETAppleEventObject.m in Sources */,
032CEB730886E48100F33185 /* ETPlaylist.m in Sources */,
032E44AF098A4F2B00C55ECB /* ETTrackEnumerator.m in Sources */,
032E476C098A8FDF00C55ECB /* ETPlaylistEnumerator.m in Sources */,
+ 638ADA371325160700B02DFB /* ETRootUserPlaylist.m in Sources */,
+ 638ADA391325160700B02DFB /* ETUserPlaylistEnumerator.m in Sources */,
030BF9AF098CFFD100D68616 /* ETDebug.m in Sources */,
+ 037310E30C15D98E004AAA53 /* NSString+LongLongValue.m in Sources */,
+ 638ADA3D1325160700B02DFB /* ETPlaylistCache.m in Sources */,
+ 638ADA3F1325160700B02DFB /* NSNumber+ETPlaylistNameSorting.m in Sources */,
+ 031B486908843CF90086F24B /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -518,10 +526,8 @@
031B481E088429A70086F24B /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- ARCHS = (
- ppc,
- i386,
- );
+ ARCHS = "$(ARCHS_STANDARD_64_BIT_PRE_XCODE_3_1)";
+ ARCHS_STANDARD_64_BIT_PRE_XCODE_3_1 = x86_64;
COPY_PHASE_STRIP = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
@@ -537,7 +543,7 @@
INSTALL_PATH = "@executable_path/../Frameworks";
LIBRARY_STYLE = DYNAMIC;
MACH_O_TYPE = mh_dylib;
- MACOSX_DEPLOYMENT_TARGET = 10.4;
+ MACOSX_DEPLOYMENT_TARGET = 10.5;
PREBINDING = NO;
PRODUCT_NAME = EyeTunes;
SKIP_INSTALL = YES;
@@ -573,7 +579,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
- GCC_PREPROCESSOR_DEFINITIONS = "";
+ GCC_PREPROCESSOR_DEFINITIONS = ET_DEBUG;
INSTALL_PATH = /usr/local/bin;
KEEP_PRIVATE_EXTERNS = YES;
OTHER_CFLAGS = "";
@@ -604,7 +610,7 @@
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "$(SYSTEM_LIBRARY_DIR)/Frameworks/AppKit.framework/Headers/AppKit.h";
- GCC_PREPROCESSOR_DEFINITIONS = "";
+ GCC_PREPROCESSOR_DEFINITIONS = ET_DEBUG;
INSTALL_PATH = /usr/local/bin;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = (
View
@@ -156,6 +156,12 @@ void rename_chinese_tracks(EyeTunes *e) {
}
}
+void test_create_playlist(EyeTunes *e) {
+ ETPlaylist *playlist = [e addPlaylistWithName:@"test3"];
+ NSLog(@"created playlist %@", [playlist name]);
+}
+
+
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
EyeTunes *e = [EyeTunes sharedInstance];
@@ -171,6 +177,7 @@ int main (int argc, const char * argv[]) {
test_track_persistent_id(e);
//rename_chinese_tracks(e);
+ //test_create_playlist(e);
[pool release];
return 0;

0 comments on commit 9ab5355

Please sign in to comment.