109 lines
3.7 KiB
Python
109 lines
3.7 KiB
Python
import argparse
|
|
import os
|
|
import sys
|
|
|
|
# Assuming these modules will be created and populated later
|
|
import converter
|
|
import utils
|
|
import config
|
|
import downloader # Import downloader module
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Convert video files to DaVinci Resolve compatible formats."
|
|
)
|
|
parser.add_argument(
|
|
"input_file",
|
|
nargs='?',
|
|
help="Path to the input video file.",
|
|
type=str
|
|
)
|
|
parser.add_argument(
|
|
"-u", "--url",
|
|
help="URL of the video to download and convert.",
|
|
type=str,
|
|
default=None
|
|
)
|
|
parser.add_argument(
|
|
"-o", "--output_dir",
|
|
help="Optional: Directory to save the converted file. Defaults to the input file's directory.",
|
|
type=str,
|
|
default=None
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
input_source = None
|
|
if args.url:
|
|
print(f"Downloading video from URL: {args.url}")
|
|
downloaded_file = downloader.download_video(args.url)
|
|
if not downloaded_file:
|
|
print("Error: Video download failed.", file=sys.stderr)
|
|
sys.exit(1)
|
|
input_source = downloaded_file
|
|
# If output_dir is not specified, use the directory of the downloaded file
|
|
if not args.output_dir:
|
|
args.output_dir = os.path.dirname(downloaded_file)
|
|
elif args.input_file:
|
|
input_source = args.input_file
|
|
|
|
while not input_source:
|
|
user_input = input("Please enter the path to the input video file or a URL: ").strip()
|
|
if not user_input:
|
|
print("Input cannot be empty. Please try again.", file=sys.stderr)
|
|
continue
|
|
|
|
if user_input.startswith("http://") or user_input.startswith("https://"):
|
|
print(f"Downloading video from URL: {user_input}")
|
|
downloaded_file = downloader.download_video(user_input)
|
|
if not downloaded_file:
|
|
print("Error: Video download failed.", file=sys.stderr)
|
|
sys.exit(1)
|
|
input_source = downloaded_file
|
|
if not args.output_dir:
|
|
args.output_dir = os.path.dirname(downloaded_file)
|
|
else:
|
|
input_source = user_input
|
|
|
|
input_file_path = os.path.abspath(input_source)
|
|
|
|
if not os.path.exists(input_file_path):
|
|
print(f"Error: Input file not found at '{input_file_path}'", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if not os.path.isfile(input_file_path):
|
|
print(f"Error: '{input_file_path}' is not a file.", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if not os.access(input_file_path, os.R_OK):
|
|
print(f"Error: No read permission for input file '{input_file_path}'.", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
output_dir = args.output_dir
|
|
if output_dir:
|
|
output_dir = os.path.abspath(output_dir)
|
|
if not os.path.isdir(output_dir):
|
|
print(f"Error: Output directory '{output_dir}' does not exist or is not a directory.", file=sys.stderr)
|
|
sys.exit(1)
|
|
if not os.access(output_dir, os.W_OK):
|
|
print(f"Error: No write permission for output directory '{output_dir}'.", file=sys.stderr)
|
|
sys.exit(1)
|
|
else:
|
|
output_dir = os.path.dirname(input_file_path)
|
|
if not os.access(output_dir, os.W_OK):
|
|
print(f"Error: No write permission for input file's directory '{output_dir}'.", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
# Perform conversion
|
|
print(f"Starting conversion for {input_file_path}...")
|
|
success = converter.convert_video(input_file_path, output_dir)
|
|
|
|
if success:
|
|
print("Conversion completed successfully.")
|
|
else:
|
|
print("Conversion failed.", file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|