def check_filename_extension(filename, content_type): """If a filename doesn't have an extension, this tries to find a suitable one based on the HTTP content-type info and add it if one is available. """ check_f(filename) if content_type is not None and not filetypes.is_allowed_filename(filename): guessed_ext = filetypes.guess_extension(content_type) if guessed_ext is not None: filename += guessed_ext return filename
def handle_external_url(url): if url.startswith(u'feed://') or url.startswith(u'feeds://'): feed_info = app.tabs['feed'].find_feed_with_url(url) if feed_info is not None: print 'SHOULD BLINK: %r' % feed_info.name return if filetypes.is_feed_filename(url): ask_for_feed_subscribe(url) elif filetypes.is_allowed_filename(url): # media URL, download it messages.DownloadURL(url).send_to_backend() else: app.widgetapp.open_url(url)
def should_load_url(self, url, mimetype=None): """Returns True if the Miro browser should handle the url and False otherwise. Situations which should return false: * if the url is something that Miro should download instead * other things? """ if mimetype is not None: logging.debug("got %s (%s)", url, mimetype) else: logging.debug("got %s", url) if url in self.seen_cache: del self.seen_cache[url] return True url = util.to_uni(url) if subscription.is_subscribe_link(url): messages.SubscriptionLinkClicked(url).send_to_backend() return False def unknown_callback(url): call_on_ui_thread(self.handle_unknown_url, url) if filetypes.is_maybe_rss_url(url): logging.debug("miro wants to handle %s", url) messages.DownloadURL(url, unknown_callback).send_to_backend() return False # parse the path out of the url and run that through the filetypes # code to see if it might be a video, audio or torrent file. # if so, try downloading it. ret = urlparse(url) if filetypes.is_allowed_filename(ret[2]): logging.debug("miro wants to handle %s", url) messages.DownloadURL(url, unknown_callback).send_to_backend() return False if mimetype is not None and filetypes.is_allowed_mimetype(mimetype): logging.debug("miro wants to handle %s", url) messages.DownloadURL(url, unknown_callback).send_to_backend() return False return True
def should_load_url(self, url): """Returns True if the Miro browser should handle the url and False otherwise. Situations which should return false: * if the url is something that Miro should download instead * other things? """ logging.debug("got %s", url) if url in self.seen_cache: del self.seen_cache[url] return True url = util.to_uni(url) if subscription.is_subscribe_link(url): self.emit('download-started') messages.SubscriptionLinkClicked(url).send_to_backend() return False if filetypes.is_maybe_rss_url(url): logging.debug("miro wants to handle %s", url) self.emit('download-started') messages.DownloadURL(url, self.unknown_callback).send_to_backend() return False # parse the path out of the url and run that through the filetypes # code to see if it might be a video, audio or torrent file. # if so, try downloading it. ret = urlparse(url) if filetypes.is_allowed_filename(ret[2]): logging.debug("miro wants to handle %s", url) self.emit('download-started') messages.DownloadURL(url, self.unknown_callback).send_to_backend() return False if util.is_magnet_uri(url): logging.debug("miro wants to handle %s", url) self.emit('download-started') messages.DownloadURL(url, self.unknown_callback).send_to_backend() return False return True