Example #1
0
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
Example #2
0
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
Example #3
0
 def test_only_extension(self):
     u = UrlParser('http://example.com/.bashrc')
     self.assertEquals('bashrc', u.path_extension())
Example #4
0
 def test_two_extensions(self):
     u = UrlParser('http://example.com/a.jpg.exe')
     self.assertEquals('exe', u.path_extension())
Example #5
0
 def test_empty_extension(self):
     u = UrlParser('http://example.com/a.')
     self.assertEquals('', u.path_extension())
Example #6
0
 def test_nested_file(self):
     u = UrlParser('http://example.com/foo/a.jpg')
     self.assertEquals('jpg', u.path_extension())
Example #7
0
    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())
Example #8
0
 def test_no_path(self):
     u = UrlParser('http://example.com')
     self.assertEquals('', u.path_extension())
Example #9
0
 def test_only_extension(self):
     u = UrlParser('http://example.com/.bashrc')
     self.assertEquals('bashrc', u.path_extension())
Example #10
0
 def test_two_extensions(self):
     u = UrlParser('http://example.com/a.jpg.exe')
     self.assertEquals('exe', u.path_extension())
Example #11
0
 def test_empty_extension(self):
     u = UrlParser('http://example.com/a.')
     self.assertEquals('', u.path_extension())
Example #12
0
 def test_nested_file(self):
     u = UrlParser('http://example.com/foo/a.jpg')
     self.assertEquals('jpg', u.path_extension())
Example #13
0
    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())
Example #14
0
 def test_no_path(self):
     u = UrlParser('http://example.com')
     self.assertEquals('', u.path_extension())