# Buggy code
def search(self, search_strings, age=0, ep_obj=None):
    """
    Searche indexer using the params in search_strings, either for latest releases, or a string/id search.

    Returns: list of results in dict form
    """
    results = []
    if not self._check_auth():
        return results

    # For providers that don't have caps, or for which the t=caps is not working.
    if not self.caps and all(
        provider not in self.url for provider in self.providers_without_caps
    ):
        self.get_newznab_categories(just_caps=True)
        if not self.caps:
            return results

    for mode in search_strings:
        self.torznab = False
        search_params = {
            "t": "search",
            "limit": 100,
            "offset": 0,
            "cat": self.cat_ids.strip(", ") or "5030,5040",
            "maxage": app.USENET_RETENTION,
        }

        if self.needs_auth and self.key:
            search_params["apikey"] = self.key

        if mode != "RSS":
            match_indexer = self._match_indexer()
            search_params["t"] = (
                "tvsearch" if match_indexer and not self.force_query else "search"
            )

            if search_params["t"] == "tvsearch":
                search_params.update(match_indexer)

                if ep_obj.show.air_by_date or ep_obj.show.sports:
                    date_str = str(ep_obj.airdate)
                    search_params["season"] = date_str.partition("-")[0]
                    search_params["ep"] = date_str.partition("-")[2].replace("-", "/")
                else:
                    search_params["season"] = ep_obj.scene_season
                    search_params["ep"] = ep_obj.scene_episode

            if mode == "Season":
                search_params.pop("ep", "")

        items = []
        logger.log("Search mode: {0}".format(mode), logger.DEBUG)

        for search_string in search_strings[mode]:
            if mode != "RSS":
                # If its a PROPER search, need to change param to 'search' so it searches using 'q' param
                if any(
                    proper_string in search_string
                    for proper_string in self.proper_strings
                ):
                    search_params["t"] = "search"

                logger.log(
                    "Search show using {search}".format(
                        search="search string: {search_string}".format(
                            search_string=search_string
                            if search_params["t"] != "tvsearch"
                            else "indexer_id: {indexer_id}".format(
                                indexer_id=match_indexer
                            )
                        )
                    ),
                    logger.DEBUG,
                )

                if search_params["t"] != "tvsearch":
                    search_params["q"] = search_string

            time.sleep(cpu_presets[app.CPU_PRESET])

            response = self.get_url(
                urljoin(self.url, "api"), params=search_params, returns="response"
            )
            if not response or not response.text:
                logger.log("No data returned from provider", logger.DEBUG)
                continue

            with BS4Parser(response.text, "html5lib") as html:
                if not self._check_auth_from_data(html):
                    return items

                try:
                    self.torznab = "xmlns:torznab" in html.rss.attrs
                except AttributeError:
                    self.torznab = False

                for item in html("item"):
                    try:
                        title = item.title.get_text(strip=True)
                        download_url = None
                        if item.link:
                            if validators.url(item.link.get_text(strip=True)):
                                download_url = item.link.get_text(strip=True)
                            elif validators.url(item.link.next.strip()):
                                download_url = item.link.next.strip()

                        if not download_url and item.enclosure:
                            if validators.url(item.enclosure.get("url", "").strip()):
                                download_url = item.enclosure.get("url", "").strip()

                        if not (title and download_url):
                            continue

                        seeders = leechers = -1
                        if "gingadaddy" in self.url:
                            size_regex = re.search(
                                r"\d*.?\d* [KMGT]B", str(item.description)
                            )
                            item_size = size_regex.group() if size_regex else -1
                        else:
                            item_size = (
                                item.size.get_text(strip=True) if item.size else -1
                            )
                            for attr in item("newznab:attr") + item("torznab:attr"):
                                item_size = (
                                    attr["value"]
                                    if attr["name"] == "size"
                                    else item_size
                                )
                                seeders = (
                                    try_int(attr["value"])
                                    if attr["name"] == "seeders"
                                    else seeders
                                )
                                peers = (
                                    try_int(attr["value"])
                                    if attr["name"] == "peers"
                                    else None
                                )
                                leechers = peers - seeders if peers else leechers

                        if not item_size or (
                            self.torznab and (seeders is -1 or leechers is -1)
                        ):
                            continue

                        size = convert_size(item_size) or -1
                        pubdate_raw = item.pubdate.get_text(strip=True)
                        pubdate = (
                            parser.parse(pubdate_raw, fuzzy=True)
                            if pubdate_raw
                            else None
                        )

                        item = {
                            "title": title,
                            "link": download_url,
                            "size": size,
                            "seeders": seeders,
                            "leechers": leechers,
                            "pubdate": pubdate,
                            "torrent_hash": None,
                        }
                        if mode != "RSS":
                            if seeders == -1:
                                logger.log(
                                    "Found result: {0}".format(title), logger.DEBUG
                                )
                            else:
                                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,
                        )
                        continue

            # Since we arent using the search string,
            # break out of the search string loop
            if "tvdbid" in search_params:
                break

        results += items

    # Reproces but now use force_query = True
    if not results and not self.force_query:
        self.force_query = True
        return self.search(search_strings, ep_obj=ep_obj)

    return results


