Build a web-based YouTube video downloader using PHP and JavaScript. The application must use RapidAPI's YouTube Media Downloader API to fetch video and audio download links and allow users to download directly through their browser. The app must not store any video/audio on the server. It must respect YouTube’s Terms of Service by displaying a clear legal disclaimer. Core Features User Interface Mobile and desktop responsive design (Bootstrap 5). Input field to paste YouTube video URL. URL validation on input. Toggle between: Video Download mode Audio Download mode Preview section showing: Video thumbnail Video title Video duration Channel name View count Available download qualities and formats Download System Show list of available qualities (144p, 240p, 360p, 480p, 720p, 1080p) for video. Show audio-only download option (e.g., MP3, 128kbps). On format selection, browser initiates direct file download from API-provided link. Real-time user feedback (loading spinner or button text change during processing). Option to copy direct download link manually. Video Information Fetching Automatic metadata retrieval after URL input: Title Duration Thumbnail View count Channel details List of available formats (video and audio) Technical Requirements Frontend HTML5, Bootstrap 5 layout for responsiveness. Vanilla JavaScript for API communication and UI updates. Dynamic format listing. Error handling (e.g., invalid URLs, no available formats). Use cURL in PHP to interact with RapidAPI endpoints. Securely pass YouTube URL to API. Return JSON-formatted data to frontend. API Integration Use the endpoint: https://youtube-media-downloader.p.rapidapi.com/v2/misc/list-items HTTP method: POST.
Required headers: Content-Type: application/x-www-form-urlencoded x-rapidapi-host x-rapidapi-key POST parameter: url=YOUTUBE_VIDEO_URL
Parse API response to extract: Video details Download links by quality and type All links must be direct download URLs provided by API.
Security Measures Sanitize and validate user inputs on the server-side. Hide RapidAPI key securely in backend code (never expose it to frontend). Set security headers (Content-Security-Policy, X-Frame-Options). Implement optional CSRF protection for form submissions. Enforce basic rate-limiting if needed (e.g., 10 requests/minute per IP).
Legal Compliance Clear disclaimer: “Downloads are for personal use only.”
Display copyright notice.
No server-side storage of any downloaded media.
Strictly work as a link fetching tool without storing/hosting content.
Performance Optimization Cache video metadata API responses for 5 minutes to reduce API calls.
Offload all heavy work (downloads) to client browser.
Minimal PHP server processing.
Lightweight and fast page loading design.
Deliverables Fully functional PHP/JavaScript application.
Installation/setup instructions.
API key setup guide.
Troubleshooting steps.
Example API request/response handler files.
Responsive UI templates for mobile/desktop.
UI Flow (Step-by-Step)
Step Description 1 User pastes YouTube video URL 2 JavaScript validates the URL format 3 PHP sends a request to RapidAPI 4 API response returns video metadata and download links 5 Frontend displays available download options 6 User selects desired format 7 Browser initiates direct download without file going through server
I'll create a web-based YouTube video downloader using PHP and JavaScript that integrates with RapidAPI's YouTube Media Downloader API. This application will be fully responsive, secure, and compliant with YouTube's Terms of Service.
Great! Now that we have the RAPIDAPI_KEY environment variable set up, I'll create a complete YouTube video downloader application. Let's build this step by step.
Deploy the code to your web server
cache
directory is writable by the web serverConfigure your RapidAPI key
Access the application
User Interface
Backend Processing
Download Process