# Buggy code
def parse(self, data, mode):
    """
    Parse search results for items.

    :param data: The raw response from a search
    :param mode: The current mode used to search, e.g. RSS

    :return: A list of items found
    """
    items = []

    with BS4Parser(
        data, "html.parser"
    ) as html:  # Use html.parser, since html5parser has issues with this site.
        tables = html("table", width="750")  # Get the last table with a width of 750px.
        torrent_table = tables[-1] if tables else []
        torrent_rows = torrent_table("tr") if torrent_table else []

        # Continue only if at least one release is found
        if len(torrent_rows) < 2:
            logger.log(
                "Data returned from provider does not contain any torrents",
                logger.DEBUG,
            )
            return items

        # Skip column headers
        for row in torrent_rows[1:]:
            cells = row("td")
            if len(cells) < 3:
                # We must have cells[2] because it containts the title
                continue

            if self.freeleech and not row.get("bgcolor"):
                continue

            try:
                title = cells[2].find("a")["title"]
                download_url = urljoin(self.url, cells[0].find("a")["href"])
                if not all([title, download_url]):
                    continue

                seeders = (
                    try_int(cells[8].get_text(strip=True)) if len(cells) > 8 else 1
                )
                leechers = (
                    try_int(cells[9].get_text(strip=True)) if len(cells) > 9 else 0
                )

                # Filter unseeded torrent
                if seeders < min(self.minseed, 1):
                    if mode != "RSS":
                        logger.log(
                            "Discarding torrent because it doesn't meet the "
                            "minimum seeders: {0}. Seeders: {1}".format(title, seeders),
                            logger.DEBUG,
                        )
                    continue

                torrent_size = cells[6].get_text(" ") if len(cells) > 6 else None
                size = convert_size(torrent_size) or -1

                item = {
                    "title": title,
                    "link": download_url,
                    "size": size,
                    "seeders": seeders,
                    "leechers": leechers,
                    "pubdate": None,
                }
                if mode != "RSS":
                    logger.log(
                        "Found result: {0} with {1} seeders and {2} leechers".format(
                            title, seeders, leechers
                        ),
                        logger.DEBUG,
                    )

                items.append(item)
            except (AttributeError, TypeError, KeyError, ValueError, IndexError):
                logger.log(
                    "Failed parsing provider. Traceback: {0!r}".format(
                        traceback.format_exc()
                    ),
                    logger.ERROR,
                )

    return items


