add a more natural sort to transcode presets list

This commit is contained in:
ChaotiCryptidz 2022-02-06 16:35:39 +00:00
parent 791213481f
commit a6d01f092f
2 changed files with 37 additions and 13 deletions

View file

@ -126,7 +126,11 @@ class CopyCommand():
exists = path_exists(dest)
if (self.args.skip_existing and not exists) or not self.args.skip_existing:
should_skip = False
if self.args.skip_existing and exists:
should_skip = True
if should_skip:
print("Copying", src, "to", dest)
copy_file(
src,
@ -150,12 +154,19 @@ class CopyCommand():
new_file = deep_copy(file)
new_file.extension = trans_config.file_extension
dest_filepath = new_file.join_filename(
) if self.args.single_directory else new_file.join_path_from_src()
dest_filepath = ""
if self.args.single_directory:
dest_filepath = new_file.join_filename()
else:
dest_filepath = new_file.join_path_from_src()
dest_filepath = self.args.dest + "/" + dest_filepath
if (self.args.skip_existing and path_exists(
dest_filepath)):
should_skip_transcode = self.args.skip_existing and path_exists(
dest_filepath)
if should_skip_transcode:
print("Skipping transcoding", dest_filepath)
self.state.transcoded_files.append(new_file)
return
@ -170,6 +181,8 @@ class CopyCommand():
print("Transcoding Files")
if not self.args.single_directory:
# set can't contain duplicates
# so it only creates a dir once
directories = set()
for file in self.state.files:
directories.add(file.path_from_src)
@ -195,8 +208,6 @@ class CopyCommand():
trans_config = get_transcode_config(
self.args.transcode_preset)
print(trans_config)
for file in self.state.files:
self._transcode_with_config(
file, trans_config)

View file

@ -1,5 +1,18 @@
from functools import reduce
import re
def atoi(text) -> int or str:
try:
ret = int(text)
return ret
except:
return text
def natural_keys(text: str):
return [ atoi(c) for c in re.split(r'(-?\d+)', text) ]
def sort_natural(list: list[str]):
list.sort(key=natural_keys)
def add_to_arr(
arr: list[str],
@ -75,7 +88,7 @@ mp3_presets = {
}
preset_transcode_presets = preset_transcode_presets | mp3_presets
add_to_arr(transcode_presets["opus"], mp3_presets.keys())
add_to_arr(transcode_presets["mp3"], mp3_presets.keys())
opus_presets = {
"opus-low": "opus-32k",
@ -88,11 +101,11 @@ opus_presets = {
preset_transcode_presets = preset_transcode_presets | opus_presets
add_to_arr(transcode_presets["opus"], opus_presets.keys())
transcode_presets["mp3"].sort()
transcode_presets["opus"].sort()
transcode_presets["vorbis"].sort()
transcode_presets["speex"].sort()
transcode_presets["g726"].sort()
sort_natural(transcode_presets["mp3"])
sort_natural(transcode_presets["opus"])
sort_natural(transcode_presets["vorbis"])
sort_natural(transcode_presets["speex"])
sort_natural(transcode_presets["g726"])
def print_transcode_presets():