def update_metadata(self, metadata): songid = None if isinstance(metadata, dict): if self._metadata == metadata: return else: self._metadata = metadata self.metadata = mpris_decode(metadata) elif isinstance(metadata, str): if self.metadata_str == metadata: return else: self.metadata_str = metadata self.metadata = didl_decode(metadata) log.msg(self.metadata) else: log.err('Bad metadata format : %s' % metadata) return if 'songid' in self.metadata: if self.songid != int(self.metadata['songid']): songid = int(self.metadata['songid']) if songid: self.songid = songid self.upnp_eventAV(int(self.songid), 'CurrentTrack') self.oh_eventPLAYLIST(int(self.songid), 'id') self.oh_eventTIME(1, 'trackcount') if 'duration' in self.metadata: if self._duration != self.metadata['duration']: duration = int(self.metadata['duration']) log.msg('duration: %d' % duration) if duration < 1: self.upnp_duration = "0:00:00" self._duration = 0 else: self._duration = duration self.upnp_duration = mpristime_to_upnptime(duration) log.msg('track length: %s' % self.upnp_duration, loglevel=logging.DEBUG) self.upnp_eventAV(self.upnp_duration, 'CurrentTrackDuration') self.oh_eventINFO(int(self._duration//1000000), 'duration') self.oh_eventTIME(int(self._duration//1000000), 'duration') if 'url' in self.metadata: if self._track_URI != self.metadata['url']: 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') if 'mpris:artUrl' in self.metadata: url = self.parent.register_art_url(self.metadata['mpris:artUrl']) self.metadata['albumArtURI'] = url self.oh_eventINFO(self.metadata_str, 'metadata') self.upnp_eventAV(self.metadata_str, 'AVTransportURIMetaData')
def update_metadata(self, metadata): songid = None if isinstance(metadata, dict): if self._metadata == metadata: return else: self._metadata = metadata self.metadata = mpris_decode(metadata) elif isinstance(metadata, str): if self.metadata_str == metadata: return else: self.metadata_str = metadata self.metadata = didl_decode(metadata) log.msg(self.metadata) else: log.err('Bad metadata format : %s' % metadata) return if 'songid' in self.metadata: if self.songid != int(self.metadata['songid']): songid = int(self.metadata['songid']) if songid: self.songid = songid self.upnp_eventAV(int(self.songid), 'CurrentTrack') self.oh_eventPLAYLIST(int(self.songid), 'id') self.oh_eventTIME(1, 'trackcount') if 'duration' in self.metadata: if self._duration != self.metadata['duration']: duration = int(self.metadata['duration']) log.msg('duration: %d' % duration) if duration < 1: self.upnp_duration = "0:00:00" self._duration = 0 else: self._duration = duration self.upnp_duration = mpristime_to_upnptime(duration) log.msg('track length: %s' % self.upnp_duration, loglevel=logging.DEBUG) self.upnp_eventAV(self.upnp_duration, 'CurrentTrackDuration') self.oh_eventINFO(int(self._duration // 1000000), 'duration') self.oh_eventTIME(int(self._duration // 1000000), 'duration') if 'url' in self.metadata: if self._track_URI != self.metadata['url']: 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') if 'mpris:artUrl' in self.metadata: url = self.parent.register_art_url(self.metadata['mpris:artUrl']) self.metadata['albumArtURI'] = url self.oh_eventINFO(self.metadata_str, 'metadata') self.upnp_eventAV(self.metadata_str, 'AVTransportURIMetaData')
def set_track_URI(self, uri, md=''): log.msg("set track uri : %s " % uri, loglevel=logging.DEBUG) try: log.msg("current uri : %s " % self._track_URI, loglevel=logging.DEBUG) except: pass if uri != self._track_URI: self._track_URI = uri self.metadata_str = md self.set_metadata(didl_decode(md.encode('utf-8'))) d = self.mpd.call('addid', uri) d.addCallback(self.set_songid) d.addCallback(self.play)
def set_track_URI(self, uri, md=''): log.msg("set track uri : %s " % uri, loglevel=logging.DEBUG) try: log.msg("current uri : %s " % self._track_URI, loglevel=logging.DEBUG) except: pass if uri != self._track_URI: self._track_URI = uri self.metadata_str = md self.set_metadata(didl_decode(md.encode('utf8'))) self.stop() reactor.callLater(0.5, # @UndefinedVariable self.play)
def set_track_URI(self, uri, md=""): log.msg("set track uri : %s " % uri, loglevel=logging.DEBUG) try: log.msg("current uri : %s " % self._track_URI, loglevel=logging.DEBUG) except: pass if uri != self._track_URI: self._track_URI = uri self.metadata_str = md self.set_metadata(didl_decode(md.encode("utf8"))) if self.launched: if self.stopping: self._down.cancel() self.stopping = False if self.playfunc != "Pause": # omxplayer fix d = self.mediaplayer.call("OpenUri", uri) d.addErrback(dbus_func_failed, ("OpenUri : %s" % uri,))
def insert_metadata(self, md): dic = didl_decode(md) # log.err(dic) for i, tag in enumerate(dic.keys()): if tag.lower() in ('class', 'restricted', 'id', 'duration', 'parentid', 'protocolinfo', 'url', 'ownerudn'): continue if not isinstance(dic[tag], str): continue reactor.callLater( # @UndefinedVariable float(i)/2, self.mpd.call, ' '.join(('sticker', 'set song', dic['url'].join('"'*2), tag, '"' + dic[tag] + '"')))
def set_track_URI(self, uri, md=''): log.msg("set track uri : %s " % uri, loglevel=logging.DEBUG) try: log.msg("current uri : %s " % self._track_URI, loglevel=logging.DEBUG) except: pass if uri != self._track_URI: self._track_URI = uri self.metadata_str = md self.set_metadata(didl_decode(md.encode('utf8'))) if self.launched: if self.stopping: self._down.cancel() self.stopping = False if self.playfunc != 'Pause': # omxplayer fix d = self.mediaplayer.call('OpenUri', uri) d.addErrback(dbus_func_failed, ('OpenUri : %s' % uri, ))
def insert(self, url, afterid, metadata, checked=False): # def get_newid(ignored): # d = self.mediaplayer.get( # 'Tracks', interf='org.mpris.MediaPlayer2.TrackList') # d.addCallback(got_id) # return d # # def got_id(newidlist): # print(newidlist) # newid = [ # item for item in newidlist if item not in self._playlist] # try: # return newid[0] # except: # print("gggg") # self.badlist.append(self.maxsongid+1) # return {'pos': self.maxsongid+1} # # def inserted(res, md): # self.maxsongid += 1 # if isinstance(res, dict): # meta = didl_decode(md.encode('utf-8')) # meta.update({'songid': res['pos']}) # res.update({'metadata': meta}) # else: # self.numid.update({res: self.maxsongid}) # print(res) # self.numid.update({self.maxsongid: res}) # return self.maxsongid if self.launching: d = task.deferLater(reactor, 0.5, self.insert, *(url, afterid, metadata)) return d if not self.launched: print("*") self.launching = True threads.deferToThread(self.launch_player) d = task.deferLater(reactor, 0.5, self.insert, *(url, afterid, metadata)) return d if "youtube" in url and not checked: # eclipse workaround !!! y = os.environ y.update({"PYTHONPATH": "/usr/bin/python"}) # / eclipse workaround d = utils.getProcessOutput("/usr/bin/youtube-dl", ["-g", "-f", "bestaudio", url], env=y, reactor=reactor) d.addCallback(lambda u: self.insert(u.split("\n")[0], afterid, metadata, True)) return d if self.has_tracklist: if len(self.playlist) == 0 or int(afterid) == 0: self.mediaplayer.call( "AddTrack", url, dbus.ObjectPath("/org/mpris/MediaPlayer2/TrackList/NoTrackurl"), True, interf="org.mpris.MediaPlayer2.TrackList", ) else: self.mediaplayer.call( "AddTrack", url, dbus.ObjectPath(self.numid[int(afterid)]), True, interf="org.mpris.MediaPlayer2.TrackList", ) # d.addCallback(get_newid) # d.addCallback(inserted, metadata) d = task.deferLater(reactor, 0.5, lambda: self.playlist[-1]) d.addCallback(show) return d else: log.err("playlist length:%s" % len(self._playlist)) self.maxsongid += 1 if not isinstance(metadata, dict): try: metadata = metadata.encode("utf-8") except: log.err("utf8 issue: %s" % metadata) metadata = metadata.decode("utf-8") metadata = didl_decode(metadata) metadata.update({"songid": str(self.maxsongid)}) if len(self._playlist) == 0: self._playlist.append([self.maxsongid, url, metadata]) else: self._playlist.insert(self.playlist[self.playlist.index(int(afterid))], [self.maxsongid, url, metadata]) log.err("real playlist: %s" % self._playlist) self.playlist = [i[0] for i in self._playlist] log.err("new playlist: %s" % self.playlist) log.err("metadata dic: %s" % metadata) self.oh_playlist = [str(i) for i in self.playlist] self.idArray = id_array(self.playlist) self.changed_state("TrackList", {}, "") if self.songid == 0: self.songid = 1 return defer.succeed(self.maxsongid)
def insert(self, url, afterid, metadata, checked=False): # def get_newid(ignored): # d = self.mediaplayer.get( # 'Tracks', interf='org.mpris.MediaPlayer2.TrackList') # d.addCallback(got_id) # return d # # def got_id(newidlist): # print(newidlist) # newid = [ # item for item in newidlist if item not in self._playlist] # try: # return newid[0] # except: # print("gggg") # self.badlist.append(self.maxsongid+1) # return {'pos': self.maxsongid+1} # # def inserted(res, md): # self.maxsongid += 1 # if isinstance(res, dict): # meta = didl_decode(md.encode('utf-8')) # meta.update({'songid': res['pos']}) # res.update({'metadata': meta}) # else: # self.numid.update({res: self.maxsongid}) # print(res) # self.numid.update({self.maxsongid: res}) # return self.maxsongid if self.launching: d = task.deferLater(reactor, 0.5, self.insert, *(url, afterid, metadata)) return d if not self.launched: print('*') self.launching = True threads.deferToThread(self.launch_player) d = task.deferLater(reactor, 0.5, self.insert, *(url, afterid, metadata)) return d if 'youtube' in url and not checked: # eclipse workaround !!! y = os.environ y.update({'PYTHONPATH': '/usr/bin/python'}) # / eclipse workaround d = utils.getProcessOutput('/usr/bin/youtube-dl', ['-g', '-f', 'bestaudio', url], env=y, reactor=reactor) d.addCallback(lambda u: self.insert( u.split('\n')[0], afterid, metadata, True)) return d if self.has_tracklist: if len(self.playlist) == 0 or int(afterid) == 0: self.mediaplayer.call( 'AddTrack', url, dbus.ObjectPath( '/org/mpris/MediaPlayer2/TrackList/NoTrackurl'), True, interf='org.mpris.MediaPlayer2.TrackList') else: self.mediaplayer.call( 'AddTrack', url, dbus.ObjectPath(self.numid[int(afterid)]), True, interf='org.mpris.MediaPlayer2.TrackList') # d.addCallback(get_newid) # d.addCallback(inserted, metadata) d = task.deferLater(reactor, 0.5, lambda: self.playlist[-1]) d.addCallback(show) return d else: log.err('playlist length:%s' % len(self._playlist)) self.maxsongid += 1 if not isinstance(metadata, dict): try: metadata = metadata.encode('utf-8') except: log.err('utf8 issue: %s' % metadata) metadata = metadata.decode('utf-8') metadata = didl_decode(metadata) metadata.update({'songid': str(self.maxsongid)}) if len(self._playlist) == 0: self._playlist.append([self.maxsongid, url, metadata]) else: self._playlist.insert( self.playlist[self.playlist.index(int(afterid))], [self.maxsongid, url, metadata]) log.err('real playlist: %s' % self._playlist) self.playlist = [i[0] for i in self._playlist] log.err('new playlist: %s' % self.playlist) log.err('metadata dic: %s' % metadata) self.oh_playlist = [str(i) for i in self.playlist] self.idArray = id_array(self.playlist) self.changed_state('TrackList', {}, '') if self.songid == 0: self.songid = 1 return defer.succeed(self.maxsongid)