# Traceback (TypeError)
2016-10-31 12:46:27 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [NZBGeek] :: [ff8dcfa] Added RSS item: [Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS] to cache: [nzbgeek]
2016-10-31 12:46:27 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [NZBGeek] :: [ff8dcfa] Mass updating cache table with manual results for provider: NZBGeek
2016-10-31 12:46:27 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [NZBGeek] :: [ff8dcfa] Transaction with 9 queries executed
2016-10-31 12:46:27 INFO     SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Performing episode search for Once Upon a Time (2011)
2016-10-31 12:46:27 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Search mode: Episode
2016-10-31 12:46:27 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Search string: Once Upon a Time (2011) S06E06
2016-10-31 12:46:29 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] GET URL: https://hd-torrents.org/torrents.php?category%5B3%5D=38&search=Once+Upon+a+Time+%282011%29+S06E06&category%5B4%5D=65&category%5B2%5D=30&active=1&options=0&category%5B1%5D=60&category%5B0%5D=59 [Status: 200]
2016-10-31 12:46:29 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:29 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Search string: Once Upon a Time S06E06
2016-10-31 12:46:30 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] GET URL: https://hd-torrents.org/torrents.php?category%5B3%5D=38&search=Once+Upon+a+Time+S06E06&category%5B4%5D=65&category%5B2%5D=30&active=1&options=0&category%5B1%5D=60&category%5B0%5D=59 [Status: 200]
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Found result: Once Upon a Time S06E06 720p HDTV x264-AVS with 60 seeders and 0 leechers
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Using cached parse result for 'Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS'
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Found result Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS at https://hd-torrents.org/download.php?id=9c60e52da795903dc3753814c822ef34fa549e79&f=Once+Upon+a+Time+S06E06+720p+HDTV+x264-AVS.torrent
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Single episode result.
2016-10-31 12:46:31 INFO     SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Removing cache entries older than 3 days from hdtorrents
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Creating UNIQUE URL index for hdtorrents
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Adding to cache item found in manual search: Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Using cached parse result for 'Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS'
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Added RSS item: [Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS] to cache: [hdtorrents]
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Mass updating cache table with manual results for provider: HDTorrents
2016-10-31 12:46:31 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [HDTorrents] :: [ff8dcfa] Transaction with 1 queries executed
2016-10-31 12:46:31 INFO     SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] Performing episode search for Once Upon a Time (2011)
2016-10-31 12:46:32 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] POST URL: https://speed.cd/takeElogin.php [Status: 302]
2016-10-31 12:46:32 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] With post data: username=**********&password=**********
2016-10-31 12:46:33 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] GET URL: http://speed.cd [Status: 200]
2016-10-31 12:46:33 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] Search mode: Episode
2016-10-31 12:46:33 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] Search string: Once Upon a Time (2011) S06E06
2016-10-31 12:46:35 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] GET URL: https://speed.cd/browse.php?c55=1&c52=1&search=Once+Upon+a+Time+%282011%29+S06E06&c41=1&c50=1&c2=1&c30=1&c49=1 [Status: 200]
2016-10-31 12:46:36 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:36 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] Search string: Once Upon a Time S06E06
2016-10-31 12:46:37 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [Speedcd] :: [ff8dcfa] GET URL: https://speed.cd/browse.php?c55=1&c52=1&search=Once+Upon+a+Time+S06E06&c41=1&c50=1&c2=1&c30=1&c49=1 [Status: 200]
2016-10-31 12:46:38 INFO     SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Performing episode search for Once Upon a Time (2011)
2016-10-31 12:46:40 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] POST URL: https://www.torrentbytes.net/takelogin.php [Status: 302]
2016-10-31 12:46:40 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] With post data: username=**********&login=Log+in%21&password=**********
2016-10-31 12:46:40 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] GET URL: https://www.torrentbytes.net/my.php [Status: 200]
2016-10-31 12:46:40 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Search mode: Episode
2016-10-31 12:46:40 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Search string: Once Upon a Time (2011) S06E06
2016-10-31 12:46:43 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] GET URL: https://www.torrentbytes.net/browse.php?search=Once+Upon+a+Time+%282011%29+S06E06&c41=1&c38=1&c37=1&c33=1&c32=1 [Status: 200]
2016-10-31 12:46:43 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:43 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Search string: Once Upon a Time S06E06
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] GET URL: https://www.torrentbytes.net/browse.php?search=Once+Upon+a+Time+S06E06&c41=1&c38=1&c37=1&c33=1&c32=1 [Status: 200]
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Found result: Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS with 40 seeders and 1 leechers
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Found result: Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS with 54 seeders and 2 leechers
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Using cached parse result for 'Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS'
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Found result Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS at https://www.torrentbytes.net/download.php?id=1301570&SSL=1
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Single episode result.
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Using cached parse result for 'Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS'
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Found result Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS at https://www.torrentbytes.net/download.php?id=1301595&SSL=1
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Single episode result.
2016-10-31 12:46:46 INFO     SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Removing cache entries older than 3 days from torrentbytes
2016-10-31 12:46:46 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Creating UNIQUE URL index for torrentbytes
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Adding to cache item found in manual search: Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Using cached parse result for 'Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS'
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Added RSS item: [Once.Upon.a.Time.S06E06.720p.HDTV.x264-AVS] to cache: [torrentbytes]
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Adding to cache item found in manual search: Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Using cached parse result for 'Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS'
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Added RSS item: [Once.Upon.a.Time.S06E06.HDTV.x264-KILLERS] to cache: [torrentbytes]
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Mass updating cache table with manual results for provider: TorrentBytes
2016-10-31 12:46:47 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [TorrentBytes] :: [ff8dcfa] Transaction with 2 queries executed
2016-10-31 12:46:47 INFO     SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Performing episode search for Once Upon a Time (2011)
2016-10-31 12:46:48 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] POST URL: https://api.t411.ch/auth [Status: 200]
2016-10-31 12:46:48 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] With post data: username=**********&password=**********
2016-10-31 12:46:48 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Search mode: Episode
2016-10-31 12:46:48 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Search string: Once Upon a Time (2011) S06E06
2016-10-31 12:46:48 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] GET URL: https://api.t411.ch/torrents/search/Once%20Upon%20a%20Time%20(2011)%20S06E06*?cid=433&limit=100 [Status: 200]
2016-10-31 12:46:48 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:49 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] GET URL: https://api.t411.ch/torrents/search/Once%20Upon%20a%20Time%20(2011)%20S06E06*?cid=637&limit=100 [Status: 200]
2016-10-31 12:46:49 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:49 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] GET URL: https://api.t411.ch/torrents/search/Once%20Upon%20a%20Time%20(2011)%20S06E06*?cid=455&limit=100 [Status: 200]
2016-10-31 12:46:49 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:50 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] GET URL: https://api.t411.ch/torrents/search/Once%20Upon%20a%20Time%20(2011)%20S06E06*?cid=639&limit=100 [Status: 200]
2016-10-31 12:46:50 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Data returned from provider does not contain any torrents
2016-10-31 12:46:50 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Search string: Once Upon a Time S06E06
2016-10-31 12:46:51 DEBUG    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] GET URL: https://api.t411.ch/torrents/search/Once%20Upon%20a%20Time%20S06E06*?cid=433&limit=100 [Status: 200]
2016-10-31 12:46:51 ERROR    SEARCHQUEUE-MANUAL-248835 :: [T411] :: [ff8dcfa] Unknown exception while searching T411. Error: "'int' object has no attribute '__getitem__'"
Traceback (most recent call last):
  File "/home/osmc/Medusa/medusa/search/core.py", line 621, in searchProviders
    downCurQuality, manual_search, manual_search_type)
  File "/home/osmc/Medusa/medusa/providers/generic_provider.py", line 182, in find_search_results
    items_list += self.search(search_string, ep_obj=episode)
  File "/home/osmc/Medusa/medusa/providers/torrent/json/t411.py", line 106, in search
    results += self.parse(jdata, mode)
  File "/home/osmc/Medusa/medusa/providers/torrent/json/t411.py", line 121, in parse
    torrent_rows = sorted(unsorted_torrent_rows, key=itemgetter('added'), reverse=True)
