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)
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)
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)
def show_format_menu(indexes): """ print a text menu with audio format references currently supported. """ menu = text_menu() setmenu = [menu[i] for i in range(len(menu)) if i not in set(indexes)] for outformat in setmenu: # realizzazione menu di output msgcustom(f"{outformat}")
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
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
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
def whichcraft(arg=None): """ Without *arg* checks for binaries in *listing* and print result. Otherwise accepts one argument and returns result of *which*: `None` if not exist or its executable path-name. """ if not arg: listing = ['ffmpeg', 'flac', 'lame', 'oggdec', 'oggenc', 'shntool', 'mac'] # listing = ['sox', 'wavpack'] # this are for futures implementations for required in listing: # if which(required): if which(required, mode=os.F_OK | os.X_OK, path=None): msgcustom(f"Check for: '{required}' ..Ok") else: msgcustom(f"Check for: '{required}' ..Not Installed") return None return which(str(arg), mode=os.F_OK | os.X_OK, path=None)