This Express TypeScript project implements a RESTful API to crop and download youtube videos based on specified time
Video Processing API
The API is built with modern TypeScript practices and includes OpenAPI (Swagger) documentation integration using @asteasolutions/zod-to-openapi for automatic API documentation generation.
Endpoint: GET /health-check
Purpose: Provides system health monitoring capabilities
- Returns a status check of the service
- Used for monitoring and ensuring the service is running properly
- Returns a standardized
ServiceResponsewith a "Service is healthy" message
Endpoint: POST /videos/process
Purpose: Processes YouTube videos with specific time segments
- Downloads YouTube videos using
youtube-dl-exec - Processes videos using
ffmpegwith the following capabilities:- Time segment extraction (using start and end times)
- High-quality video processing with H.264 codec
- Audio processing with AAC codec at 192k bitrate
- Maintains original video resolution
- Optimized compression using slow preset for better quality
{
youtubeUrl: string, // URL of the YouTube video --- (https://www.youtube.com/watch?v=GimCcrwYxdE)
startTime: string, // Start time in "MM:SS" format (e.g., "2:56")
endTime: string // End time in "MM:SS" format
}{
id: string, // Unique UUID for the processed video
originalUrl: string, // Original YouTube URL
processedUrl: string, // URL of the processed video
startTime: string, // Requested start time
endTime: string, // Requested end time
createdAt: Date // Processing timestamp
}The API follows a clean architecture pattern with the following components:
- Handle HTTP route definitions
- Integrate OpenAPI documentation
- Define request/response schemas using Zod
- Map routes to controllers
- Handle HTTP request/response logic
- Validate incoming requests
- Delegate business logic to services
- Implement core business logic
- Handle video processing operations
- Manage error handling and response formatting
- Define data structures and types
- Implement validation schemas using Zod
- Ensure type safety throughout the application
- Handle data persistence
- Manage file uploads and storage
- Interface with external storage services
The API implements robust error handling with:
- Standardized
ServiceResponseformat for all responses - HTTP status code mapping
- Detailed error messages for debugging
- Logging integration for error tracking
- Rate limiting middleware
- Request logging for audit trails
- Input validation using Zod schemas
- Secure file handling with temporary storage cleanup
- OpenAPI (Swagger) integration
- Automatic API documentation generation
- Type-safe request/response schemas
- Clear endpoint descriptions and tags
- Express.js with TypeScript
- Zod for validation
- FFmpeg for video processing
- youtube-dl for video downloading
- OpenAPI for API documentation
- Custom middleware for logging and error handling
This API is designed to be scalable, maintainable, and follows best practices for TypeScript/Express applications with a focus on type safety and proper error handling.
If you want to implement a more secure approach when connecting to your local server, you can implement and extend the current functionality to accept an Authorization header, include your API key, and implement API key validation in a suitable middleware.