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