diff --git a/FFMpeg-Compressor/modules/utils.py b/FFMpeg-Compressor/modules/utils.py index a7c82e7..0c4f43b 100644 --- a/FFMpeg-Compressor/modules/utils.py +++ b/FFMpeg-Compressor/modules/utils.py @@ -1,19 +1,23 @@ from modules import printer +import glob import os -def get_dir_size(start_path): +def get_dir_size(directory, files): total_size = 0 - for dirpath, dirnames, filenames in os.walk(start_path): - for f in filenames: - fp = os.path.join(dirpath, f) - if not os.path.islink(fp): - total_size += os.path.getsize(fp) + for f in files: + fp = glob.glob(f'{directory}/{f}*')[0] + if not os.path.islink(fp): + total_size += os.path.getsize(fp) return total_size def get_compression(orig, comp): - comp = 100 - int((get_dir_size(comp) / get_dir_size(orig)) * 100) + processed_files = [] + for file in os.listdir(comp): + processed_files.append(os.path.splitext(file)[0]) + + comp = 100 - int((get_dir_size(comp, processed_files) / get_dir_size(orig, processed_files)) * 100) if comp < 0: printer.warning(f'Compression: {comp}%') printer.warning("The resulting files are larger than the original ones!")