def test_is_maybe_rss_url(self): # negative tests for test in ["http://example.com/", "mailto:[email protected]", ]: self.assertEqual(filetypes.is_maybe_rss_url(test), False) # positive tests for test in ["http://feeds.feedburner.com/galacticast-flv", "http://example.com/101-tips-from-dean/feed.rss", "http://example.com/rss/DeanRocksVideoPodcast", "http://example.com/rss2.php", ]: self.assertEqual(filetypes.is_maybe_rss_url(test), True)
def test_is_maybe_rss_url(self): # negative tests for test in [ "http://example.com/", "mailto:[email protected]", ]: self.assertEqual(filetypes.is_maybe_rss_url(test), False) # positive tests for test in [ "http://feeds.feedburner.com/galacticast-flv", "http://example.com/101-tips-from-dean/feed.rss", "http://example.com/rss/DeanRocksVideoPodcast", "http://example.com/rss2.php", ]: self.assertEqual(filetypes.is_maybe_rss_url(test), True)
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