def generate_tracklist(tracks): if not isinstance(tracks, list): tracks = [tracks] # if len(self.badlist) > 0: # for tr in self.badlist: # tracks.append(self.numid[tr]['metadata']) tl = et.Element("TrackList") for track in tracks: log.err("track: %s" % track) track = mpris_decode(track) en = et.Element("Entry") i = et.Element("Id") try: i.text = str(self.numid[track["mpris:trackid"]]) except: i.text = str(track["songid"]) en.append(i) uri = et.Element("Uri") uri.text = track["url"].decode("utf-8") en.append(uri) md = et.Element("Metadata") md.text = didl_encode(track) en.append(md) tl.append(en) return et.tostring(tl)
def generate_tracklist(tracks, tracklist=None): # log.err(tracks) if not isinstance(tracks, list): tracks = [tracks] tl = et.Element('TrackList') for idx, track in enumerate(tracks): # log.err(track) if isinstance(track, dict): track = mpd_decode(track) else: # log.err(track) nd = {} for d in track: # log.err(d) nd.update(d) track = mpd_decode(nd) # log.msg(nd) en = et.Element('Entry') i = et.Element('Id') if not 'id' in track: if tracklist: track.update({'id': str(tracklist[idx])}) else: log.err(track) i.text = track['id'].decode('utf-8') en.append(i) uri = et.Element('Uri') uri.text = track['url'].decode('utf-8') en.append(uri) md = et.Element('Metadata') md.text = didl_encode(track) en.append(md) tl.append(en) return et.tostring(tl)
def generate_tracklist(tracks): if not isinstance(tracks, list): tracks = [tracks] # if len(self.badlist) > 0: # for tr in self.badlist: # tracks.append(self.numid[tr]['metadata']) tl = et.Element('TrackList') for track in tracks: log.err('track: %s' % track) track = mpris_decode(track) en = et.Element('Entry') i = et.Element('Id') try: i.text = str(self.numid[track['mpris:trackid']]) except: i.text = str(track['songid']) en.append(i) uri = et.Element('Uri') uri.text = track['url'].decode('utf-8') en.append(uri) md = et.Element('Metadata') md.text = didl_encode(track) en.append(md) tl.append(en) return et.tostring(tl)
def update_metadata(self, metadata): if metadata != self._metadata: self._metadata.update(metadata) self.metadata.update(mpris_decode(metadata)) if 'mpris:length' in metadata.keys(): ln = int(metadata['mpris:length']) if ln < 1: self._track_duration = "0:00:00" else: self._track_duration = mpristime_to_upnptime(ln) log.msg('track length: %s' % self._track_duration, loglevel=logging.DEBUG) if 'xesam:url' in metadata.keys(): self._track_URI = metadata['xesam:url'] self.metadata_str = didl_encode(self.metadata)
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.err(md) self.metadata.update(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.oh_eventINFO(sec, 'duration') self.oh_eventTIME(sec, 'duration') if self.songid != self.metadata['id']: self.songid = self.metadata['id'] self.upnp_eventAV(int(self.songid), 'CurrentTrack') self.oh_eventPLAYLIST(int(self.songid), 'id') self.oh_eventTIME(1, 'trackcount') 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.oh_eventINFO(1, 'lossless') else: self.oh_eventINFO(0, 'lossless') 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 update_metadata(self, metadata): if metadata == self._metadata: return self._metadata = metadata metadata = mpris_decode(metadata) songid = None if self.has_tracklist: if "mpris:trackid" in metadata: try: if self.songid != self.numid[str(metadata["mpris:trackid"])]: songid = self.numid[str(metadata["mpris:trackid"])] except KeyError: if "url" in metadata: self.maxsongid += 1 self.numid.update({self.maxsongid: str(metadata["mpris:trackid"])}) self.numid.update({str(metadata["mpris:trackid"]): self.maxsongid}) self.playlist.append(self.maxsongid) # if len(self.badlist) > 0: # songid = self.badlist.pop(0) # self.numid.update( # {songid: str(metadata['mpris:trackid'])}) # self.numid.update( # {str(metadata['mpris:trackid']): songid}) # else: # self.insert( # metadata['url'], self.maxsongid, metadata) elif "songid" in metadata: if self.songid != int(metadata["songid"]): songid = int(metadata["songid"]) else: if "songid" in metadata: if self.songid != int(metadata["songid"]): songid = int(metadata["songid"]) else: if "url" in metadata: for track in self._playlist: if track[1] == metadata["url"]: songid = track[0] metadata.update(track[2]) break else: songid = self.maxsongid + 1 self.insert(metadata["url"], self.maxsongid, metadata) if songid: self.songid = songid self.metadata = {} self.upnp_eventAV(int(self.songid), "CurrentTrack") self.oh_eventPLAYLIST(int(self.songid), "id") self.oh_eventTIME(1, "trackcount") if "duration" in metadata: if self._duration != metadata["duration"]: duration = int(metadata["duration"]) log.err("duration: %d" % duration) if duration < 1: self._track_duration = "0:00:00" self._duration = 0 else: self._duration = duration self._track_duration = mpristime_to_upnptime(duration) log.msg("track length: %s" % self._track_duration, loglevel=logging.DEBUG) self.upnp_eventAV(self._track_duration, "CurrentTrackDuration") self.oh_eventINFO(int(self._duration // 1000000), "duration") self.oh_eventTIME(int(self._duration // 1000000), "duration") if "url" in metadata: if self._track_URI != metadata["url"]: self._track_URI = metadata["url"] self.upnp_eventAV(self._track_URI, "AVTransportURI") self.oh_eventINFO(self._track_URI, "uri") self.upnp_eventAV(self._track_URI, "CurrentTrackURI") if "mpris:artUrl" in metadata: url = self.parent.register_art_url(metadata["mpris:artUrl"]) metadata["albumArtURI"] = url self.metadata.update(metadata) self.metadata_str = didl_encode(self.metadata) self.oh_eventINFO(self.metadata_str, "metadata") self.upnp_eventAV(self.metadata_str, "AVTransportURIMetaData")
def got_result(res): uri = res['url'] return (uri, didl_encode(res))
def update_metadata(self, metadata): if metadata == self._metadata: return self._metadata = metadata metadata = mpris_decode(metadata) songid = None if self.has_tracklist: if 'mpris:trackid' in metadata: try: if self.songid != self.numid[str( metadata['mpris:trackid'])]: songid = self.numid[str(metadata['mpris:trackid'])] except KeyError: if 'url' in metadata: self.maxsongid += 1 self.numid.update( {self.maxsongid: str(metadata['mpris:trackid'])}) self.numid.update( {str(metadata['mpris:trackid']): self.maxsongid}) self.playlist.append(self.maxsongid) # if len(self.badlist) > 0: # songid = self.badlist.pop(0) # self.numid.update( # {songid: str(metadata['mpris:trackid'])}) # self.numid.update( # {str(metadata['mpris:trackid']): songid}) # else: # self.insert( # metadata['url'], self.maxsongid, metadata) elif 'songid' in metadata: if self.songid != int(metadata['songid']): songid = int(metadata['songid']) else: if 'songid' in metadata: if self.songid != int(metadata['songid']): songid = int(metadata['songid']) else: if 'url' in metadata: for track in self._playlist: if track[1] == metadata['url']: songid = track[0] metadata.update(track[2]) break else: songid = self.maxsongid + 1 self.insert(metadata['url'], self.maxsongid, metadata) if songid: self.songid = songid self.metadata = {} self.upnp_eventAV(int(self.songid), 'CurrentTrack') self.oh_eventPLAYLIST(int(self.songid), 'id') self.oh_eventTIME(1, 'trackcount') if 'duration' in metadata: if self._duration != metadata['duration']: duration = int(metadata['duration']) log.err('duration: %d' % duration) if duration < 1: self._track_duration = "0:00:00" self._duration = 0 else: self._duration = duration self._track_duration = mpristime_to_upnptime(duration) log.msg('track length: %s' % self._track_duration, loglevel=logging.DEBUG) self.upnp_eventAV(self._track_duration, 'CurrentTrackDuration') self.oh_eventINFO(int(self._duration // 1000000), 'duration') self.oh_eventTIME(int(self._duration // 1000000), 'duration') if 'url' in metadata: if self._track_URI != metadata['url']: self._track_URI = metadata['url'] self.upnp_eventAV(self._track_URI, 'AVTransportURI') self.oh_eventINFO(self._track_URI, 'uri') self.upnp_eventAV(self._track_URI, 'CurrentTrackURI') if 'mpris:artUrl' in metadata: url = self.parent.register_art_url(metadata['mpris:artUrl']) metadata['albumArtURI'] = url self.metadata.update(metadata) self.metadata_str = didl_encode(self.metadata) self.oh_eventINFO(self.metadata_str, 'metadata') self.upnp_eventAV(self.metadata_str, 'AVTransportURIMetaData')