minimum viable product
This commit is contained in:
parent
85c2aa9722
commit
5aa710156c
|
@ -3,7 +3,7 @@
|
|||
|
||||
""" Author: Hendrik Schutter, localhorst@mosad.xyz
|
||||
Date of creation: 2022/02/13
|
||||
Date of last modification: 2022/01/13
|
||||
Date of last modification: 2022/01/25
|
||||
"""
|
||||
|
||||
import os
|
||||
|
@ -22,15 +22,19 @@ def get_length(filename):
|
|||
"format=duration", "-of",
|
||||
"default=noprint_wrappers=1:nokey=1", filename],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
return float(result.stdout)
|
||||
stderr=subprocess.DEVNULL)
|
||||
try:
|
||||
length = float(result.stdout)
|
||||
except ValueError:
|
||||
length = 0.0
|
||||
return length
|
||||
|
||||
def get_codec(filename):
|
||||
result = subprocess.run(["ffprobe", "-v", "error", "-select_streams", "v:0",
|
||||
"-show_entries", "stream=codec_name",
|
||||
"-of", "default=noprint_wrappers=1:nokey=1", filename],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
stderr=subprocess.DEVNULL)
|
||||
return str(result.stdout.decode("utf-8")).rstrip("\n")
|
||||
|
||||
def get_resolution(filename):
|
||||
|
@ -38,8 +42,12 @@ def get_resolution(filename):
|
|||
"-show_entries", "stream=width,height",
|
||||
"-of", "default=noprint_wrappers=1:nokey=1", filename],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
return str(result.stdout.decode("utf-8")).rstrip("\n").replace("\n", "x")
|
||||
stderr=subprocess.DEVNULL)
|
||||
try:
|
||||
resolution = str(result.stdout.decode("utf-8")).rstrip("\n").replace("\n", "x")
|
||||
except ValueError:
|
||||
resolution = "NaN"
|
||||
return resolution
|
||||
|
||||
def human_readable_size(size, decimal_places=2):
|
||||
for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:
|
||||
|
@ -48,15 +56,22 @@ def human_readable_size(size, decimal_places=2):
|
|||
size /= 1024.0
|
||||
return f"{size:.{decimal_places}f} {unit}"
|
||||
|
||||
def cut_file_name(filename, max_lenght, ellipsis="..."):
|
||||
if len(filename) > max_lenght:
|
||||
return filename[:max_lenght-len(ellipsis)] + ellipsis
|
||||
else:
|
||||
return filename
|
||||
|
||||
def main() -> None:
|
||||
if(len(sys.argv) != 2):
|
||||
path = '.'
|
||||
else:
|
||||
path = sys.argv[1]
|
||||
|
||||
files = filter(supported_file_extension, os.listdir(path))
|
||||
for file in files:
|
||||
print ("{:<35} {:<10} {:<5} {:<5} {:<5}".format( file, str(datetime.timedelta(seconds=get_length(file))), human_readable_size(os.path.getsize(file)), get_codec(file), get_resolution(file)))
|
||||
|
||||
for root, dirs, files in os.walk(path, topdown=False):
|
||||
for name in filter(supported_file_extension, files):
|
||||
full_path = os.path.join(root, name)
|
||||
print ("{:<64} | {:<8} | {:<16} | {:<8} | {:<8}".format(cut_file_name(name, 64), str(datetime.timedelta(seconds=get_length(full_path))).split(".")[0], human_readable_size(os.path.getsize(full_path)), get_codec(full_path), get_resolution(full_path)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue