# 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, "html5lib") as html:
        torrent_rows = html("div", class_="release_block")
        if len(torrent_rows) < 2:
            return

        for row in torrent_rows[1:]:
            try:
                first_cell = row.find("div", class_="release_row_first")
                cells = row("div", class_="release_row")

                title = (
                    cells[1]
                    .find("div", class_="release_text_contents")
                    .get_text()
                    .strip()
                )
                download_url = first_cell("a")[-1].get("href")

                if not all([title, download_url]):
                    continue

                download_url = urljoin(self.url, download_url)

                # Provider does not support seeders or leechers.
                seeders = -1
                leechers = -1

                torrent_size = first_cell.find("div", class_="release_size").get_text()
                match_size = ShanaProjectProvider.size_regex.match(torrent_size)
                try:
                    size = (
                        convert_size(match_size.group(1) + " " + match_size.group(2))
                        or -1
                    )
                except AttributeError:
                    size = -1

                date = cells[0].find("div", class_="release_last").get_text()
                pubdate = parser.parse(date)

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

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

    return items


# Traceback (TypeError)
2017-03-17 02:00:38 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Getting all episodes of [292421]
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Indexer info for show The Late Late Show with James Corden: S02E144
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Scene numbering enabled show 'The Late Late Show with James Corden', using indexer numbering: S02E144
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Converted parsed result James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT into title: James Corden, date: 2017-03-15, episode_title: Reese Witherspoon, screen_size: 720p, format: WEB-DL, video_codec: h264, release_group: HEAT, type: episode, parsing_time: 0.200747013092, total_time: None, absolute_episode: [], quality: 720p WEB-DL, episode: [144], season: 2
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Matched release 'James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT' to a show in your database: 'The Late Late Show with James Corden'
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Parsed 'James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT' into title: James Corden, date: 2017-03-15, episode_title: Reese Witherspoon, screen_size: 720p, format: WEB-DL, video_codec: h264, release_group: HEAT, type: episode, parsing_time: 0.200747013092, total_time: 57.1374089718, absolute_episode: [], quality: 720p WEB-DL, episode: [144], season: 2
2017-03-17 02:01:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Added RSS item: [James.Corden.2017.03.15.Reese.Witherspoon.720p.WEB.h264-HEAT] to cache: [bithdtv]
2017-03-17 02:01:15 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Time.The.Kalief.Browder.Story.S01E03.720p.WEB.x264-HEAT to a show in your database. Parser result: title: Time The Kalief Browder Story, season: 1, episode: [3], screen_size: 720p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: HEAT, type: episode, parsing_time: 0.193681955338, total_time: 0.560091018677, absolute_episode: [], quality: 720p WEB-DL
2017-03-17 02:01:15 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Seth.Meyers.2017.03.15.Keri.Russell.720p.HDTV.x264-CROOKS to a show in your database. Parser result: title: Seth Meyers, date: 2017-03-15, episode_title: Keri Russell, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CROOKS, type: episode, parsing_time: 0.221388101578, total_time: 0.225222110748, absolute_episode: [], quality: 720p HDTV, episode: [], season: None
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Akibas.Trip.The.Animation.S01E11.720p.WEB.x264-ANiURL to a show in your database. Parser result: title: Akibas Trip The Animation, season: 1, episode: [11], screen_size: 720p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: ANiURL, type: episode, parsing_time: 0.194520950317, total_time: 0.556681871414, absolute_episode: [], quality: 720p WEB-DL
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Matched release 'The.100.S04E06.We.Will.Rise.1080p.AMZN.WEBRip.DD+5.1.x264-CasStudio.mkv' to a show in your database: 'The 100'
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Parsed 'The.100.S04E06.We.Will.Rise.1080p.AMZN.WEBRip.DD+5.1.x264-CasStudio.mkv' into title: The 100, season: 4, episode: [6], episode_title: We Will Rise, screen_size: 1080p, streaming_service: Amazon Prime, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, release_group: CasStudio, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.303165912628, total_time: 0.304452180862, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:16 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Added RSS item: [The.100.S04E06.We.Will.Rise.1080p.AMZN.WEBRip.DD+5.1.x264-CasStudio.mkv] to cache: [bithdtv]
2017-03-17 02:01:17 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Arrow.S05E16.Checkmate.720p.WEBRip.DD5.1.x264 to a show in your database. Parser result: title: Arrow, season: 5, episode: [16], episode_title: Checkmate, screen_size: 720p, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, type: episode, parsing_time: 0.235898017883, total_time: 0.593179941177, absolute_episode: [], quality: 720p WEB-DL
2017-03-17 02:01:17 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Jimmy.Fallon.2017.03.15.Ice.Cube.720p.HDTV.x264-CROOKS to a show in your database. Parser result: title: Jimmy Fallon, date: 2017-03-15, episode_title: Ice Cube, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: CROOKS, type: episode, parsing_time: 0.219856977463, total_time: 0.223697900772, absolute_episode: [], quality: 720p HDTV, episode: [], season: None
2017-03-17 02:01:17 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match At.Midnight.2017.03.15.1080p.WEB.x264-HEAT to a show in your database. Parser result: title: At Midnight, date: 2017-03-15, screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: HEAT, type: episode, parsing_time: 0.223325014114, total_time: 0.227200031281, absolute_episode: [], quality: 1080p WEB-DL, episode: [], season: None
2017-03-17 02:01:18 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Descending.Stories.Showa.Genroku.Rakugo.Shinju.S01E10.1080p.WEB.x264-ANiURL to a show in your database. Parser result: title: Descending Stories Showa Genroku Rakugo Shinju, season: 1, episode: [10], screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: ANiURL, type: episode, parsing_time: 0.198397874832, total_time: 0.558728933334, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:18 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match The.Americans.2013.S05E02.Pests.1080p.AMZN.WEBRip.DD5.1.x264-NTb.mkv to a show in your database. Parser result: title: The Americans, alias: The Americans 2013, year: 2013, season: 5, episode: [2], episode_title: Pests, screen_size: 1080p, streaming_service: Amazon Prime, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, release_group: NTb, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.318644046783, total_time: 0.679970979691, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Scene numbering enabled show 'Snatch' using indexer numbering: S01E02
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Converted parsed result Snatch.S01E02.1080p.WEB.X264-DEFLATE into title: Snatch, season: 1, episode: [2], screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: DEFLATE, type: episode, parsing_time: 0.193113088608, total_time: None, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Matched release 'Snatch.S01E02.1080p.WEB.X264-DEFLATE' to a show in your database: 'Snatch'
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Parsed 'Snatch.S01E02.1080p.WEB.X264-DEFLATE' into title: Snatch, season: 1, episode: [2], screen_size: 1080p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: DEFLATE, type: episode, parsing_time: 0.193113088608, total_time: 0.200086116791, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Added RSS item: [Snatch.S01E02.1080p.WEB.X264-DEFLATE] to cache: [bithdtv]
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Bellevue.S01E04.INTERNAL.720p.HDTV.x264-aAF to a show in your database. Parser result: title: Bellevue, season: 1, episode: [4], other: Internal, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: aAF, type: episode, parsing_time: 0.189285993576, total_time: 0.541562795639, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:19 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Seth.Meyers.2017.03.15.Keri.Russell.720p.WEB.x264-HEAT to a show in your database. Parser result: title: Seth Meyers, date: 2017-03-15, episode_title: Keri Russell, screen_size: 720p, format: WEB-DL, video_codec: h264, video_encoder: x264, release_group: HEAT, type: episode, parsing_time: 0.221376895905, total_time: 0.225260019302, absolute_episode: [], quality: 720p WEB-DL, episode: [], season: None
2017-03-17 02:01:20 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Arrow.S05E16.Checkmate.1080p.WEBRip.DD5.1.x264-CasStudio.mkv to a show in your database. Parser result: title: Arrow, season: 5, episode: [16], episode_title: Checkmate, screen_size: 1080p, format: WEBRip, audio_codec: AC3, audio_channels: 5.1, video_codec: h264, video_encoder: x264, release_group: CasStudio, container: mkv, mimetype: video/x-matroska, type: episode, parsing_time: 0.257858991623, total_time: 0.618865013123, absolute_episode: [], quality: 1080p WEB-DL
2017-03-17 02:01:21 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Jeff.And.Some.Aliens.S01E10.720p.HDTV.x264-MiNDTHEGAP to a show in your database. Parser result: title: Jeff And Some Aliens, season: 1, episode: [10], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: MiNDTHEGAP, type: episode, parsing_time: 0.190773963928, total_time: 0.556802988052, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:21 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Greys.Anatomy.S13E16.720p.HDTV.X264-DIMENSION to a show in your database. Parser result: title: Greys Anatomy, season: 13, episode: [16], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: DIMENSION, type: episode, parsing_time: 0.181162118912, total_time: 0.184938192368, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:21 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [BITHDTV] :: [a70a6df] Unable to match Bellevue.S01E03.INTERNAL.720p.HDTV.x264-aAF to a show in your database. Parser result: title: Bellevue, season: 1, episode: [3], other: Internal, screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: aAF, type: episode, parsing_time: 0.18679690361, total_time: 0.549944877625, absolute_episode: [], quality: 720p HDTV
2017-03-17 02:01:22 ERROR    SHOWUPDATER :: [a70a6df] Problem running show_updater, Indexer TVDBv2 seems to be having issues while trying to get updates for show Hannibal. Cause: 'NoneType' object is not iterable.
Traceback (most recent call last):
  File "/home/pi/Medusa/medusa/show_updater.py", line 86, in run
    update_max_weeks)
  File "/home/pi/Medusa/medusa/indexers/tvdbv2/tvdbv2_api.py", line 565, in get_last_updated_series
    last_update_ts = max(x.last_updated for x in updates)
TypeError: 'NoneType' object is not iterable

# 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, "html5lib") as html:
        torrent_rows = html("div", class_="release_block")
        if len(torrent_rows) < 2:
            return items

        for row in torrent_rows[1:]:
            try:
                first_cell = row.find("div", class_="release_row_first")
                cells = row("div", class_="release_row")

                title = (
                    cells[1]
                    .find("div", class_="release_text_contents")
                    .get_text()
                    .strip()
                )
                download_url = first_cell("a")[-1].get("href")

                if not all([title, download_url]):
                    continue

                download_url = urljoin(self.url, download_url)

                # Provider does not support seeders or leechers.
                seeders = -1
                leechers = -1

                torrent_size = first_cell.find("div", class_="release_size").get_text()
                match_size = ShanaProjectProvider.size_regex.match(torrent_size)
                try:
                    size = (
                        convert_size(match_size.group(1) + " " + match_size.group(2))
                        or -1
                    )
                except AttributeError:
                    size = -1

                date = cells[0].find("div", class_="release_last").get_text()
                pubdate = parser.parse(date)

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

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

    return items