Changeset 414


Ignore:
Timestamp:
02/25/08 23:16:56 (12 years ago)
Author:
Nicholas Riley
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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))
     
    133150        iTunes = iTunesApp()
    134151        if iTunes.player_state() == k.playing:
     152            if amuaPlaying():
     153                AmuaApp().display_album_details()
     154                return
    135155            url = iTunes.current_stream_URL()
    136156            if url != k.missing_value:
     
    155175    def incrementRatingBy(self, increment):
    156176        iTunes = iTunesApp()
     177        if amuaPlaying():
     178            if rating < 0:
     179                AmuaApp().ban_song()
     180                growlNotify('Banned song.', '')
     181            else:
     182                AmuaApp().love_song()
     183                growlNotify('Loved song.', '')
     184            return
    157185        rating = iTunes.current_track.rating()
    158186        rating += increment
     
    172200        if not useStereo:
    173201            needsStereoPowerOn = False
    174         iTunes.playpause()
     202        if was_playing and amuaPlaying():
     203            AmuaApp().stop()
     204        else:
     205            iTunes.playpause()
    175206        if not was_playing and iTunes.player_state() == k.stopped:
    176207            # most likely, we're focused on the iPod, so playing does nothing
     
    201232            self.playPause(useStereo=False)
    202233
     234    def nextTrack(self):
     235        if amuaPlaying():
     236            AmuaApp().skip_song()
     237            return
     238        iTunesApp().next_track()
     239
    203240    def registerZoomWindowHotKey(self):
    204241        self.zoomWindowHotKey = self.registerHotKey(self.zoomWindow, 42, cmdKey | controlKey) # cmd-ctrl-\
     
    236273        self.registerHotKey(self.playPause, 101) # F9
    237274        self.registerHotKey(lambda: iTunesApp().previous_track(), 109) # F10
    238         self.registerHotKey(lambda: iTunesApp().next_track(), 103) # F11
     275        self.registerHotKey(self.nextTrack, 103) # F11
    239276        self.registerHotKey(lambda: self.incrementRatingBy(-20), 109, shiftKey) # shift-F10
    240277        self.registerHotKey(lambda: self.incrementRatingBy(20), 103, shiftKey) # shift-F11
Note: See TracChangeset for help on using the changeset viewer.