- Timestamp:
- 10/24/08 18:23:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/StreamVision/StreamVision.py
r459 r486 4 4 from appscript import app, k, its, CommandError 5 5 from AppKit import NSApplication, NSApplicationDefined, NSBeep, NSSystemDefined, NSURL, NSWorkspace 6 from Foundation import NSDistributedNotificationCenter 6 from Foundation import NSDistributedNotificationCenter, NSSearchPathForDirectoriesInDomains, NSCachesDirectory, NSUserDomainMask 7 7 from PyObjCTools import AppHelper 8 8 from Carbon.CarbonEvt import RegisterEventHotKey, GetApplicationEventTarget 9 9 from Carbon.Events import cmdKey, shiftKey, controlKey 10 import httplib2 11 import os 10 12 import struct 11 13 import scrape … … 98 100 return AmuaApp().is_playing() 99 101 102 class OneFileCache(object): 103 __slots__ = ('key', 'cache') 104 105 def __init__(self, cache): 106 if not os.path.exists(cache): 107 os.makedirs(cache) 108 self.cache = os.path.join(cache, 'file') 109 self.key = None 110 111 def get(self, key): 112 if key == self.key: 113 return file(self.cache, 'r').read() 114 115 def set(self, key, value): 116 self.key = key 117 file(self.cache, 'w').write(value) 118 119 def delete(self, key): 120 if key == self.key: 121 self.key = None 122 os.remove(cache) 123 100 124 class StreamVision(NSApplication): 101 125 … … 129 153 AmuaApp().display_song_information() 130 154 return 155 url = iTunes.current_stream_URL() 156 kw = {} 157 if url != k.missing_value and url.endswith('.jpg'): 158 response, content = self.http.request(url) 159 if response['content-type'].startswith('image/'): 160 file(self.imagePath, 'w').write(content) 161 kw['image_from_location'] = self.imagePath 131 162 growlNotify(cleanStreamTitle(iTunes.current_stream_title()), 132 cleanStreamTrackName(trackName) )163 cleanStreamTrackName(trackName), **kw) 133 164 return 134 165 if trackClass == k.property: … … 269 300 def finishLaunching(self): 270 301 super(StreamVision, self).finishLaunching() 302 303 caches = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, 304 NSUserDomainMask, True)[0] 305 cache = os.path.join(caches, 'StreamVision') 306 self.http = httplib2.Http(OneFileCache(cache), 5) 307 self.imagePath = os.path.join(cache, 'image') 308 271 309 self.registerHotKey(self.displayTrackInfo, 100) # F8 272 310 self.registerHotKey(self.goToSite, 100, cmdKey) # cmd-F8
Note:
See TracChangeset
for help on using the changeset viewer.