-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitunes_info.py
executable file
·54 lines (46 loc) · 1.3 KB
/
itunes_info.py
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
#!/usr/bin/python
from ScriptingBridge import SBApplication, NSPredicate
iTunes = SBApplication.applicationWithBundleIdentifier_('com.apple.iTunes')
metadata = {
'date_released': '2007-04-16',
'artist': 'Artist Name',
'album': 'Name of Album',
'genre': 'Rock',
}
query_string = "artist == '{artist}' AND album == '{album}'".format(**metadata)
library = iTunes.sources().objectWithName_("Library")
all_tracks = library.libraryPlaylists()[0]
tracks = all_tracks.tracks().filteredArrayUsingPredicate_(NSPredicate.predicateWithFormat_(query_string))
start = 0.0
track_md = []
# extend track duration by N seconds
fudge = (
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
)
for i, track in enumerate(tracks):
tno = track.trackNumber()
title = track.name()
length = track.duration() + fudge[tno - 1]
# print u'ffmpeg -i "input.mkv" -map 0:1 -c:a copy -ss {:.03f} -t {:.03f} "{:02d} - {}.dts"'.format(start, length, tno, title)
track_md.append({
'track': tno,
'title': track.name(),
'start': float('{:.03f}'.format(start)),
'duration': float('{:.03f}'.format(length)),
})
start += length
metadata['tracks'] = track_md
from json import dump
with open('metadata.json', 'w') as rum:
dump(metadata, rum, indent=2)