diff --git a/rtv/mime_parsers.py b/rtv/mime_parsers.py index f9005f7..a33b33c 100644 --- a/rtv/mime_parsers.py +++ b/rtv/mime_parsers.py @@ -153,7 +153,10 @@ class ImgurAlbumMIMEParser(BaseMIMEParser): urls = [] for div in soup.find_all('div', class_='post-image'): - urls.append('http:' + div.find('img').get('src')) + img = div.find('img') + src = img.get('src') if img else None + if src: + urls.append('http:{0}'.format(src)) if urls: return " ".join(urls), 'image/x-imgur-album' diff --git a/rtv/terminal.py b/rtv/terminal.py index 76d8b46..3915762 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -51,12 +51,7 @@ class Terminal(object): self.config = config self.loader = LoadScreen(self) self._display = None - - try: - self._mailcap_dict = mailcap.getcaps() - except IOError: - # Python 2 raises an error, python 3 does not - self._mailcap_dict = {} + self._mailcap_dict = mailcap.getcaps() @property def up_arrow(self): @@ -416,7 +411,14 @@ class Terminal(object): # could also be updated to point to a different page, or it # could refer to the location of a temporary file with the # page's downloaded content. - modified_url, content_type = parser.get_mimetype(url) + try: + modified_url, content_type = parser.get_mimetype(url) + except Exception as e: + # If Imgur decides to change its html layout, let it fail + # silently in the background instead of crashing. + _logger.warn('parser %s raised an exception', parser) + _logger.exception(e) + raise exceptions.MailcapEntryNotFound() if not content_type: _logger.info('Content type could not be determined') raise exceptions.MailcapEntryNotFound()