source: trunk/Update Podcasts/update_podcasts.py@ 639

Last change on this file since 639 was 639, checked in by Nicholas Riley, 13 years ago

Fix verbiage since I have more than one iOS device now.

File size: 1.9 KB
Line 
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4from appscript import *
5from aem import AEEnum
6import sys
7import time
8
9def iTunes_main_pane():
10 return app(u'System Events').application_processes[u'iTunes'].windows[u'iTunes'].scroll_areas[1]
11
12def wait_for_podcast_update(iTunes):
13 # show 'Podcasts'
14 iTunes.playlists[its.special_kind == AEEnum('kSpP')].reveal()
15 podcast_status = iTunes_main_pane().outlines[1].rows.static_texts[1].value
16 # XXX this can fail if iTunes is hidden; fix it
17 while any(status in (u'downloading', u'queued for download')
18 for status in podcast_status.get()):
19 time.sleep(0.5)
20
21def sync_devices(iTunes):
22 try:
23 iTunes.update()
24 except CommandError:
25 print >> sys.stderr, 'No iOS devices detected. Waiting for an iOS device...'
26 while True:
27 time.sleep(0.5)
28 try:
29 iTunes.update()
30 return
31 except CommandError:
32 pass
33
34 # show first iOS device
35 iTunes.sources[its.kind == AEEnum('kPod')].sources[1].library_playlists[1].reveal()
36
37 # wait for update to complete
38 def sync_enabled():
39 try:
40 iTunes_main_pane().buttons[u'Apply'].click()
41 except CommandError:
42 pass
43 try:
44 return iTunes_main_pane().buttons[u'Sync'].enabled.get()
45 except CommandError:
46 pass
47
48 while not sync_enabled():
49 time.sleep(0.5)
50
51if __name__ == '__main__':
52 iTunes = app('iTunes')
53 print >> sys.stderr, 'Starting podcast update...'
54 iTunes.updateAllPodcasts()
55 print >> sys.stderr, 'Synchronizing iOS devices...'
56 sync_devices(iTunes)
57 print >> sys.stderr, 'Updating podcasts...'
58 iTunes.updateAllPodcasts()
59 wait_for_podcast_update(iTunes)
60 print >> sys.stderr, 'Synchronizing iOS devices...'
61 sync_devices(iTunes)
62 app(id='net.sabi.UpdatePodcasts').quit()
Note: See TracBrowser for help on using the repository browser.