def get_file(self, path): f = None if (path == "/"): f = File(self) f.path = "0" f.mimetype = f.DEVICE_ROOT f.resource = "" f.name = self.get_name() f.icon = self.get_icon() f.info = "UPnP network storage" f.folder_flags = f.ITEMS_ENQUEUEABLE else: if (path.startswith("/")): path = path[1:] didl, nil, nil, nil = self.__cds_proxy.Browse(None, path, "BrowseMetadata", "*", "0", "0", "") entry = didl_lite.parse(didl) ident, clss, child_count, res, title, artist, mimetype = entry[0] url_base = self.__description.get_url_base() f = File(self) f.mimetype = mimetype f.resource = res f.name = title f.info = artist f.path = "/" + path if (f.mimetype == f.DIRECTORY): f.resource = ident f.folder_flags = f.ITEMS_ENQUEUEABLE else: f.resource = urlparse.urljoin(url_base, res) f.child_count = child_count return f
def __build_file(self, url_base, entry): ident, clss, child_count, res, title, artist, mimetype = entry f = File(self) f.mimetype = mimetype f.resource = res or urlparse.urljoin(url_base, ident) f.name = title f.artist = artist f.info = artist if (f.mimetype == f.DIRECTORY): f.path = "/" + ident f.folder_flags = f.ITEMS_ENQUEUEABLE else: f.path = "/" + ident f.child_count = child_count # MythTV thinks Ogg-Vorbis was text/plain... if (clss.startswith("object.item.audioItem") and f.mimetype == "text/plain"): f.mimetype = "audio/x-unknown" # no useful MIME type reported? let's look at the file extension if (not f.mimetype in mimetypes.get_audio_types() + mimetypes.get_video_types() + mimetypes.get_image_types() + [f.DIRECTORY]): ext = os.path.splitext(f.name)[-1] f.mimetype = mimetypes.ext_to_mimetype(ext) if (f.mimetype.startswith("image/")): f.thumbnail = f.resource logging.debug("'%s' has MIME type '%s'" % (f.name, f.mimetype)) return f