def find_propers(self, search_date=None):
        results = []
        db = DBConnection()
        placeholder = ','.join([
            str(x) for x in Quality.DOWNLOADED + Quality.SNATCHED +
            Quality.SNATCHED_BEST
        ])
        sql_results = db.select(
            'SELECT s.show_name, s.lang, e.showid, e.season, e.episode, e.status, e.airdate'
            ' FROM tv_episodes AS e'
            ' INNER JOIN tv_shows AS s ON (e.showid = s.indexer_id)'
            ' WHERE e.airdate >= ' + str(search_date.toordinal()) +
            ' AND e.status IN (' + placeholder + ')')

        for result in sql_results or []:
            show = Show.find(sickbeard.showList, int(result['showid']))

            if show:
                episode = show.getEpisode(result['season'], result['episode'])

                for term in self.proper_strings:
                    search_strings = self._get_episode_search_strings(
                        episode, add_string=term)

                    for item in self.search(search_strings[0]):
                        title, url = self._get_title_and_url(item)

                        results.append(
                            Proper(title, url, datetime.today(), show))

        return results
Exemple #2
0
    def _check_for_propers(needed):
        if not sickbeard.DOWNLOAD_PROPERS:
            return

        propers = {}
        my_db = db.DBConnection('cache.db')
        sql_results = my_db.select('SELECT * FROM provider_cache')
        re_p = r'\brepack|proper|real%s\b' % ('', '|v[2-9]')[needed.need_anime]

        proper_regex = re.compile(re_p, flags=re.I)

        for s in sql_results:
            if proper_regex.search(s['name']):
                try:
                    show = helpers.find_show_by_id(
                        sickbeard.showList,
                        {INDEXER_TVDB: int(s['indexerid'])})
                except (StandardError, Exception):
                    continue
                if show:
                    propers.setdefault(s['provider'], []).append(
                        Proper(s['name'],
                               s['url'],
                               datetime.datetime.fromtimestamp(s['time']),
                               show,
                               parsed_show=show))

        if propers:
            logger.log(
                'Found Proper/Repack/Real in recent search, sending data to properfinder'
            )
            propersearch_queue_item = sickbeard.search_queue.ProperSearchQueueItem(
                propers=propers)
            sickbeard.searchQueueScheduler.action.add_item(
                propersearch_queue_item)
Exemple #3
0
    def find_propers(self, search_date=None):
        results = self.cache.list_propers(search_date)

        return [
            Proper(x[b'name'], x[b'url'], datetime.fromtimestamp(x[b'time']),
                   self.show) for x in results
        ]