-
Notifications
You must be signed in to change notification settings - Fork 0
/
flac.html
97 lines (90 loc) · 2.96 KB
/
flac.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube to FLAC Downloader</title>
<script src="https://cdn.jsdelivr.net/npm/ytdl-core@latest/dist/browser.js"></script>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f0f0f0;
}
.container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
#urlInput {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
}
button {
width: 100%;
padding: 10px;
background-color: #ff0000;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #cc0000;
}
#status {
margin-top: 20px;
padding: 10px;
border-radius: 4px;
}
</style>
</head>
<body>
<div class="container">
<h1>YouTube to FLAC Downloader</h1>
<input type="text" id="urlInput" placeholder="Enter YouTube URL">
<button onclick="downloadAudio()">Download as FLAC</button>
<div id="status"></div>
</div>
<script>
async function downloadAudio() {
const url = document.getElementById('urlInput').value;
const status = document.getElementById('status');
try {
status.innerHTML = 'Starting download...';
const info = await ytdl.getInfo(url);
const audioFormat = ytdl.chooseFormat(info.formats, { quality: 'highestaudio' });
const audioStream = ytdl(url, { format: audioFormat });
const fileName = `${info.videoDetails.title}.flac`;
// Create download link
const blob = await streamToBlob(audioStream);
const downloadUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = downloadUrl;
a.download = fileName;
a.click();
status.innerHTML = 'Download complete!';
} catch (error) {
status.innerHTML = `Error: ${error.message}`;
}
}
async function streamToBlob(stream) {
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
return new Blob(chunks, { type: 'audio/flac' });
}
</script>
</body>
</html>