# Buggy code
def load_imdb_info(self):
    """Load all required show information from IMDb with IMDbPY."""
    imdb_api = imdb.IMDb()
    if not self.imdbid:
        self.imdbid = imdb_api.title2imdbID(self.name, kind="tv series")

    if not self.imdbid:
        logger.log(
            "{0}: Not loading show info from IMDb, because we don't know its ID".format(
                self.indexerid
            )
        )
        return

    # Make sure we only use one ID
    imdb_id = self.imdbid.split(",")[0]

    logger.log(
        "{0}: Loading show info from IMDb with ID: {1}".format(self.indexerid, imdb_id),
        logger.DEBUG,
    )

    # Remove first two chars from ID
    imdb_obj = imdb_api.get_movie(imdb_id[2:])

    self.imdb_info = {
        "imdb_id": imdb_id,
        "title": imdb_obj.get("title", ""),
        "year": imdb_obj.get("year", ""),
        "akas": "|".join(imdb_obj.get("akas", "")),
        "genres": "|".join(imdb_obj.get("genres", "")),
        "countries": "|".join(imdb_obj.get("countries", "")),
        "country_codes": "|".join(imdb_obj.get("country codes", "")),
        "rating": imdb_obj.get("rating", ""),
        "votes": imdb_obj.get("votes", ""),
        "last_update": datetime.date.today().toordinal(),
    }

    if imdb_obj.get("runtimes"):
        self.imdb_info["runtimes"] = re.search(r"\d+", imdb_obj["runtimes"][0]).group(0)

    # Get only the production country certificate if any
    if imdb_obj.get("certificates") and imdb_obj.get("countries"):
        for certificate in imdb_obj["certificates"]:
            if certificate.split(":")[0] in imdb_obj["countries"]:
                self.imdb_info["certificates"] = certificate.split(":")[1]
                break

    logger.log(
        "{0}: Obtained info from IMDb: {1}".format(self.indexerid, self.imdb_info),
        logger.DEBUG,
    )


# Traceback (IOError)
2016-09-15 08:30:28 DEBUG    SHOWQUEUE-UPDATE :: [949e76b] 258959: Loading show info from IMDb with ID: tt2193041
2016-09-15 08:31:02,550 CRITICAL [imdbpy] /home/osmc/SickRage/lib/imdb/_exceptions.py:35: IMDbDataAccessError exception raised; args: ({'exception type': 'IOError', 'url': 'http://akas.imdb.com/title/tt2193041/plotsummary', 'errcode': 'socket error', 'proxy': '', 'original exception': IOError('socket error', timeout('timed out',)), 'errmsg': 'timed out'},); kwds: {}
Traceback (most recent call last):
File "/home/osmc/SickRage/lib/imdb/parser/http/__init__.py", line 202, in retrieve_unicode
uopener = self.open(url)
File "/usr/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/usr/lib/python2.7/urllib.py", line 350, in open_http
h.endheaders(data)
File "/usr/lib/python2.7/httplib.py", line 997, in endheaders
self._send_output(message_body)
File "/usr/lib/python2.7/httplib.py", line 850, in _send_output
self.send(msg)
File "/usr/lib/python2.7/httplib.py", line 812, in send
self.connect()
File "/usr/lib/python2.7/httplib.py", line 793, in connect
self.timeout, self.source_address)
File "/usr/lib/python2.7/socket.py", line 571, in create_connection
raise err
IOError: [Errno socket error] timed out
2016-09-15 08:31:02,563 CRITICAL [imdbpy] /home/osmc/SickRage/lib/imdb/__init__.py:777: caught an exception retrieving or parsing "plot" info set for mopID "2193041" (accessSystem: http)
Traceback (most recent call last):
File "/home/osmc/SickRage/lib/imdb/__init__.py", line 772, in update
ret = method(mopID)
File "/home/osmc/SickRage/lib/imdb/parser/http/__init__.py", line 514, in get_movie_plot
cont = self._retrieve(self.urls['movie_main'] % movieID + 'plotsummary')
File "/home/osmc/SickRage/lib/imdb/parser/http/__init__.py", line 453, in _retrieve
ret = self.urlOpener.retrieve_unicode(url, size=size)
File "/home/osmc/SickRage/lib/imdb/parser/http/__init__.py", line 236, in retrieve_unicode
'original exception': e})
IMDbDataAccessError: {'exception type': 'IOError', 'url': 'http://akas.imdb.com/title/tt2193041/plotsummary', 'errcode': 'socket error', 'proxy': '', 'original exception': IOError('socket error', timeout('timed out',)), 'errmsg': 'timed out'}

# Fixed code
def load_imdb_info(self):
    """Load all required show information from IMDb with IMDbPY."""
    imdb_api = imdb.IMDb()

    try:
        if not self.imdbid:
            self.imdbid = imdb_api.title2imdbID(self.name, kind="tv series")

        if not self.imdbid:
            logger.log(
                "{0}: Not loading show info from IMDb, "
                "because we don't know its ID".format(self.indexerid)
            )
            return

        # Make sure we only use one ID
        imdb_id = self.imdbid.split(",")[0]

        logger.log(
            "{0}: Loading show info from IMDb with ID: {1}".format(
                self.indexerid, imdb_id
            ),
            logger.DEBUG,
        )

        # Remove first two chars from ID
        imdb_obj = imdb_api.get_movie(imdb_id[2:])

    except IMDbDataAccessError:
        logger.log(
            "{0}: Failed to obtain info from IMDb for: {1}".format(
                self.indexerid, self.name
            ),
            logger.DEBUG,
        )
        return

    except IMDbParserError:
        logger.log(
            "{0}: Failed to parse info from IMDb for: {1}".format(
                self.indexerid, self.name
            ),
            logger.ERROR,
        )
        return

    self.imdb_info = {
        "imdb_id": imdb_id,
        "title": imdb_obj.get("title", ""),
        "year": imdb_obj.get("year", ""),
        "akas": "|".join(imdb_obj.get("akas", "")),
        "genres": "|".join(imdb_obj.get("genres", "")),
        "countries": "|".join(imdb_obj.get("countries", "")),
        "country_codes": "|".join(imdb_obj.get("country codes", "")),
        "rating": imdb_obj.get("rating", ""),
        "votes": imdb_obj.get("votes", ""),
        "last_update": datetime.date.today().toordinal(),
    }

    if imdb_obj.get("runtimes"):
        self.imdb_info["runtimes"] = re.search(r"\d+", imdb_obj["runtimes"][0]).group(0)

    # Get only the production country certificate if any
    if imdb_obj.get("certificates") and imdb_obj.get("countries"):
        for certificate in imdb_obj["certificates"]:
            if certificate.split(":")[0] in imdb_obj["countries"]:
                self.imdb_info["certificates"] = certificate.split(":")[1]
                break

    logger.log(
        "{0}: Obtained info from IMDb: {1}".format(self.indexerid, self.imdb_info),
        logger.DEBUG,
    )