Esempio n. 1
0
    def prompt_to_output_format(self):
        """
        Prompt to set codec and output audio format.
        """
        for input_format, val in list(self.filecatalog.items()):
            msgcustom(f"\n\033[1mConvert the '\033[32;1m"
                      f"{input_format}\033[0m'format to:\033[0m")

            show_format_menu(val['index'])  # show text menu before prompt
            while True:
                output_select = input("Type a format number among those "
                                      "available, and press the Enter key > ")
                if output_select in ('a', 'A'):
                    msgend(abort=True)
                    sys.exit()
                codec = get_codec_data(input_format, output_select)

                if codec is None:
                    msgdebug(err=f"Invalid option '{output_select}'")
                    continue
                break

            self.filecatalog[input_format]['codec'] = codec[0]
            self.filecatalog[input_format]['format'] = codec[4]

            self.prompt_to_bitrate(codec, input_format)
Esempio n. 2
0
    def prompt_to_output_format(self):
        """
        Prompt to get codec data and set the output audio format
        """
        msgcustom(f"\n\033[1mConvert the '\033[32;1m"
                  f"{self.input_format}\033[0m' format to:\033[0m")
        show_format_menu(self.index)  # show text menu before prompt

        while True:
            output_select = input("Type a format number among those "
                                  "available, and press the Enter key > ")
            if output_select in ('a', 'A'):
                msgend(abort=True)
                sys.exit()
            data_codec = get_codec_data(self.input_format, output_select)

            if data_codec is None:
                msgdebug(err=f"Invalid option '{output_select}'")
                continue
            break

        self.codec = data_codec[0]
        self.output_format = data_codec[4]

        self.prompt_to_bitrate(data_codec)
Esempio n. 3
0
    def prompt_to_bitrate(self, data_codec):
        """
        Prompt to set the audio bitrate
        """
        if data_codec[1] is not None:  # None bitrate
            msgcustom(data_codec[2])  # show menu

            while True:
                level = input(data_codec[3])  # show text menu before prompt
                if level in data_codec[1]:
                    self.bitrate = data_codec[1][level]
                else:
                    msgdebug(err=f"Invalid option '{level}'")
                    continue
                break
Esempio n. 4
0
    def __init__(self, path_i, path_o):
        """
        Print a text menu with a list of available formats
        and wait for user input. The input value given by the
        user represents the format of the files to be converted
        in a given folder .
        """
        # (too-many-instance-attributes) (FIXME)
        self.inputdir = path_i
        self.outputdir = path_o
        self.input_format = None
        self.output_format = None
        self.index = None
        self.codec = None
        self.bitrate = ''
        self.not_processed = []
        self.processed = []
        self.warnings = []
        self.info = []
        self.errors = []

        msgcustom("\n\033[1mWhat is the files format to convert?\033[0m")
        for inputformat in text_menu():
            msgcustom(f"{inputformat}")  # show menu

        while True:
            input_selection = input("Type a format number among those "
                                    "available, and press the Enter key > ")

            if input_selection in ('a', 'A'):
                msgend(abort=True)
                sys.exit()

            try:
                selection = int(input_selection)
            except ValueError:
                msgdebug(err=(f"Invalid option '{input_selection}'"))
                continue

            if supported_formats().get(selection):
                self.input_format = supported_formats().get(selection)[1]
                self.index = supported_formats().get(selection)[2]
            else:
                msgdebug(err=(f"Invalid option '{input_selection}'"))
                continue
            break
Esempio n. 5
0
def run_subprocess(command):
    """
    Run command using subprocess.run
    """
    interrupted = None
    # print(command) # uncomment for debug, and comment try clause
    try:
        subprocess.run(command, check=True, shell=True)

    except subprocess.CalledProcessError as error:
        sys.exit(msgdebug(err=error))

    except KeyboardInterrupt:
        interrupted = True

    if interrupted:
        sys.exit(msgdebug(head='\n\n', warn="KeyboardInterrupt !"))
Esempio n. 6
0
    def prompt_to_bitrate(self, codec, input_format):
        """
        Prompt to set the audio bitrate
        """
        if codec[1] is None:  # None bitrate
            bitrate = ''
        else:
            msgcustom(codec[2])  # show menu

            while True:
                level = input(codec[3])  # show text menu before prompt
                if level in codec[1]:
                    bitrate = codec[1][level]
                else:
                    msgdebug(err=f"Invalid option '{level}'")
                    continue
                break

        self.filecatalog[input_format]['bitrate'] = bitrate
Esempio n. 7
0
    def end_check(self):
        """
        Print debug messages at the end of the tasks
        """
        if self.info:
            for msg in self.info:
                msgdebug(info=msg)

        if self.warnings:
            for msg in self.warnings:
                msgdebug(warn=msg)

        if self.errors:
            for msg in self.errors:
                msgdebug(err=msg)

        if self.not_processed:
            msgcolor(orange="\nInput files NOT converted:")
            for list1 in self.not_processed:
                msgcustom(list1)

        if self.processed:
            msgcolor(green="\nConverted successfully:")
            for list2 in self.processed:
                msgcustom(list2)

        msgend(done=True)