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

Last change on this file since 628 was 628, checked in by Nicholas Riley, 14 years ago

Wait for missing iPod; wait 0.5 seconds before checking "Sync" button.

File size: 1.7 KB
RevLine 
[488]1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4from appscript import *
[489]5from aem import AEEnum
[491]6import sys
[489]7import time
[488]8
[489]9def iTunes_main_pane():
[625]10 return app(u'System Events').application_processes[u'iTunes'].windows[u'iTunes'].splitter_groups[1].scroll_areas[1]
[488]11
[489]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
[491]16 while any(status in (u'downloading', u'queued for download')
17 for status in podcast_status.get()):
[489]18 time.sleep(0.5)
[488]19
[628]20def sync_iPod(iTunes):
21 try:
22 iTunes.update()
23 except CommandError:
24 print >> sys.stderr, 'No iPod detected. Waiting for iPod...'
25 while True:
26 time.sleep(0.5)
27 try:
28 iTunes.update()
29 except CommandError:
30 pass
31
[489]32 # show iPod
33 iTunes.sources[its.kind == AEEnum('kPod')].sources[1].library_playlists[1].reveal()
[628]34
35 # wait for update to complete
[489]36 sync_enabled = iTunes_main_pane().buttons[u'Sync'].enabled
[546]37 while True:
[628]38 time.sleep(0.5)
[546]39 try:
40 if sync_enabled.get() == True:
41 return
42 except CommandError:
43 pass
[489]44
[488]45if __name__ == '__main__':
[489]46 iTunes = app('iTunes')
[609]47 print >> sys.stderr, 'Starting podcast update...'
48 iTunes.updateAllPodcasts()
[491]49 print >> sys.stderr, 'Synchronizing iPod...'
[628]50 sync_iPod(iTunes)
[491]51 print >> sys.stderr, 'Updating podcasts...'
[489]52 iTunes.updateAllPodcasts()
53 wait_for_podcast_update(iTunes)
[546]54 print >> sys.stderr, 'Synchronizing iPod...'
[628]55 sync_iPod(iTunes)
[574]56 app(id='net.sabi.UpdatePodcasts').quit()
Note: See TracBrowser for help on using the repository browser.