# Traceback (ValueError)
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Parsed 'Z.Nation.S03E13.720p.HDTV.x264-SVA[rartv]' into title: Z Nation, season: 3, episode: [13], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: SVA, type: episode, parsing_time: 0.10568189621, total_time: 0.106388092041, absolute_episode: [], quality: 720p HDTV
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] 280494: Allowed, Preferred = [ SDTV, SD DVD ] [ None ] Found = [ 720p HDTV ]
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] 280494: Ignoring found result for 'Z Nation' S03E13 with unwanted quality '720p HDTV'
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Ignoring result Z.Nation.S03E13.720p.HDTV.x264-SVA[rartv].
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Parsed 'Z.Nation.S03E13.720p.HDTV.x264-FLEET[rartv]' into title: Z Nation, season: 3, episode: [13], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: FLEET, type: episode, parsing_time: 0.115422010422, total_time: 0.116024971008, absolute_episode: [], quality: 720p HDTV
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] 280494: Allowed, Preferred = [ SDTV, SD DVD ] [ None ] Found = [ 720p HDTV ]
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] 280494: Ignoring found result for 'Z Nation' S03E13 with unwanted quality '720p HDTV'
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Ignoring result Z.Nation.S03E13.720p.HDTV.x264-FLEET[rartv].
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Parsed 'Z.Nation.S03E13.HDTV.x264-FLEET[rartv]' into title: Z Nation, season: 3, episode: [13], format: HDTV, video_codec: h264, video_encoder: x264, release_group: FLEET, type: episode, parsing_time: 0.0889599323273, total_time: 0.0901069641113, absolute_episode: [], quality: SDTV
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] 280494: Allowed, Preferred = [ SDTV, SD DVD ] [ None ] Found = [ SDTV ]
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] 280494: 'Z Nation' S03E13 status is 'WANTED'. Accepting result with quality 'SDTV'
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Found result Z.Nation.S03E13.HDTV.x264-FLEET[rartv] at magnet:?xt=urn:btih:90ffd8c87f10e60ffd274d2508412868236e721b&dn=Z.Nation.S03E13.HDTV.x264-FLEET%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Single episode result.
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] The highest quality of any match is SDTV
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Picking the best result out of [u'Z.Nation.S03E13.HDTV.x264-FLEET[rartv]']
2016-12-09 19:22:15 INFO     SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Quality of Z.Nation.S03E13.HDTV.x264-FLEET[rartv] is SDTV
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Rarbg] :: [c5c1504] Picked Z.Nation.S03E13.HDTV.x264-FLEET[rartv] as the best
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [NyaaTorrents] :: [c5c1504] Z Nation is not an anime, skipping
2016-12-09 19:22:15 INFO     SEARCHQUEUE-FORCED-280494 :: [Usenet-Crawler] :: [c5c1504] Performing episode search for Z Nation
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Usenet-Crawler] :: [c5c1504] Search mode: Episode
2016-12-09 19:22:15 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Usenet-Crawler] :: [c5c1504] Search show using search string: Z Nation S03E13
2016-12-09 19:22:18 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Usenet-Crawler] :: [c5c1504] GET URL: https://www.usenet-crawler.com/api?apikey=**********&maxage=3000&cat=5000%2C5070%2C5040%2C5050%2C5030&q=Z+Nation+S03E13&limit=100&t=search&offset=0 [Status: 200]
2016-12-09 19:22:18 INFO     SEARCHQUEUE-FORCED-280494 :: [Hydra] :: [c5c1504] Performing episode search for Z Nation
2016-12-09 19:22:18 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Hydra] :: [c5c1504] Search mode: Episode
2016-12-09 19:22:18 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Hydra] :: [c5c1504] Search show using search string: Z Nation S03E13
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [Hydra] :: [c5c1504] GET URL: http://192.168.1.249:5075/api?apikey=**********&maxage=3000&cat=5000%2C5030%2C5040%2C5050%2C5070&q=Z+Nation+S03E13&limit=100&t=search&offset=0 [Status: 200]
2016-12-09 19:22:22 INFO     SEARCHQUEUE-FORCED-280494 :: [c5c1504] Downloading Z.Nation.S03E13.HDTV.x264-FLEET[rartv] with 94 seeders and 459 leechers from Rarbg
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Calling Transmission Client
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Requested a POST connection to http://192.168.1.249:9091/transmission/rpc with Params: None Data: {"arguments": {}, "method": "session-get"}
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Response to POST request is {"arguments":{"alt-speed-down":50,"alt-speed-enabled":false,"alt-speed-time-begin":540,"alt-speed-time-day":127,"alt-speed-time-enabled":false,"alt-speed-time-end":1020,"alt-speed-up":50,"blocklist-enabled":true,"blocklist-size":0,"blocklist-url":"http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz","cache-size-mb":16,"config-dir":"/config","dht-enabled":true,"download-dir":"/downloads/complete","download-dir-free-space":162111234048,"download-queue-enabled":true,"download-queue-size":5,"encryption":"preferred","idle-seeding-limit":30,"idle-seeding-limit-enabled":true,"incomplete-dir":"/downloads/incomplete","incomplete-dir-enabled":true,"lpd-enabled":false,"peer-limit-global":200,"peer-limit-per-torrent":50,"peer-port":51413,"peer-port-random-on-start":false,"pex-enabled":true,"port-forwarding-enabled":true,"queue-stalled-enabled":true,"queue-stalled-minutes":30,"rename-partial-files":true,"rpc-version":15,"rpc-version-minimum":1,"script-torrent-done-enabled":true,"script-torrent-done-filename":"/app/nzbToMedia/TorrentToMedia.py","seed-queue-enabled":false,"seed-queue-size":10,"seedRatioLimit":0,"seedRatioLimited":true,"speed-limit-down":100,"speed-limit-down-enabled":false,"speed-limit-up":100,"speed-limit-up-enabled":false,"start-added-torrents":true,"trash-original-torrent-files":false,"units":{"memory-bytes":1024,"memory-units":["KiB","MiB","GiB","TiB"],"size-bytes":1000,"size-units":["kB","MB","GB","TB"],"speed-bytes":1000,"speed-units":["kB/s","MB/s","GB/s","TB/s"]},"utp-enabled":true,"version":"2.92 (14714)"},"result":"success"}
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Requested a POST connection to http://192.168.1.249:9091/transmission/rpc with Params: None Data: {"arguments": {"paused": 0, "download-dir": "/downloads/complete/medusa", "filename": "magnet:?xt=u...
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Response to POST request is {"arguments":{"torrent-added":{"hashString":"90ffd8c87f10e60ffd274d2508412868236e721b","id":5,"name":"Z.Nation.S03E13.HDTV.x264-FLEET[rartv]"}},"result":"success"}
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Requested a POST connection to http://192.168.1.249:9091/transmission/rpc with Params: None Data: {"arguments": {"seedRatioMode": 1, "seedRatioLimit": 0.0, "ids": ["90ffd8c87f10e60ffd274d2508412868...
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Response to POST request is {"arguments":{},"result":"success"}
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Requested a POST connection to http://192.168.1.249:9091/transmission/rpc with Params: None Data: {"arguments": {"queuePosition": 0, "priority-high": [], "ids": ["90ffd8c87f10e60ffd274d250841286823...
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transmission: Response to POST request is {"arguments":{},"result":"success"}
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Checking if we should stop searching for a better quality for for episode Z.Nation.S03E13.HDTV.x264-FLEET[rartv]
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Found codec for Z Nation Duel
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] 280494: Formatting pattern: %SN - %Sx%0E - %EN - %QN -> Z Nation - 3x13 - 041 - Duel - SDTV
2016-12-09 19:22:22 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] GROWL: Sending message 'Z Nation - 3x13 - 041 - Duel - SDTV with 94 seeders and 459 leechers from Rarbg' to 192.168.1.101:23053
2016-12-09 19:22:23 DEBUG    SEARCHQUEUE-FORCED-280494 :: [c5c1504] Transaction with 1 queries executed
2016-12-09 19:22:27 DEBUG    SEARCHQUEUE-FORCED-311816 :: [c5c1504] 311816: Formatting pattern: %SN - S%0SE%0E - %EN -> The Exorcist - S01E09 - 009 - Chapter Nine 162
2016-12-09 19:22:27 INFO     SEARCHQUEUE-FORCED-311816 :: [c5c1504] Beginning forced search for: [The Exorcist - S01E09 - 009 - Chapter Nine 162]
2016-12-09 19:22:27 DEBUG    SEARCHQUEUE-FORCED-311816 :: [c5c1504] Internal name cache for The Exorcist set to: [the exorcist]
2016-12-09 19:22:27 INFO     SEARCHQUEUE-FORCED-311816 :: [c5c1504] Using backlog search providers
2016-12-09 19:22:27 INFO     SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Performing episode search for The Exorcist
2016-12-09 19:22:27 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Search mode: Episode
2016-12-09 19:22:27 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Search string: The Exorcist S01E09
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] GET URL: http://torrentapi.org/pubapi_v2.php?sort=seeders&min_leechers=0&min_seeders=1&search_tvdb=311816&app_id=medusa&search_string=The+Exorcist+S01E09&ranked=0&category=tv&format=json_extended&token=awdzxvs4hc&limit=100&mode=search [Status: 200]
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Found result: The.Exorcist.S01E09.HDTV.x264-FLEET[rartv] with 102 seeders and 307 leechers
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Found result: The.Exorcist.S01E09.720p.HDTV.x264-AVS[rartv] with 74 seeders and 468 leechers
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Parsed 'The.Exorcist.S01E09.720p.HDTV.x264-AVS[rartv]' into title: The Exorcist, season: 1, episode: [9], screen_size: 720p, format: HDTV, video_codec: h264, video_encoder: x264, release_group: AVS, type: episode, parsing_time: 0.107269048691, total_time: 0.107873916626, absolute_episode: [], quality: 720p HDTV
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] 311816: Allowed, Preferred = [ SDTV, SD DVD ] [ None ] Found = [ 720p HDTV ]
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] 311816: Ignoring found result for 'The Exorcist' S01E09 with unwanted quality '720p HDTV'
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Ignoring result The.Exorcist.S01E09.720p.HDTV.x264-AVS[rartv].
2016-12-09 19:22:32 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Parsed 'The.Exorcist.S01E09.HDTV.x264-FLEET[rartv]' into title: The Exorcist, season: 1, episode: [9], format: HDTV, video_codec: h264, video_encoder: x264, release_group: FLEET, type: episode, parsing_time: 0.08997797966, total_time: 0.0911781787872, absolute_episode: [], quality: SDTV
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] 311816: Allowed, Preferred = [ SDTV, SD DVD ] [ None ] Found = [ SDTV ]
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] 311816: 'The Exorcist' S01E09 status is 'WANTED'. Accepting result with quality 'SDTV'
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Found result The.Exorcist.S01E09.HDTV.x264-FLEET[rartv] at magnet:?xt=urn:btih:42a79ba5ff0d2d01779f6060c91f970725777dd2&dn=The.Exorcist.S01E09.HDTV.x264-FLEET%5Brartv%5D&tr=http%3A%2F%2Ftracker.trackerfix.com%3A80%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2710&tr=udp%3A%2F%2F9.rarbg.to%3A2710&tr=udp%3A%2F%2Fopen.demonii.com%3A1337%2Fannounce
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Single episode result.
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] The highest quality of any match is SDTV
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Picking the best result out of [u'The.Exorcist.S01E09.HDTV.x264-FLEET[rartv]']
2016-12-09 19:22:33 INFO     SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Quality of The.Exorcist.S01E09.HDTV.x264-FLEET[rartv] is SDTV
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Rarbg] :: [c5c1504] Picked The.Exorcist.S01E09.HDTV.x264-FLEET[rartv] as the best
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [NyaaTorrents] :: [c5c1504] The Exorcist is not an anime, skipping
2016-12-09 19:22:33 INFO     SEARCHQUEUE-FORCED-311816 :: [Usenet-Crawler] :: [c5c1504] Performing episode search for The Exorcist
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Usenet-Crawler] :: [c5c1504] Search mode: Episode
2016-12-09 19:22:33 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Usenet-Crawler] :: [c5c1504] Search show using search string: The Exorcist S01E09
2016-12-09 19:22:36 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Usenet-Crawler] :: [c5c1504] GET URL: https://www.usenet-crawler.com/api?apikey=**********&maxage=3000&cat=5000%2C5070%2C5040%2C5050%2C5030&q=The+Exorcist+S01E09&limit=100&t=search&offset=0 [Status: 200]
2016-12-09 19:22:36 INFO     SEARCHQUEUE-FORCED-311816 :: [Hydra] :: [c5c1504] Performing episode search for The Exorcist
2016-12-09 19:22:36 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Hydra] :: [c5c1504] Search mode: Episode
2016-12-09 19:22:36 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Hydra] :: [c5c1504] Search show using search string: The Exorcist S01E09
2016-12-09 19:22:40 DEBUG    SEARCHQUEUE-FORCED-311816 :: [Hydra] :: [c5c1504] GET URL: http://192.168.1.249:5075/api?apikey=**********&maxage=3000&cat=5000%2C5030%2C5040%2C5050%2C5070&q=The+Exorcist+S01E09&limit=100&t=search&offset=0 [Status: 200]
2016-12-09 19:22:40 ERROR    SEARCHQUEUE-FORCED-311816 :: [Hydra] :: [c5c1504] Failed parsing provider. Traceback: 'Traceback (most recent call last):\n  File "/app/sickrage/medusa/providers/nzb/newznab.py", line 196, in search\n    pubdate = parser.parse(pubdate_raw, fuzzy=True) if pubdate_raw else None\n  File "/app/sickrage/lib/dateutil/parser.py", line 1168, in parse\n    return DEFAULTPARSER.parse(timestr, **kwargs)\n  File "/app/sickrage/lib/dateutil/parser.py", line 562, in parse\n    raise ValueError("String does not contain a date.")\nValueError: String does not contain a date.\n'
Traceback (most recent call last):
  File "/app/sickrage/medusa/providers/nzb/newznab.py", line 196, in search
    pubdate = parser.parse(pubdate_raw, fuzzy=True) if pubdate_raw else None
  File "/app/sickrage/lib/dateutil/parser.py", line 1168, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/app/sickrage/lib/dateutil/parser.py", line 562, in parse
    raise ValueError("String does not contain a date.")
