def current_track(self, tid=None): log.debug('songid: %s' % tid) if not tid: return self.track tid = int(tid) if tid == self.trackindex: return if tid in self.tracks: self.trackindex = tid if len(self.details) != len(self.tracks): log.debug('details: %s tracks: %s' % (len(self.details), len(self.tracks))) reactor.callLater( # @UndefinedVariable 1, self.current_track, tid) return t, d = self.details[self.tracks.index(tid)] url, md = (c.text for c in t.getchildren()[1:3]) self.track = (url, md,) self.mpd.trackcount += 1 self.mpd.detailscount = 0 self.mpd.metatextcount = 0 self.mpd.songid = str(tid) self.mpd.upnp_eventAV(tid, 'currenttrack') self.mpd.oh_eventPLAYLIST(tid, 'id') self.mpd.oh_eventTIME(self.mpd.trackcount, 'trackcount') self.mpd.oh_eventINFO(self.mpd.trackcount, 'trackcount') if self.mpd.timer: self.mpd.timer.set() if 'duration' in d: self.mpd._track_duration = d['duration'] sec = upnptime_to_mpdtime(d['duration']) self.mpd.ohduration = sec log.debug('duration=%s' % sec) self.mpd.upnp_eventAV(d['duration'], 'currenttrackduration') self.mpd.oh_eventINFO(sec, 'duration') self.mpd.oh_eventTIME(sec, 'duration') if 'url' in d: self.mpd._track_URI = d['url'] self.mpd.upnp_eventAV(d['url'], 'avtransporturi') self.mpd.oh_eventINFO(d['url'], 'uri') self.mpd.upnp_eventAV(d['url'], 'currenttrackuri') if 'codec' in d: self.mpd.oh_eventINFO( d['codec'].upper(), 'codecname') if d['codec'].lower() in ['flac', 'm4a']: self.mpd.lossless = True self.mpd.oh_eventINFO(1, 'lossless') else: self.mpd.lossless = False self.mpd.oh_eventINFO(0, 'lossless') self.mpd.codecname = d['codec'].upper() self.mpd.metadata_str = t.getchildren()[2].text self.mpd.oh_eventINFO(self.mpd.metadata_str, 'metadata') self.mpd.upnp_eventAV( self.mpd.metadata_str, 'avtransporturimetadata') if self.mpd.tracksmax == 0: self.mpd.tracksmax = 10000 self.mpd.oh_eventPLAYLIST(1000, 'tracksmax') else: reactor.callLater(1, self.current_track, tid) # @UndefinedVariable
def getmd(md): if isinstance(md, list): nd = {} for d in md: nd.update(d) md = nd if md != self._metadata: self._metadata = md # log.error(unicode(md)) self.metadata = mpd_decode(self._metadata) if self._track_duration != self.metadata['duration']: self._track_duration = self.metadata['duration'] self.upnp_eventAV(self._track_duration, 'CurrentTrackDuration') sec = upnptime_to_mpdtime(self._track_duration) self.ohduration = sec self.oh_eventINFO(sec, 'duration') self.oh_eventTIME(sec, 'duration') if self.songid != self.metadata['id']: self.trackcount += 1 self.detailscount = 0 self.metatextcount = 0 self.songid = self.metadata['id'] self.upnp_eventAV(int(self.songid), 'CurrentTrack') self.oh_eventPLAYLIST(int(self.songid), 'id') self.oh_eventTIME(self.trackcount, 'trackcount') self.oh_eventINFO(self.trackcount, 'trackcount') if self.timer: self.timer.set() if 'url' in self.metadata.keys(): self._track_URI = self.metadata['url'] self.upnp_eventAV(self._track_URI, 'AVTransportURI') self.oh_eventINFO(self._track_URI, 'uri') self.upnp_eventAV(self._track_URI, 'CurrentTrackURI') try: self.oh_eventINFO( self.metadata['codec'].upper(), 'codecname') if self.metadata['codec'].lower() in ['flac', 'm4a']: self.lossless = True self.oh_eventINFO(1, 'lossless') else: self.lossless = False self.oh_eventINFO(0, 'lossless') self.codecname = self.metadata['codec'].upper() except KeyError: pass self.metadata_str = didl_encode(self.metadata) self.oh_eventINFO(self.metadata_str, 'metadata') self.upnp_eventAV(self.metadata_str, 'AVTransportURIMetaData') if self.tracksmax == 0: self.tracksmax = 10000 self.oh_eventPLAYLIST(self.tracksmax, 'tracksmax')
def getmd(md): if isinstance(md, list): nd = {} for d in md: nd.update(d) md = nd if md != self._metadata: self._metadata = md # log.error(unicode(md)) self.metadata = mpd_decode(self._metadata) if self._track_duration != self.metadata['duration']: self._track_duration = self.metadata['duration'] self.upnp_eventAV(self._track_duration, 'CurrentTrackDuration') sec = upnptime_to_mpdtime(self._track_duration) self.ohduration = sec self.oh_eventINFO(sec, 'duration') self.oh_eventTIME(sec, 'duration') if self.songid != self.metadata['id']: self.trackcount += 1 self.detailscount = 0 self.metatextcount = 0 self.songid = self.metadata['id'] self.upnp_eventAV(int(self.songid), 'CurrentTrack') self.oh_eventPLAYLIST(int(self.songid), 'id') self.oh_eventTIME(self.trackcount, 'trackcount') self.oh_eventINFO(self.trackcount, 'trackcount') if self.timer: self.timer.set() if 'url' in self.metadata.keys(): self._track_URI = self.metadata['url'] self.upnp_eventAV(self._track_URI, 'AVTransportURI') self.oh_eventINFO(self._track_URI, 'uri') self.upnp_eventAV(self._track_URI, 'CurrentTrackURI') try: self.oh_eventINFO(self.metadata['codec'].upper(), 'codecname') if self.metadata['codec'].lower() in ['flac', 'm4a']: self.lossless = True self.oh_eventINFO(1, 'lossless') else: self.lossless = False self.oh_eventINFO(0, 'lossless') self.codecname = self.metadata['codec'].upper() except KeyError: pass self.metadata_str = didl_encode(self.metadata) self.oh_eventINFO(self.metadata_str, 'metadata') self.upnp_eventAV(self.metadata_str, 'AVTransportURIMetaData') if self.tracksmax == 0: self.tracksmax = 10000 self.oh_eventPLAYLIST(self.tracksmax, 'tracksmax')
def set_position(self, newpos, fmt='UPNP'): def transition(obj): current_state = self._state self.set_state('pending') reactor.callLater(0.5, # @UndefinedVariable self.set_state, current_state) if fmt == 'UPNP': pos = upnptime_to_mpdtime(newpos) else: pos = newpos d = self.mpd.call('seekcur', pos) d.addCallback(transition) return d
def current_track(self, tid=None): log.debug('songid: %s' % tid) if not tid: return self.track tid = int(tid) if tid == self.trackindex: return if tid in self.tracks: self.trackindex = tid if len(self.details) != len(self.tracks): log.debug('details: %s tracks: %s' % (len(self.details), len(self.tracks))) reactor.callLater( # @UndefinedVariable 1, self.current_track, tid) return t, d = self.details[self.tracks.index(tid)] url, md = (c.text for c in t.getchildren()[1:3]) self.track = ( url, md, ) self.mpd.trackcount += 1 self.mpd.detailscount = 0 self.mpd.metatextcount = 0 self.mpd.songid = str(tid) self.mpd.upnp_eventAV(tid, 'currenttrack') self.mpd.oh_eventPLAYLIST(tid, 'id') self.mpd.oh_eventTIME(self.mpd.trackcount, 'trackcount') self.mpd.oh_eventINFO(self.mpd.trackcount, 'trackcount') if self.mpd.timer: self.mpd.timer.set() if 'duration' in d: self.mpd._track_duration = d['duration'] sec = upnptime_to_mpdtime(d['duration']) self.mpd.ohduration = sec log.debug('duration=%s' % sec) self.mpd.upnp_eventAV(d['duration'], 'currenttrackduration') self.mpd.oh_eventINFO(sec, 'duration') self.mpd.oh_eventTIME(sec, 'duration') if 'url' in d: self.mpd._track_URI = d['url'] self.mpd.upnp_eventAV(d['url'], 'avtransporturi') self.mpd.oh_eventINFO(d['url'], 'uri') self.mpd.upnp_eventAV(d['url'], 'currenttrackuri') if 'codec' in d: self.mpd.oh_eventINFO(d['codec'].upper(), 'codecname') if d['codec'].lower() in ['flac', 'm4a']: self.mpd.lossless = True self.mpd.oh_eventINFO(1, 'lossless') else: self.mpd.lossless = False self.mpd.oh_eventINFO(0, 'lossless') self.mpd.codecname = d['codec'].upper() self.mpd.metadata_str = t.getchildren()[2].text self.mpd.oh_eventINFO(self.mpd.metadata_str, 'metadata') self.mpd.upnp_eventAV(self.mpd.metadata_str, 'avtransporturimetadata') if self.mpd.tracksmax == 0: self.mpd.tracksmax = 10000 self.mpd.oh_eventPLAYLIST(1000, 'tracksmax') else: reactor.callLater(1, self.current_track, tid) # @UndefinedVariable