1
0

now with auto-naming output

This commit is contained in:
2025-03-19 19:40:50 +01:00
parent 06c2fb63af
commit 990a385481
+12 -2
View File
@@ -1,7 +1,14 @@
#! /usr/bin/python #! /usr/bin/python
"""Call ffmpeg with youtube-dl to convert files or youtube videos to mp4 or webp files.""" """Call ffmpeg with youtube-dl to convert files or youtube videos to mp4 or webp files."""
import subprocess, argparse import subprocess, argparse, re
def get_video_title(input_path: str) -> str:
if "https" in input_path:
title = subprocess.run(["yt-dlp", "--get-title", input_path], capture_output=True, encoding='utf-8')
return re.sub(r'[\W]+', '_', title.stdout.strip()) + ".mp4"
else:
return "vc"+input_path
def get_input_args(input_path: str) -> list[str]: def get_input_args(input_path: str) -> list[str]:
"""Generate ffmpeg input arguments for either local files or YouTube URLs.""" """Generate ffmpeg input arguments for either local files or YouTube URLs."""
@@ -76,7 +83,7 @@ def get_video_filter(crop_arg: str | None) -> str:
def main(): def main():
parser = argparse.ArgumentParser(description='Call ffmpeg for converting small video files to mp4 or webp') parser = argparse.ArgumentParser(description='Call ffmpeg for converting small video files to mp4 or webp')
parser.add_argument('input', help='input file or url') parser.add_argument('input', help='input file or url')
parser.add_argument('output', help='output filename') parser.add_argument('output', nargs='?', default="", help='output filename')
parser.add_argument('-s', '--start', help='start time, if not 00:00') parser.add_argument('-s', '--start', help='start time, if not 00:00')
parser.add_argument('-t', '--to', help='end time, if not end of file') parser.add_argument('-t', '--to', help='end time, if not end of file')
parser.add_argument('-q', '--quality', help='quality of output, as a percentage') parser.add_argument('-q', '--quality', help='quality of output, as a percentage')
@@ -88,6 +95,9 @@ def main():
- Edge: "edge:left:right:top:bottom" or "edge:width:height" or single value for all""") - Edge: "edge:left:right:top:bottom" or "edge:width:height" or single value for all""")
args = parser.parse_args() args = parser.parse_args()
if not args.output:
args.output = get_video_title(args.input)
f_args = get_input_args(args.input) f_args = get_input_args(args.input)
f_args += ["-vf", get_video_filter(args.crop)] f_args += ["-vf", get_video_filter(args.crop)]