now with auto-naming output
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
#! /usr/bin/python
|
||||
"""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]:
|
||||
"""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():
|
||||
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('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('-t', '--to', help='end time, if not end of file')
|
||||
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""")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not args.output:
|
||||
args.output = get_video_title(args.input)
|
||||
|
||||
f_args = get_input_args(args.input)
|
||||
|
||||
f_args += ["-vf", get_video_filter(args.crop)]
|
||||
|
||||
Reference in New Issue
Block a user