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 download_srt(url): """Downloads and extracts .srt file from zip url""" my_zip = get_zip_file(url) storage_path = get_downloads_folder() Color.print_bold_string( Constants.download_zip_text.format(Color.RED, storage_path, url)) for file in my_zip.namelist(): if my_zip.getinfo(file).filename.endswith('.srt'): my_zip.extract( file, storage_path ) # extract the file to current folder if it is a text file
def create_query() -> SearchQuery: Print.long_hash() s = input(Color.get_bold_string(Constants.search_string_text)) while not s: s = input(Color.get_bold_string(Constants.search_string_text)) q = 'all' g = Helper.take_optional_input('genre') o = Helper.take_optional_input('order') return SearchQuery(s, q, g, 0, o, 0, 'all')
def take_order_input(): print_long_hash() Color.print_bold_string(Constants.order_selection_text) order_options = Constants.order_by while True: want_order = input(get_yes_no()) if want_order not in ['y', 'Y', 'n', 'N']: print_wrong_option() continue else: break o = 0 if want_order == 'y' or want_order == 'Y': Color.print_bold_string(Constants.specific_order_text) for i in range(1, len(order_options)): print('{0}{1}: {2}{3}'.format(Color.YELLOW, i, order_options[i], Color.END)) while True: o = int(input()) if o > 6 or o < 1: print_wrong_option() continue else: break Color.print_colored_note( Constants.specific_order_note.format(order_options[0])) else: Color.print_colored_note(Constants.imdb_order_note) return order_options[o]
def take_genre_input(): print_long_hash() Color.print_bold_string(Constants.genre_selection_text) genre_options = Constants.genre while True: want_genre = input(get_yes_no()) if want_genre not in ['y', 'Y', 'n', 'N']: print_wrong_option() continue else: break g = 0 if want_genre == 'y' or want_genre == 'Y': Color.print_bold_string(Constants.specific_genre_text) for i in range(1, len(genre_options)): print('{0}{1}: {2}{3}'.format(Color.YELLOW, i, genre_options[i], Color.END)) while True: g = int(input()) if 1 <= g <= 27: break else: print_wrong_option() continue Color.print_colored_note( Constants.specific_genre_note.format(genre_options[g])) else: Color.print_colored_note(Constants.all_genre_note) return genre_options[g]
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 start(self, search_query: SearchQuery): url = search_query.get_url() crawler = Crawler(api_flag=self.api_flag) movies = crawler.crawl_list(url) if self.api_flag is True: return movies self.show_movies(movies) print(Constants.restart_search_text) restart_search = input('{0}\n'.format(Color.get_colored_yes())) if restart_search == 'y' or restart_search == 'Y': main() else: print('{0}{1}{2}'.format(Color.BLUE, Constants.thanks_text, Color.END))
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 start(self, search_query: SearchQuery): url = Constants.search_url.format(search_query.search_term, search_query.quality, search_query.genre, search_query.rating, search_query.order_by) crawler = Crawler() movies = crawler.crawl_list(url) self.show_movies(movies) print(Constants.restart_search_text) restart_search = input('{0}\n'.format(Color.get_colored_yes())) if restart_search == 'y' or restart_search == 'Y': main() else: print('{0}{1}{2}'.format(Color.BLUE, Constants.thanks_text, Color.END))
def create_query() -> SearchQuery: Print.long_hash() s = input(Color.get_bold_string(Constants.search_string_text)) q = 'all' """ print('Please enter any specific quality of your torrent: ') quality_options = Constants.quality for i in range(len(quality_options)): print('{0}: {1}'.format(i, quality_options[i])) q = int(input()) while q > 4 or q < 0: print('Wrong option, Try again') q = quality_options[q] """ g = Helper.take_optional_input('genre') o = Helper.take_optional_input('order') return SearchQuery(s, q, g, 0, o, 0, 'all')
def get_yes_no(): return '{0}\n{1}\n'.format(Color.get_colored_yes(), Color.get_colored_no())
def bold_string(string): print(Color.get_bold_string(string))