ValueError: String does not contain a date.
2016-12-09 19:22:40 ERROR    SEARCHQUEUE-FORCED-311816 :: [Hydra] :: [c5c1504] Failed parsing provider. Traceback: 'Traceback (most recent call last):\n  File "/app/sickrage/medusa/providers/nzb/newznab.py", line 196, in search\n    pubdate = parser.parse(pubdate_raw, fuzzy=True) if pubdate_raw else None\n  File "/app/sickrage/lib/dateutil/parser.py", line 1168, in parse\n    return DEFAULTPARSER.parse(timestr, **kwargs)\n  File "/app/sickrage/lib/dateutil/parser.py", line 562, in parse\n    raise ValueError("String does not contain a date.")\nValueError: String does not contain a date.\n'
Traceback (most recent call last):
  File "/app/sickrage/medusa/providers/nzb/newznab.py", line 196, in search
    pubdate = parser.parse(pubdate_raw, fuzzy=True) if pubdate_raw else None
  File "/app/sickrage/lib/dateutil/parser.py", line 1168, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
  File "/app/sickrage/lib/dateutil/parser.py", line 562, in parse
    raise ValueError("String does not contain a date.")
ValueError: String does not contain a date.

# Fixed code
def search(self, search_strings, age=0, ep_obj=None):
    """
    Searche indexer using the params in search_strings, either for latest releases, or a string/id search.

    Returns: list of results in dict form
    """
    results = []
    if not self._check_auth():
        return results

    # For providers that don't have caps, or for which the t=caps is not working.
    if not self.caps and all(
        provider not in self.url for provider in self.providers_without_caps
    ):
        self.get_newznab_categories(just_caps=True)
        if not self.caps:
            return results

    for mode in search_strings:
        self.torznab = False
        search_params = {
            "t": "search",
            "limit": 100,
            "offset": 0,
            "cat": self.cat_ids.strip(", ") or "5030,5040",
            "maxage": app.USENET_RETENTION,
        }

        if self.needs_auth and self.key:
            search_params["apikey"] = self.key

        if mode != "RSS":
            match_indexer = self._match_indexer()
            search_params["t"] = (
                "tvsearch" if match_indexer and not self.force_query else "search"
            )

            if search_params["t"] == "tvsearch":
                search_params.update(match_indexer)

                if ep_obj.show.air_by_date or ep_obj.show.sports:
                    date_str = str(ep_obj.airdate)
                    search_params["season"] = date_str.partition("-")[0]
                    search_params["ep"] = date_str.partition("-")[2].replace("-", "/")
                else:
                    search_params["season"] = ep_obj.scene_season
                    search_params["ep"] = ep_obj.scene_episode

            if mode == "Season":
                search_params.pop("ep", "")

        items = []
        logger.log("Search mode: {0}".format(mode), logger.DEBUG)

        for search_string in search_strings[mode]:
            if mode != "RSS":
                # If its a PROPER search, need to change param to 'search' so it searches using 'q' param
                if any(
                    proper_string in search_string
                    for proper_string in self.proper_strings
                ):
                    search_params["t"] = "search"

                logger.log(
                    "Search show using {search}".format(
                        search="search string: {search_string}".format(
                            search_string=search_string
                            if search_params["t"] != "tvsearch"
                            else "indexer_id: {indexer_id}".format(
                                indexer_id=match_indexer
                            )
                        )
                    ),
                    logger.DEBUG,
                )

                if search_params["t"] != "tvsearch":
                    search_params["q"] = search_string

            time.sleep(cpu_presets[app.CPU_PRESET])

            response = self.get_url(
                urljoin(self.url, "api"), params=search_params, returns="response"
            )
            if not response or not response.text:
                logger.log("No data returned from provider", logger.DEBUG)
                continue

            with BS4Parser(response.text, "html5lib") as html:
                if not self._check_auth_from_data(html):
                    return items

                try:
                    self.torznab = "xmlns:torznab" in html.rss.attrs
                except AttributeError:
                    self.torznab = False

                for item in html("item"):
                    try:
                        title = item.title.get_text(strip=True)
                        download_url = None
                        if item.link:
                            if validators.url(item.link.get_text(strip=True)):
                                download_url = item.link.get_text(strip=True)
                            elif validators.url(item.link.next.strip()):
                                download_url = item.link.next.strip()

                        if not download_url and item.enclosure:
                            if validators.url(item.enclosure.get("url", "").strip()):
                                download_url = item.enclosure.get("url", "").strip()

                        if not (title and download_url):
                            continue

                        seeders = leechers = -1
                        if "gingadaddy" in self.url:
                            size_regex = re.search(
                                r"\d*.?\d* [KMGT]B", str(item.description)
                            )
                            item_size = size_regex.group() if size_regex else -1
                        else:
                            item_size = (
                                item.size.get_text(strip=True) if item.size else -1
                            )
                            for attr in item("newznab:attr") + item("torznab:attr"):
                                item_size = (
                                    attr["value"]
                                    if attr["name"] == "size"
                                    else item_size
                                )
                                seeders = (
                                    try_int(attr["value"])
                                    if attr["name"] == "seeders"
                                    else seeders
                                )
                                peers = (
                                    try_int(attr["value"])
                                    if attr["name"] == "peers"
                                    else None
                                )
                                leechers = peers - seeders if peers else leechers

                        if not item_size or (
                            self.torznab and (seeders is -1 or leechers is -1)
                        ):
                            continue

                        size = convert_size(item_size) or -1
                        pubdate_raw = item.pubdate.get_text(strip=True)
                        try:
                            pubdate = (
                                parser.parse(pubdate_raw, fuzzy=True)
                                if pubdate_raw
                                else None
                            )
                        except ValueError:
                            pubdate = None

                        item = {
                            "title": title,
                            "link": download_url,
                            "size": size,
                            "seeders": seeders,
                            "leechers": leechers,
                            "pubdate": pubdate,
                            "torrent_hash": None,
                        }
                        if mode != "RSS":
                            if seeders == -1:
                                logger.log(
                                    "Found result: {0}".format(title), logger.DEBUG
                                )
                            else:
                                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,
                        )
                        continue

            # Since we arent using the search string,
            # break out of the search string loop
            if "tvdbid" in search_params:
                break

        results += items

    # Reproces but now use force_query = True
    if not results and not self.force_query:
        self.force_query = True
        return self.search(search_strings, ep_obj=ep_obj)

    return results