Changeset 489 for trunk/Update Podcasts


Ignore:
Timestamp:
02/14/09 11:05:01 (16 years ago)
Author:
Nicholas Riley
Message:

iPod touch/iPhone podcast updater, now complete.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Update Podcasts/update_podcasts.py

    r488 r489  
    33
    44from appscript import *
     5from aem import AEEnum
    56from itertools import izip
    67import htmlentitydefs
    78import re
     9import time
    810
    911# based on <http://sebsauvage.net/python/snyppets/>
     
    1618        if entity in htmlentitydefs.name2codepoint:
    1719            return unichr(htmlentitydefs.name2codepoint[entity])
    18         return u' '  # Unknown entity: We replace with a space.
     20        return u' ' # Unknown entity: We replace with a space.
    1921    replaced = 0
    2022    s, n = RE_ENTITY_CHR.subn(entity2char, s)
     
    4951    return s
    5052
    51 def podcasts_to_lyrics():
    52     iTunes = app('iTunes')
    53 
     53def podcasts_to_lyrics(iTunes):
    5454    podcasts = iTunes.tracks[its.podcast == True]
    5555
     
    7575        iTunes.tracks[its.id == id_].lyrics.set(longdesc)
    7676
     77def iTunes_main_pane():
     78    return app(u'System Events').application_processes[u'iTunes'].windows[u'iTunes'].splitter_groups[1].scroll_areas[1]
    7779
     80def wait_for_podcast_update(iTunes):
     81    # show 'Podcasts'
     82    iTunes.playlists[its.special_kind == AEEnum('kSpP')].reveal()
     83    podcast_status = iTunes_main_pane().outlines[1].rows.static_texts[1].value
     84    while u'queued for download' in podcast_status.get():
     85        time.sleep(0.5)
     86
     87def wait_for_iPod_update(iTunes):
     88    # show iPod
     89    iTunes.sources[its.kind == AEEnum('kPod')].sources[1].library_playlists[1].reveal()
     90    sync_enabled = iTunes_main_pane().buttons[u'Sync'].enabled
     91    while sync_enabled.get() == False:
     92        time.sleep(0.5)
    7893
    7994if __name__ == '__main__':
    80     # sync_ipod()
    81     # - poll whether 'Sync' button is enabled
    82     # update_podcasts()
    83     # - poll '[queued for download]' on last podcast, then any remaining
    84     podcasts_to_lyrics()
    85     # sync_ipod()
    86 
    87 # write podcast entry replacing http://njr.sabi.net/2007/03/04/an-applescript-to-update-podcasts-and-your-ipod/ - now we can use accessibility
     95    iTunes = app('iTunes')
     96    iTunes.updateAllPodcasts() # start downloading
     97    iTunes.update() # sync iPod
     98    wait_for_iPod_update(iTunes)
     99    iTunes.updateAllPodcasts()
     100    wait_for_podcast_update(iTunes)
     101    podcasts_to_lyrics(iTunes)
     102    iTunes.update()
Note: See TracChangeset for help on using the changeset viewer.