-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_playlists.js
executable file
·79 lines (68 loc) · 1.56 KB
/
read_playlists.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
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
#!/usr/bin/osascript -l JavaScript
const FLAGS = {
library: 'l',
folder: 'f',
subscription: 'b',
user: 'u',
smart: 's',
genius: 'g',
shared: 'h',
radio: 'r',
cd: 'c'
};
var app = Application('Music');
app.includeStandardAdditions = true;
var playlists = {};
app.userPlaylists().forEach(function(playlist) {
playlists[playlist.persistentID()] = {
name: playlist.name(),
user: true,
smart: playlist.smart(),
genius: playlist.genius(),
shared: playlist.shared()
};
});
app.libraryPlaylists().forEach(function(playlist) {
playlists[playlist.persistentID()] = {
name: playlist.name(),
library: true
};
});
app.radioTunerPlaylists().forEach(function(playlist) {
playlists[playlist.persistentID()] = {
name: playlist.name(),
radio: true
};
});
app.subscriptionPlaylists().forEach(function(playlist) {
playlists[playlist.persistentID()] = {
name: playlist.name(),
subscription: true
};
});
app.audioCDPlaylists().forEach(function(playlist) {
playlists[playlist.persistentID()] = {
name: playlist.name(),
cd: true
};
});
app.playlists.whose({_match: [ObjectSpecifier().class, 'folderPlaylist']})().forEach(function(playlist) {
playlists[playlist.persistentID()] = {
name: playlist.name(),
folder: true
};
});
playlists = Object.keys(playlists).filter(function(id) {
return !playlists[id].cd;
}).map(function(id) {
var flags = '';
for(var f in FLAGS) {
if(playlists[id][f]) {
flags += FLAGS[f].toUpperCase();
} else {
flags += FLAGS[f];
}
}
return `${id}:${flags}:${playlists[id].name}`;
})
console.log(playlists.join('\n'));