Skip to content

Commit

Permalink
Added Spotify ScriptingBridge header, also shows iTunes rating now
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed May 21, 2012
1 parent d0da49f commit 65ab622
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
74 changes: 74 additions & 0 deletions Spotify.h
@@ -0,0 +1,74 @@
/*
* Spotify.h
*/

#import <AppKit/AppKit.h>
#import <ScriptingBridge/ScriptingBridge.h>


@class SpotifyApplication, SpotifyTrack, SpotifyApplication;

enum SpotifyEPlS {
SpotifyEPlSStopped = 'kPSS',
SpotifyEPlSPlaying = 'kPSP',
SpotifyEPlSPaused = 'kPSp'
};
typedef enum SpotifyEPlS SpotifyEPlS;



/*
* Spotify Suite
*/

// The Spotify application.
@interface SpotifyApplication : SBApplication

@property (copy, readonly) SpotifyTrack *currentTrack; // The current playing track.
@property NSInteger soundVolume; // The sound output volume (0 = minimum, 100 = maximum)
@property (readonly) SpotifyEPlS playerState; // Is Spotify stopped, paused, or playing?
@property double playerPosition; // The player’s position within the currently playing track in seconds.

- (void) nextTrack; // Skip to the next track.
- (void) previousTrack; // Skip to the previous track.
- (void) playpause; // Toggle play/pause.
- (void) pause; // Pause playback.
- (void) play; // Resume playback.

@end

// A Spotify track.
@interface SpotifyTrack : SBObject

@property (copy, readonly) NSString *artist; // The artist of the track.
@property (copy, readonly) NSString *album; // The album of the track.
@property (readonly) NSInteger discNumber; // The disc number of the track.
@property (readonly) NSInteger duration; // The length of the track in seconds.
@property (readonly) NSInteger playedCount; // The number of times this track has been played.
@property (readonly) NSInteger trackNumber; // The index of the track in its album.
@property (readonly) BOOL starred; // Is the track starred?
@property (readonly) NSInteger popularity; // How popular is this track? 0-100
- (NSString *) id; // The ID of the item.
@property (copy, readonly) NSString *name; // The name of the track.
@property (copy, readonly) NSImage *artwork; // The track's album cover.
@property (copy, readonly) NSString *albumArtist; // That album artist of the track.
@property (copy) NSString *spotifyUrl; // The URL of the track.


@end



/*
* Standard Suite
*/

// The application's top level scripting object.
@interface SpotifyApplication (StandardSuite)

@property (copy, readonly) NSString *name; // The name of the application.
@property (readonly) BOOL frontmost; // Is this the frontmost (active) application?
@property (copy, readonly) NSString *version; // The version of the application.

@end

2 changes: 2 additions & 0 deletions campfire-tunes.xcodeproj/project.pbxproj
Expand Up @@ -50,6 +50,7 @@
1B6F6BC81566AEEB00B5AF2A /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
1B6F6BCA1566AEFA00B5AF2A /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
1B6F6C641566B38F00B5AF2A /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
1B77EC94156A9273009991E1 /* Spotify.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Spotify.h; sourceTree = "<group>"; };
1B8ECE421566F4B600FEA7C8 /* iTunes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTunes.h; sourceTree = "<group>"; };
1B8ECE431566F4B600FEA7C8 /* campfireTunesAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = campfireTunesAppDelegate.h; sourceTree = "<group>"; };
1B8ECE441566F4B600FEA7C8 /* campfireTunesAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = campfireTunesAppDelegate.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -126,6 +127,7 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
1B77EC94156A9273009991E1 /* Spotify.h */,
1B8ECE421566F4B600FEA7C8 /* iTunes.h */,
1B8ECE431566F4B600FEA7C8 /* campfireTunesAppDelegate.h */,
1B8ECE441566F4B600FEA7C8 /* campfireTunesAppDelegate.m */,
Expand Down
1 change: 1 addition & 0 deletions campfireTunesAppDelegate.h
Expand Up @@ -72,6 +72,7 @@
- (void) timerUpdate:(NSTimer*) timer;
- (void) update;
- (void) updateStatus: (NSString *)msg;
- (NSInteger) getITunesRatingInStars:(iTunesTrack *)track;
- (void) updateTrackWithName: (NSString *)name withArtist:(NSString *)artist withAlbum:(NSString *)album;
- (void) clearTrackInfo;
- (void) prefPaneFieldDidChange:(NSNotification *)aNotification;
Expand Down
15 changes: 14 additions & 1 deletion campfireTunesAppDelegate.m
Expand Up @@ -262,6 +262,15 @@ - (void)timerUpdate:(NSTimer *)timerObj {
[self update];
}

- (NSInteger)getITunesRatingInStars:(iTunesTrack *)track {
// returns 0 - 5
if ([track ratingKind] == iTunesERtKUser) {
NSInteger rating = [track rating];
return rating / 20;
}
return 0;
}

- (void)update {
NSLog(@"Updating...");
if ([player isRunning]) {
Expand Down Expand Up @@ -295,8 +304,12 @@ - (void)update {
NSString *roomID = [self.prefs stringForKey:@"campfireRoomID"];
[self updateStatus:@"Sending track..."];
NSLog(@"Notifying campfire of new track");
NSString *campfireText = [NSString stringWithFormat:@":notes: %@ :guitar: %@ :dvd: %@",
NSMutableString *campfireText = [NSMutableString stringWithFormat:@":notes: %@ :guitar: %@ :dvd: %@",
self.currentName, self.currentArtist, self.currentAlbum];
NSInteger rating = [self getITunesRatingInStars:newTrack];
for (int i=0; i < rating; i++) {
[campfireText appendString:@" :star:"];
}
[self.campfire sendText:campfireText toRoom:roomID
completionHandler:^(HCMessage *message, NSError *error){
NSLog(@"Sent [%@] to campfire", message);
Expand Down

0 comments on commit 65ab622

Please sign in to comment.