コード例 #1
0
 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
コード例 #2
0
 def download_srt(url):
     """Downloads and extracts .srt file from zip url"""
     my_zip = Helper.__get_zip_file(url)
     storage_path = Helper.__get_downloads_folder()
     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
コード例 #3
0
    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')
コード例 #4
0
 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
コード例 #5
0
 def take_optional_input(input_type):
     Print.long_hash()
     if input_type not in Constants.input_types:
         Print.bold_string('Wrong input type: {0}'.format(input_type))
         exit(1)
     selection_text = Constants.selection_text[input_type]
     specific_final_option = Constants.specific_final_option[input_type]
     special_final_option = Constants.special_final_option[input_type]
     Print.bold_string(selection_text)
     want = Helper.ask_for_options()
     options = Constants.options[input_type]
     if not want:
         Print.colored_note(special_final_option)
         return options[0]
     final_option = Helper.take_input(input_type, options)
     Print.colored_note(specific_final_option.format(final_option))
     return final_option
コード例 #6
0
    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')
コード例 #7
0
 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]
コード例 #8
0
 def take_input(input_type, options) -> int:
     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])
     index = Helper.take_int_input(no_of_options)
     return options[index]
コード例 #9
0
    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)
コード例 #10
0
def sigint_handler(signum, frame):
    Print.thanks()
    exit(1)