45 lines
1.0 KiB
Python
Executable File
45 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3.9
|
|
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
from ffmpeg import ffprobe
|
|
import logging
|
|
|
|
|
|
def get_resolution(video_path: Path) -> str:
|
|
try:
|
|
info = ffprobe(video_path)
|
|
except subprocess.CalledProcessError:
|
|
return None
|
|
|
|
if 700 <= info.height <= 800:
|
|
return "720p"
|
|
elif 1000 <= info.height <= 1200:
|
|
return "1080p"
|
|
elif info.height > 2000:
|
|
return "4K"
|
|
return None
|
|
|
|
|
|
def main():
|
|
for it in sys.argv[1:]:
|
|
video_path = Path(it)
|
|
if not video_path.is_file():
|
|
continue
|
|
resolution = get_resolution(video_path)
|
|
if resolution is None:
|
|
logging.info("unknown resolution: %s", video_path)
|
|
continue
|
|
if resolution in video_path.stem:
|
|
continue
|
|
|
|
logging.info("%s: %s", video_path.stem, resolution)
|
|
new_path = video_path.with_stem(f"{video_path.stem} [{resolution}]")
|
|
video_path.rename(new_path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
logging.basicConfig(level=logging.INFO)
|
|
main()
|