def show_movies(self, movies: MoviesList): print('Movies List: ') for ind, movie in enumerate(movies): print('{0}{1}: {2} ({3}){4}'.format(Color.PURPLE, ind + 1, movie.name, movie.year, Color.END)) while True: mid = int( input(Color.get_bold_string(Constants.movie_download_text))) if mid > len(movies) or mid < 1: Print.wrong_option() continue else: break movie_selected = movies[mid - 1] Print.bold_string(Constants.available_torrents_text) available_torrents = self.get_available_torrents( movie_selected.torrents) if len(available_torrents.values()) == 0: print('{0}{1}{2}'.format(Color.RED, Constants.no_torrent_text, Color.END)) else: ati = 1 for torrent_format in list(available_torrents): print('{0}{1}: {2}{3}'.format(Color.YELLOW, ati, torrent_format, Color.END)) ati += 1 if len(available_torrents) == 1: op = input( 'Press 1 to Download, Press any other key to exit\n') if op == '1': torrent_link = list(available_torrents.values())[0] Print.bold_string('{0}{1}{2}{3}'.format( Constants.click_link_text, Color.RED, torrent_link, Color.END)) else: Print.bold_string(Constants.movie_quality_text) qu = int(input()) torrent_link = list(available_torrents.values())[qu - 1] Helper.open_magnet_link(torrent_link) Print.bold_string('{0}{1}{2}{3}'.format( Constants.click_link_text, Color.RED, torrent_link, Color.END)) Print.long_hash() if movie_selected.subtitle_url and movie_selected.subtitle_url != '': Print.bold_string(Constants.selection_text['subtitle']) download_subtitle = Helper.ask_for_options() if download_subtitle: subtitle = Subtitle() subtitle.search_subtitle(movie_selected.subtitle_url) Print.long_hash() print( Constants.another_movies_text.format( Color.RED, Color.get_bold_string(self.search_query.search_term))) reshow_movies = input(Color.get_yes_no()) if reshow_movies == 'y' or reshow_movies == 'Y': self.show_movies(movies)
def ask_for_options() -> bool: while True: want = input(Color.get_yes_no()) if want in ['y', 'Y']: return True if want in ['n', 'N']: return False Print.wrong_option() continue
def take_int_input(no_of_options) -> int: index = None while True: try: index = int( input(Color.get_bold_string(Constants.choose_option_text))) if 1 <= index <= no_of_options: break else: Print.wrong_option() continue except ValueError: Print.wrong_option() continue return index
def take_input(input_type, options): if input_type not in Constants.input_types: Print.bold_string('Wrong input type: {0}'.format(input_type)) exit(1) specific_text = Constants.specific_text[input_type] no_of_options = len(options) Print.bold_string(specific_text) for i in range(1, len(options)): Print.option(i, options[i]) while True: index = int(input()) if 1 <= index <= no_of_options: break else: Print.wrong_option() continue return options[index - 1]