FFMpeg-Compressor: Calculate compression only for processed files
This commit is contained in:
parent
13f40d14ce
commit
2ba51730a2
1 changed files with 11 additions and 7 deletions
|
@ -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!")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue