import React, { useState, useEffect } from 'react';
import {
Youtube,
Music,
Download,
Link as LinkIcon,
Loader2,
AlertCircle,
CheckCircle2,
Play,
ShieldCheck
} from 'lucide-react';
const App = () => {
const [url, setUrl] = useState('');
const [status, setStatus] = useState('idle'); // idle, loading, success, error
const [errorMessage, setErrorMessage] = useState('');
const [result, setResult] = useState(null);
// Simple validation for YouTube URLs
const isValidYoutubeUrl = (url) => {
const regExp = /^(?:https?:\/\/)?(?:m\.|www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
return url.match(regExp);
};
const handleConvert = async () => {
if (!isValidYoutubeUrl(url)) {
setErrorMessage('Please enter a valid YouTube URL (e.g., https://www.youtube.com/watch?v=...)');
setStatus('error');
return;
}
setStatus('loading');
setErrorMessage('');
try {
// In a real production scenario, you would call a conversion API or your own backend.
// We are simulating the API response cycle here.
// Example of how a fetch would look with a proxy/API:
/*
const response = await fetch(`https://api.example.com/convert?url=${encodeURIComponent(url)}`);
const data = await response.json();
if (!response.ok) throw new Error(data.message);
setResult(data);
*/
// Simulation delay
await new Promise(resolve => setTimeout(resolve, 2500));
const videoId = url.split('v=')[1]?.split('&')[0] || url.split('/').pop();
setResult({
title: "Extracted Audio Stream",
thumbnail: `https://img.youtube.com/vi/${videoId}/mqdefault.jpg`,
duration: "03:45",
downloadUrl: "#", // This would be the actual MP3/AAC file link
format: "MP3 320kbps"
});
setStatus('success');
} catch (err) {
setErrorMessage('Failed to connect to the conversion server. Please try again later.');
setStatus('error');
}
};
return (
);
};
export default App;
{/* Header */}
{/* Input Section */}
setUrl(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleConvert()}
/>
{/* Error Message */}
{status === 'error' && (
)}
{/* Result Card */}
{status === 'success' && result && (
)}
{/* Safety Footer */}
Secure SSL Encrypted Conversion
AudioExtractor
Convert YouTube links to high-quality audio files instantly.
{errorMessage}
{result.title}
{result.format}Duration: {result.duration}
By using this service you agree to convert only non-copyrighted content or content you have explicit permission to use. This tool is for personal educational purposes only.
Comments
Post a Comment