-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitunes.py
More file actions
executable file
·71 lines (49 loc) · 2.08 KB
/
itunes.py
File metadata and controls
executable file
·71 lines (49 loc) · 2.08 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
# Author - Dean Jones - http://deanproxy.com
#
# ITunes class to sync from itunes to destination.
import os
import sys
import urllib2
import urlparse
# from Foundation import *
from ScriptingBridge import SBApplication
class iTunesTrack(object):
def __init__(self, track):
""" represents the essential information for a track """
self.name = track.name()
self.albumArtist = track.albumArtist()
self.album = track.album()
self.artist = track.artist()
self.kind = track.kind()
self.size = track.size()
self.path = self._get_track_location(track)
def is_protected(self):
kind_blacklist = ['Protected AAC audio file']
return self.kind in kind_blacklist
def _get_track_location(self, track):
""" Returns the absolute path to the iTunes track """
location = urllib2.unquote(str(track.location()))
return urlparse.urlparse(location)[2]
class iTunesPlaylist(object):
def __init__(self, playlist):
""" represents the essential information for a playlist """
self.name = playlist.name()
self.kind = playlist.specialKind()
self.tracks = [iTunesTrack(i) for i in playlist.fileTracks()]
def tracks_in_playlist(self, playlist):
""" Returns an array of iTunesTrack """
return self.tracks
def is_music_playlist(self):
real_playlist_kind = 1800302446
return self.kind == real_playlist_kind
class iTunes(object):
def __init__(self):
""" opens the iTunes library """
self.itunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
def playlists(self):
""" Returns all of the playlists available as an array of iTunesPlaylist """
return [iTunesPlaylist(p) for p in self.itunes.sources()[0].userPlaylists()]
def tracks(self):
""" returns all tracks from the primary playlist (Music playlist)
which should be every track available as an array of iTunesTrack """
return [iTunesTrack(t) for t in self.itunes.sources()[0].userPlaylists()[0].fileTracks()]