forked from tombfix/patch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.iTunes.sendLyrics.js
41 lines (37 loc) · 1.04 KB
/
action.iTunes.sendLyrics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Tombloo.Service.actions.register( {
name : 'iTunes - Send Lyrics',
type : 'context',
icon : 'chrome://tombloo/skin/iTunes.ico',
check : function(ctx){
return !ctx.window.getSelection().isCollapsed;
},
execute : function(ctx){
var self = this;
var lyrics = convertToPlainText(ctx.window.getSelection()).replace(/[\u2028\u2029]/g,'');
runWSH(function(lyrics){
var iTunes = WScript.CreateObject('iTunes.Application');
var tracks = iTunes.selectedTracks;
if(!tracks)
throw 'Tracks not selected.';
var res = [];
forEach(tracks, function(track){
if(track.lyrics)
throw 'Already exists lyrics.';
track.lyrics = lyrics;
res.push({
artist : track.artist,
name : track.name,
});
});
return res;
}, lyrics).addCallback(function(tracks){
notify(self.name, (
tracks.length > 1?
'(+' + (tracks.length - 1) + ') ' :
''
) + tracks[0].artist + ' - ' + tracks[0].name, notify.ICON_INFO);
}).addErrback(function(e){
alert('ERROR: ' + e.message);
});
},
}, '----');