def _get_scrape_url(link): if not link.is_self: sr_name = link.subreddit_slow.name if not feature.is_enabled("imgur_gif_conversion", subreddit=sr_name): return link.url p = UrlParser(link.url) # If it's a gif link on imgur, replacing it with gifv should # give us the embedly friendly video url if is_subdomain(p.hostname, "imgur.com"): if p.path_extension().lower() == "gif": p.set_extension("gifv") return p.unparse() return link.url urls = extract_urls_from_markdown(link.selftext) second_choice = None for url in urls: p = UrlParser(url) if p.is_reddit_url(): continue # If we don't find anything we like better, use the first image. if not second_choice: second_choice = url # This is an optimization for "proof images" in AMAs. if is_subdomain(p.netloc, 'imgur.com') or p.has_image_extension(): return url return second_choice
def test_only_extension(self): u = UrlParser('http://example.com/.bashrc') self.assertEquals('bashrc', u.path_extension())
def test_two_extensions(self): u = UrlParser('http://example.com/a.jpg.exe') self.assertEquals('exe', u.path_extension())
def test_empty_extension(self): u = UrlParser('http://example.com/a.') self.assertEquals('', u.path_extension())
def test_nested_file(self): u = UrlParser('http://example.com/foo/a.jpg') self.assertEquals('jpg', u.path_extension())
def test_directory(self): u = UrlParser('http://example.com/') self.assertEquals('', u.path_extension()) u = UrlParser('http://example.com/foo/') self.assertEquals('', u.path_extension())
def test_no_path(self): u = UrlParser('http://example.com') self.assertEquals('', u.path_extension())