Changeset 414

Show
Ignore:
Timestamp:
02/25/08 11:16:56 PM (9 months ago)
Author:
nicholas
Message:

StreamVision?.py: Support for Last.fm playback via Amua.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/StreamVision/StreamVision.py

    r341 r414  
    7575def iTunesApp(): return app(id='com.apple.iTunes') 
    7676def XTensionApp(): return app(creator='SHEx') 
     77def AmuaApp(): return app('Amua.app') 
    7778 
    7879HAVE_XTENSION = False 
     
    8384    pass 
    8485 
     86HAVE_AMUA = False 
     87try: 
     88    AmuaApp() 
     89    HAVE_AMUA = True 
     90except: 
     91    pass 
     92 
    8593needsStereoPowerOn = HAVE_XTENSION 
     94 
     95def amuaPlaying(): 
     96    if not HAVE_AMUA: 
     97        return False 
     98    return AmuaApp().is_playing() 
    8699 
    87100class StreamVision(NSApplication): 
     
    90103    hotKeys = [] 
    91104 
    92     def displayTrackInfo(self): 
     105    def displayTrackInfo(self, playerInfo=None): 
    93106        global needsStereoPowerOn 
    94107 
     
    112125            needsStereoPowerOn = False 
    113126        if trackClass == k.URL_track: 
     127            if amuaPlaying(): 
     128                if playerInfo is None: # Amua displays it itself 
     129                    AmuaApp().display_song_information() 
     130                return 
    114131            growlNotify(cleanStreamTitle(iTunes.current_stream_title()), 
    115132                        cleanStreamTrackName(trackName)) 
     
    134151        iTunes = iTunesApp() 
    135152        if iTunes.player_state() == k.playing: 
     153            if amuaPlaying(): 
     154                AmuaApp().display_album_details() 
     155                return 
    136156            url = iTunes.current_stream_URL() 
    137157            if url != k.missing_value: 
     
    156176    def incrementRatingBy(self, increment): 
    157177        iTunes = iTunesApp() 
     178        if amuaPlaying(): 
     179            if rating < 0: 
     180                AmuaApp().ban_song() 
     181                growlNotify('Banned song.', '') 
     182            else: 
     183                AmuaApp().love_song() 
     184                growlNotify('Loved song.', '') 
     185            return 
    158186        rating = iTunes.current_track.rating() 
    159187        rating += increment 
     
    173201        if not useStereo: 
    174202            needsStereoPowerOn = False 
    175         iTunes.playpause() 
     203        if was_playing and amuaPlaying(): 
     204            AmuaApp().stop() 
     205        else: 
     206            iTunes.playpause() 
    176207        if not was_playing and iTunes.player_state() == k.stopped: 
    177208            # most likely, we're focused on the iPod, so playing does nothing 
     
    202233            self.playPause(useStereo=False) 
    203234 
     235    def nextTrack(self): 
     236        if amuaPlaying(): 
     237            AmuaApp().skip_song() 
     238            return 
     239        iTunesApp().next_track() 
     240 
    204241    def registerZoomWindowHotKey(self): 
    205242        self.zoomWindowHotKey = self.registerHotKey(self.zoomWindow, 42, cmdKey | controlKey) # cmd-ctrl-\ 
     
    237274        self.registerHotKey(self.playPause, 101) # F9 
    238275        self.registerHotKey(lambda: iTunesApp().previous_track(), 109) # F10 
    239         self.registerHotKey(lambda: iTunesApp().next_track(), 103) # F11 
     276        self.registerHotKey(self.nextTrack, 103) # F11 
    240277        self.registerHotKey(lambda: self.incrementRatingBy(-20), 109, shiftKey) # shift-F10 
    241278        self.registerHotKey(lambda: self.incrementRatingBy(20), 103, shiftKey) # shift-F11