2026-04-22 21:01:43 -04:00

63 lines
2.3 KiB
Python

"""CLI interface for audio extraction operations"""
from pathlib import Path
from audio_extractor.extractor import AudioExtractor
class AudioExtractorCLI:
"""Command-line interface for audio extraction"""
def __init__(self):
self.extractor = AudioExtractor()
def extract_audio(self, target: str, output: str) -> None:
"""
Extract audio from video file(s).
Args:
target: Path to video file or folder containing video files
output: Output folder path for extracted audio files
"""
target_path = Path(target)
output_path = Path(output)
if not target_path.exists():
raise FileNotFoundError(f"Target not found: {target}")
# Create output directory if it doesn't exist
output_path.mkdir(parents=True, exist_ok=True)
if target_path.is_file():
# Single file
print(f"Extracting audio from: {target_path}")
self.extractor.extract_audio_from_file(target_path, output_path)
elif target_path.is_dir():
# Directory - process all video files
video_files = self.extractor.find_video_files(target_path)
if not video_files:
print(f"No video files found in: {target_path}")
return
print(f"Found {len(video_files)} video file(s)")
for i, video_file in enumerate(video_files, 1):
print(f"[{i}/{len(video_files)}] Extracting audio from: {video_file.name}")
try:
self.extractor.extract_audio_from_file(video_file, output_path)
except Exception as e:
print(f" Error processing {video_file.name}: {e}")
else:
raise ValueError(f"Invalid target: {target}")
def add_audio_tracks(self, target: str, input_folder: str, output: str, title: str = None) -> None:
"""
Add audio tracks to video files (future feature).
Args:
target: Path to folder containing audio files
input_folder: Path to folder containing video files
output: Output folder for processed video files
title: Title/name for the added audio tracks
"""
print("Feature not yet implemented")
# TODO: Implement add_audio_tracks functionality