@@ -35,6 +35,8 @@ function getCurrentState(){
35
35
currentState [ 'playlist' ] = currentPlaylist . name ( ) ;
36
36
currentState [ 'volume' ] = itunes . soundVolume ( ) ;
37
37
currentState [ 'muted' ] = itunes . mute ( ) ;
38
+ currentState [ 'repeat' ] = itunes . songRepeat ( ) ;
39
+ currentState [ 'shuffle' ] = itunes . shuffleEnabled ( ) && itunes . shuffleMode ( ) ;
38
40
39
41
if ( currentTrack . year ( ) ) {
40
42
currentState [ 'album' ] += " (" + currentTrack . year ( ) + ")" ;
@@ -95,6 +97,39 @@ function setMuted(muted){
95
97
}
96
98
}
97
99
100
+ function setShuffle ( mode ) {
101
+ itunes = Application ( 'iTunes' ) ;
102
+
103
+ if ( ! mode ) {
104
+ mode = "songs"
105
+ }
106
+
107
+ if ( mode == "false" || mode == "off" ) {
108
+ itunes . shuffleEnabled = false ;
109
+ return false ;
110
+ } else {
111
+ itunes . shuffleEnabled = true ;
112
+ itunes . shuffleMode = mode ;
113
+ return true ;
114
+ }
115
+ }
116
+
117
+ function setRepeat ( mode ) {
118
+ itunes = Application ( 'iTunes' ) ;
119
+
120
+ if ( ! mode ) {
121
+ mode = "all"
122
+ }
123
+
124
+ if ( mode == "false" || mode == "off" ) {
125
+ itunes . songRepeat = false ;
126
+ return false ;
127
+ } else {
128
+ itunes . songRepeat = mode ;
129
+ return true ;
130
+ }
131
+ }
132
+
98
133
function getPlaylistsFromItunes ( ) {
99
134
itunes = Application ( 'iTunes' ) ;
100
135
playlists = itunes . playlists ( ) ;
@@ -195,6 +230,27 @@ app.put('/mute', function(req, res){
195
230
} )
196
231
} )
197
232
233
+ app . put ( '/shuffle' , function ( req , res ) {
234
+ osa ( setShuffle , req . body . mode , function ( error , data , log ) {
235
+ if ( error ) {
236
+ console . log ( error )
237
+ res . sendStatus ( 500 )
238
+ } else {
239
+ sendResponse ( error , res )
240
+ }
241
+ } )
242
+ } )
243
+
244
+ app . put ( '/repeat' , function ( req , res ) {
245
+ osa ( setRepeat , req . body . mode , function ( error , data , log ) {
246
+ if ( error ) {
247
+ console . log ( error )
248
+ res . sendStatus ( 500 )
249
+ } else {
250
+ sendResponse ( error , res )
251
+ }
252
+ } )
253
+ } )
198
254
199
255
app . get ( '/now_playing' , function ( req , res ) {
200
256
error = null
0 commit comments