Beispiel #1
0
    def search(self,
               search_string,
               season=False,
               episode=False,
               search_type='torrent'):
        """
        Return an array of values:

        [
          [
            ['Title string', 'search url'],
            [head1, head2, head3, id],
            [head1-width, head2-width, head3-width],
            [head1-alignment, head2-alignment, head3-alignment]
          ],
          [
            [<column 1 data>, <column 2 data>, <column 3 data>, <id>],
            [<column 1 data>, <column 2 data>, <column 3 data>, <id>],
            # etc...
          ]
        ]
        """

        self.season = season
        self.episode = episode
        self.show_name = search_string
        self.search_type = search_type

        click.echo()

        if self.search_type == 'torrent':
            header = [[search_string, ''],
                      ['Name', 'Size', 'Date', 'Seeds', 'SE'],
                      [0, 10, 12, 6, 2], ['<', '>', '<', '>', '<']]
        else:
            header = [[search_string, ''], ['Name', 'Size', 'Date', 'SE'],
                      [0, 10, 12, 2], ['<', '>', '<', '<']]

        if self.search_type == 'torrent':
            engines = self.torrent_engines
        elif self.search_type == 'nzb':
            engines = self.newsgroup_engines
        else:
            raise ValueError('search_type can only be "torrent" or "nzb"')

        # socket.setdefaulttimeout(3.05)
        socket.setdefaulttimeout(1)
        episodes = []
        with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
            res = {
                executor.submit(self.job, engine, search_string, season,
                                episode): engine
                for engine in engines
            }
            with click.progressbar(
                    concurrent.futures.as_completed(res),
                    label=U.style('  %s' % search_string, bold=True),
                    empty_char=style(Config.pb.empty_char,
                                     fg=Config.pb.dark,
                                     bg=Config.pb.dark),
                    fill_char=style(Config.pb.fill_char,
                                    fg=Config.pb.light,
                                    bg=Config.pb.light),
                    length=len(engines),
                    show_percent=False,
                    show_eta=False,
                    item_show_func=self.progress_title,
                    width=Config.pb.width,
                    bar_template=Config.pb.template,
                    show_pos=True,
            ) as bar:
                for future in bar:
                    results = future.result()
                    # remove the search engine name from the end of
                    # the results array that was added in self.job()
                    # so progress_title() could make use of it.
                    results = results[:-1]
                    episodes = episodes + results

        # go up 3 lines to remove the progress bar
        click.echo('[%sA' % 3)

        if self.search_type == 'torrent':
            self.sort_torrents(episodes)

        # return search_results
        return [header] + [episodes]
Beispiel #2
0
def style(text, fg=None, bg=None, bold=None, strike=None, ul=None):
    if Config.is_win:
        fancy = click.style(text, fg=fg, bg=bg, bold=bold, underline=ul)
    else:
        fancy = U.style(text, fg=fg, bg=bg, bold=bold, strike=strike, ul=ul)
    return fancy
Beispiel #3
0
def style(text, fg=None, bg=None, bold=None, strike=None, ul=None):
    if Config.is_win:
        fancy = click.style(text, fg=fg, bg=bg, bold=bold, underline=ul)
    else:
        fancy = U.style(text, fg=fg, bg=bg, bold=bold, strike=strike, ul=ul)
    return fancy