Ticket #317: filter.diff
| File filter.diff, 7.6 kB (added by Caleb, 2 years ago) |
|---|
-
__init__.py
old new 131 131 # create our own media renderer 132 132 # but only if we have a matching Coherence package installed 133 133 if self.coherence_version < (0, 5, 2): 134 print "activation fail d. Coherence is older than version 0.5.2"134 print "activation failed. Coherence is older than version 0.5.2" 135 135 else: 136 136 from coherence.upnp.devices.media_renderer import MediaRenderer 137 137 from MediaPlayer import RhythmboxPlayer … … 222 222 self.coherence_version = __version_info__ 223 223 224 224 coherence_config = { 225 #'logmode': 'info',225 'logmode': 'warning', 226 226 'controlpoint': 'yes', 227 227 'plugins': {}, 228 228 } … … 315 315 table.attach(port_spinner, 1, 2, 0, 1, 316 316 xoptions=gtk.FILL|gtk.EXPAND,yoptions=gtk.FILL|gtk.EXPAND,xpadding=5,ypadding=5) 317 317 318 label = gtk.Label(" Interface:")318 label = gtk.Label("Network Interface:") 319 319 label.set_alignment(0,0.5) 320 320 table.attach(label, 0, 1, 1, 2) 321 321 interface_entry = gtk.Entry() -
UpnpSource.py
old new 22 22 'udn': (gobject.TYPE_PYOBJECT, 'udn', 'udn', gobject.PARAM_WRITABLE|gobject.PARAM_CONSTRUCT_ONLY), 23 23 } 24 24 25 25 26 def __init__(self): 26 27 rb.BrowserSource.__init__(self) 27 28 self.__db = None 28 29 self.__activated = False 29 30 self.container_watch = [] 30 if coherence_version < (0,5,1): 31 self.process_media_server_browse = self.old_process_media_server_browse 32 else: 33 self.process_media_server_browse = self.new_process_media_server_browse 31 self.filters = "/Audio/All Audio", 34 32 35 33 def do_set_property(self, property, value): 36 34 if property.name == 'plugin': … … 54 52 self.__entry_type = self.get_property('entry-type') 55 53 56 54 # load upnp db 57 self. load_db(0)55 self.browse_source(0, '', True) 58 56 self.__client.content_directory.subscribe_for_variable('ContainerUpdateIDs', self.state_variable_change) 59 57 self.__client.content_directory.subscribe_for_variable('SystemUpdateID', self.state_variable_change) 60 58 61 59 62 def load_db(self, id):60 def browse_source(self, id, path, update_db): 63 61 d = self.__client.content_directory.browse(id, browse_flag='BrowseDirectChildren', process_result=False, backward_compatibility=False) 64 d.addCallback(self.process_media_server_browse, self.__udn )62 d.addCallback(self.process_media_server_browse, self.__udn, path, update_db) 65 63 64 def browse_item(self, id, path): 65 self.debug("browse_item called with id %s and path %s", id, path) 66 d = self.__client.content_directory.browse(id, browse_flag='BrowseMetadata', process_result=False) 67 d.addCallback(get_path, id, path) 66 68 69 def get_path(self, result, id, path): 70 elt = DIDLLite.DIDLElement.fromString(result['Result']) 71 for item in elt.getItems(): 72 if item.upnp_class.startswith("object.container") and item.id != '0': 73 d = self.__client.content_directory.browse(item.parentID, browse_flag='BrowseMetadata', process_result=False) 74 d.addCallback(get_path, id, "/" + item.title + path) 75 else: 76 self.debug("get_path got path %s", path) 77 got_path(self, id, path) 78 79 def got_path(self, id, path): 80 for filter in self.filters: 81 self.debug("browsing source with path %s, filtering on", path, filter) 82 self.browse_source(id, path, filter in path) 83 67 84 def state_variable_change(self, variable, udn=None): 68 85 self.info("%s changed from >%s< to >%s<", variable.name, variable.old_value, variable.value) 69 86 if variable.old_value == '': 70 87 return 71 88 72 89 if variable.name == 'SystemUpdateID': 73 self. load_db(0)90 self.browse_source(0, '', True) 74 91 elif variable.name == 'ContainerUpdateIDs': 75 92 changes = variable.value.split(',') 76 93 while len(changes) > 1: 77 94 container = changes.pop(0).strip() 78 95 update_id = changes.pop(0).strip() 79 96 if container in self.container_watch: 80 self. info("we have a change in %r, container needs a reload", container)81 self. load_db(container)97 self.warning("we have a change in %r, container needs a reload", container) 98 self.browse_item(container, '') 82 99 83 84 def new_process_media_server_browse(self, results, udn): 100 def process_media_server_browse(self, results, udn, path, update_db): 85 101 didl = DIDLLite.DIDLElement.fromString(results['Result']) 86 102 for item in didl.getItems(): 87 self. info("process_media_server_browse %r %r", item.id, item)103 self.debug("process_media_server_browse %r %r", item.id, item) 88 104 if item.upnp_class.startswith('object.container'): 89 self.load_db(item.id) 90 if item.upnp_class.startswith('object.item.audioItem'): 105 current_path = path + "/" + item.title 91 106 107 self.debug("%s (%s) with %d items" % (current_path, item.id, item.childCount)) 108 109 #browse subcontainers, only adding them if their path matches one of the specified filters 110 for filter in self.filters: 111 self.browse_source(item.id, current_path, filter in current_path) 112 113 if item.upnp_class.startswith('object.item.audioItem') and update_db == True: 114 92 115 url = None 93 116 duration = None 94 117 size = None … … 96 119 97 120 for res in item.res: 98 121 remote_protocol,remote_network,remote_content_format,remote_flags = res.protocolInfo.split(':') 99 self.info(" %r %r %r %r",remote_protocol,remote_network,remote_content_format,remote_flags)122 self.info("remote: %r %r %r %r",remote_protocol,remote_network,remote_content_format,remote_flags) 100 123 if remote_protocol == 'http-get': 101 124 url = res.data 102 125 duration = res.duration … … 105 128 break 106 129 107 130 if url is not None: 108 self.info("url %r %r",url,item.title)131 self.info("url: %r %r",url,item.title) 109 132 110 133 entry = self.__db.entry_lookup_by_location (url) 111 134 if entry == None: … … 133 156 if duration is not None: 134 157 h,m,s = duration.split(':') 135 158 seconds = int(h)*3600 + int(m)*60 + float(s) 136 self.info(" %r %r:%r:%r %r" % (duration,h,m,s,seconds))159 self.info("Duration: %r %r:%r:%r %r" % (duration,h,m,s,seconds)) 137 160 self.__db.set(entry, rhythmdb.PROP_DURATION, int(seconds)) 138 161 139 162 if size is not None: 140 163 self.__db.set(entry, rhythmdb.PROP_FILE_SIZE,int(size)) 141 164 142 165 self.__db.commit() 143 144 gobject.type_register(UpnpSource) 166 167 gobject.type_register(UpnpSource)