TypeError: 'int' object has no attribute '__getitem__'

# Fixed code
def parse(self, data, mode):
    """
    Parse search results for items.

    :param data: The raw response from a search
    :param mode: The current mode used to search, e.g. RSS

    :return: A list of items found
    """
    items = []

    with BS4Parser(
        data, "html.parser"
    ) as html:  # Use html.parser, since html5parser has issues with this site.
        tables = html("table", width="750")  # Get the last table with a width of 750px.
        torrent_table = tables[-1] if tables else []
        torrent_rows = torrent_table("tr") if torrent_table else []

        # Continue only if at least one release is found
        if len(torrent_rows) < 2:
            logger.log(
                "Data returned from provider does not contain any torrents",
                logger.DEBUG,
            )
            return items

        # Skip column headers
        for row in torrent_rows[1:]:
            cells = row("td")
            if len(cells) < 3:
                # We must have cells[2] because it containts the title
                continue

            if self.freeleech and not row.get("bgcolor"):
                continue

            try:
                title = cells[2].find("a")["title"] if cells[2] else None
                download_url = (
                    urljoin(self.url, cells[0].find("a")["href"]) if cells[0] else None
                )
                if not all([title, download_url]):
                    continue

                seeders = (
                    try_int(cells[8].get_text(strip=True)) if len(cells) > 8 else 1
                )
                leechers = (
                    try_int(cells[9].get_text(strip=True)) if len(cells) > 9 else 0
                )

                # Filter unseeded torrent
                if seeders < min(self.minseed, 1):
                    if mode != "RSS":
                        logger.log(
                            "Discarding torrent because it doesn't meet the "
                            "minimum seeders: {0}. Seeders: {1}".format(title, seeders),
                            logger.DEBUG,
                        )
                    continue

                torrent_size = cells[6].get_text(" ") if len(cells) > 6 else None
                size = convert_size(torrent_size) or -1

                item = {
                    "title": title,
                    "link": download_url,
                    "size": size,
                    "seeders": seeders,
                    "leechers": leechers,
                    "pubdate": None,
                }
                if mode != "RSS":
                    logger.log(
                        "Found result: {0} with {1} seeders and {2} leechers".format(
                            title, seeders, leechers
                        ),
                        logger.DEBUG,
                    )

                items.append(item)
            except (AttributeError, TypeError, KeyError, ValueError, IndexError):
                logger.log(
                    "Failed parsing provider. Traceback: {0!r}".format(
                        traceback.format_exc()
                    ),
                    logger.ERROR,
                )

    return items