def __init__(self, addr, port): self.addr = addr self.port = port self.notilyric = NotiLyric('fmlyric') self.interval = 1 self.artist = self.title = ''
class FMLyric(object): def __init__(self, addr, port): self.addr = addr self.port = port self.notilyric = NotiLyric('fmlyric') self.interval = 1 self.artist = self.title = '' def run(self): self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.conn.connect((socket.gethostbyname(self.addr), self.port)) except: print 'Connect to FMD failed. Is FMD running?' return res = self.conn.recv(1024) # receive welcome info while True: try: time.sleep(self.interval) except: print 'Quit.' self.conn.send('bye') self.conn.close() self.notilyric.close() break try: self.conn.send('info') obj = json.loads(self.conn.recv(4096)) except: print 'Server quit.' self.conn.close() self.notilyric.close() break status = obj['status'] if status != 'playing': self.notilyric.close() continue artist = obj['song']['artist'].encode('utf-8') title = obj['song']['title'].encode('utf-8') progress = obj['progress'] if self.artist != artist or self.title != title: self.artist = artist self.title = title self.notilyric.setinfo(artist, title) self.notilyric.display(progress)
class FMLyric(object): def __init__(self, addr, port): self.addr = addr self.port = port self.notilyric = NotiLyric('fmlyric') self.interval = 1 self.artist = self.title = '' def run(self): self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: self.conn.connect((socket.gethostbyname(self.addr), self.port)) except: print 'Connect to FMD failed. Is FMD running?' return while True: try: time.sleep(self.interval) except: print 'Quit.' self.conn.send('bye') self.conn.close() self.notilyric.close() break try: self.conn.send('info') obj = json.loads(self.conn.recv(4096)) except: print 'Server quit.' self.conn.close() self.notilyric.close() break status = obj['status'] if status != 'play': self.notilyric.close() continue artist = obj['artist'].encode('utf-8') title = obj['title'].encode('utf-8') progress = obj['pos'] if self.artist != artist or self.title != title: self.artist = artist self.title = title self.notilyric.setinfo(artist, title) self.notilyric.display(progress)
class QLyric(EventPlugin): PLUGIN_ID = "QLyric" PLUGIN_NAME = "Quod Libet Lyric" PLUGIN_DESC = "A lyric downloader and displayer for Quod Libet" PLUGIN_VERSION = "0.1" def __init__(self): self.live = False self.notilyric = NotiLyric('QLyric') self.interval = 1 def display(self): while self.live: time.sleep(self.interval) if player.paused: self.notilyric.close() continue progress = int(player.get_position() // 1000) self.notilyric.display(progress) def enabled(self): self.live = True thread.start_new_thread(self.display, ()) def disabled(self): self.live = False self.notilyric.close() def plugin_on_song_started(self, song): self.notilyric.setinfo(song.get('artist'), song.get('title'))
class FMLyric(object): def __init__(self, addr, port): self.addr = addr self.port = port self.notilyric = NotiLyric('fmlyric') self.interval = 1 self.artist = self.title = '' def run(self): self.client = mpd.MPDClient() try: self.client.connect(self.addr, self.port) except: print 'Connect to MPD failed. Is MPD running?' return while True: try: time.sleep(self.interval) except: print 'Quit.' self.client.disconnect() self.notilyric.close() break status = self.client.status() if status['state'] != 'play': self.notilyric.close() continue song = self.client.currentsong() artist = song['artist'] title = song['title'] progress = int(status['time'].split(':')[0]) if self.artist != artist or self.title != title: self.artist = artist self.title = title self.notilyric.setinfo(artist, title) self.notilyric.display(progress)
def __init__(self): self.live = False self.notilyric = NotiLyric('QLyric') self.interval = 1