forked from tombfix/patch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.downloadSoundcloud.js
More file actions
83 lines (72 loc) · 2.5 KB
/
action.downloadSoundcloud.js
File metadata and controls
83 lines (72 loc) · 2.5 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
(function(){
var BASE_ACTION = {
name : 'Download Soundcloud',
type : 'context',
icon : 'http://soundcloud.com/favicon.ico',
}
function downloadAll(urls){
urls = urls.slice(0).filter(function(url){
return !/\/\/soundcloud.com\/users\//.test(url);
});
function getTrack(){
if(!urls.length)
return;
return Soundcloud.download(urls.shift()).addCallbacks(getTrack, alertError);
}
function alertError(err){
alert(err.message.status + ': ' + err.message.statusText + ': \n' + err.message.channel.URI.spec);
return succeed().addCallbacks(getTrack, alertError);
}
return succeed().addCallbacks(getTrack, alertError).addCallback(function(){
notify(BASE_ACTION.name, 'End', notify.ICON_DOWNLOAD);
});
}
Tombloo.Service.actions.register(update({}, BASE_ACTION, {
check : function(ctx){
return Soundcloud.normalizeTrackUrl(ctx.href) &&
ctx.document.querySelectorAll('.info-body').length;
},
execute : function(ctx){
return downloadAll([ctx.href]);
},
}), '----');
Tombloo.Service.actions.register(update({}, BASE_ACTION, {
name : 'Download Soundcloud(All)',
check : function(ctx){
return ctx.href.match('//soundcloud.com') && !!ctx.document.querySelector('.tracks-list');
},
execute : function(ctx){
return downloadAll($x('//div[contains(@class, "info-header")]//h3/a', ctx.document, true).map(itemgetter('href')));
},
}), '----');
Tombloo.Service.actions.register(update({}, BASE_ACTION, {
name : 'Download Soundcloud(Set/All)',
check : function(ctx){
return ctx.href.match('//soundcloud.com/.*/sets/');
},
execute : function(ctx){
return downloadAll($x('//span[@class="info"]/a', ctx.document, true).map(itemgetter('href')));
},
}), '----');
var downloadFromLdr = {
name : 'Download Soundcloud(LDR)',
check : function(ctx){
return Soundcloud.normalizeTrackUrl(this.getLink(ctx));
},
execute : function(ctx){
return downloadAll([this.getLink(ctx)]);
},
getLink : function(ctx){
var item = Tombloo.Service.extractors.LDR.getItem(ctx, true);
return item && /soundcloud\.com/.test(item.href) && item.href;
}
};
Tombloo.Service.actions.register(update({}, BASE_ACTION, downloadFromLdr), '----');
Tombloo.Service.actions.register(update({}, BASE_ACTION, downloadFromLdr, {
name : 'Download Soundcloud(LDR/All)',
execute : function(ctx){
// Array.prototype.mapが独自に定義されている
return downloadAll(map(itemgetter('link'), ctx.window.get_active_feed().items));
},
}), '----');
})();