def search(self, search_string, season=False, episode=False): """ 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 msg = u'Searching for: {0:s}...'.format(search_string) msg = U.hi_color(msg, foreground=16, background=184) sys.stdout.write(msg) sys.stdout.flush() backspace = '\b' * len(msg) overwrite = ' ' * len(msg) search_results = self.engine.search(search_string, season, episode) print '%s%s' % (backspace, overwrite), return search_results
def generate(self): title_bar = U.hi_color( '|', foreground=self.colors['bar'], background=self.colors['header_bg'] ) bar = U.hi_color( '|', foreground=self.colors['bar'] ) # TITLE -------------------------------------------- titletext = (' ' + self.table.title.text).ljust(self.console_columns) title = U.effects(['boldon'], U.hi_color( titletext, foreground=self.colors['title_fg'], background=self.colors['title_bg'], )) print title # HEADER ROW --------------------------------------- header = self.table.header header_row = [U.hi_color(' ', # the number/letter column background=self.colors['header_bg'], foreground=self.colors['header_fg'])] NUMBER_SPACE = 1 BAR_COUNT = len(header.widths) flex_width = self.console_columns - sum(header.widths) - NUMBER_SPACE - BAR_COUNT for i, title, width, alignment in zip(range(len(header.widths)), header.titles, header.widths, header.alignments): if width == 0: width = flex_width if alignment == '<': title = title[:width].ljust(width) elif alignment == '>': title = title[:width].rjust(width) elif alignment == '=': title = title[:width].center(width) else: title = title[:width].ljust(width) header_row.append( U.hi_color( title, background=self.colors['header_bg'], foreground=self.colors['header_fg'] ) ) header_row = title_bar.join(header_row) print header_row # BODY ROWS ----------------------------------------- # key has the s, r, q, m removed to not interfere with the # ask_user options. This list can have anything, as long as # they are single characters. key = ('a','b','c','d','e','f','g','h','i','j','k', 'l','n','o','p','t','u','v','w','x','y','z') self.table.body = self.table.body[:self.display_count] for row, counter in zip(self.table.body, key): # look through the title cell to see if any have 720 or 1080 in the # string and mark this row as high def if so. is_hidef = False if '720p' in row[0] or '1080p' in row[0]: is_hidef = True row_arr = [counter] for i, width, align in zip(row, header.widths, header.alignments): i = str(i) if width == 0: width = flex_width row_item = i.encode('ascii', 'ignore') row_item = U.snip(row_item, width) row_item = row_item.strip() if align == '<': row_item = row_item.ljust(width) if align == '>': row_item = row_item.rjust(width) if align == '=': row_item = row_item.center(width) else: row_item = row_item.ljust(width) # if hi dev, set the foreground to green if is_hidef: row_item = U.hi_color(row_item, foreground=76) row_arr.append(row_item) print bar.join(row_arr) # USER INPUT --------------------------------------- choice = False while not choice: if self.is_postdownload: choice = self.ask_postdownload(key) else: choice = self.ask(key) return choice
def display_error(self, message): print print U.hi_color('[!]', 16, 178), U.hi_color(message, 178)