-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.html
More file actions
321 lines (274 loc) · 10.7 KB
/
Copy pathdecode.html
File metadata and controls
321 lines (274 loc) · 10.7 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Song Lyrics Decoder</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet">
<link rel="icon" href="https://raw.githubusercontent.com/realaurora-stw/song-player/refs/heads/main/icons/hammer.png" type="image/png">
<style>
* {
font-family: 'Poppins', sans-serif;
}
body, button, input, label, select, textarea, a {
font-family: 'Poppins', sans-serif;
}
@keyframes fadeInSizeUp {
0% {
opacity: 0;
transform: scale(0.95);
}
100% {
opacity: 1;
transform: scale(1);
}
}
body {
background-color: #000000;
color: #e0e0e0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
padding: 20px;
box-sizing: border-box;
margin: 0;
}
.container {
background-color: #070707;
padding: 35px 40px;
border-radius: 24px;
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.7);
text-align: center;
max-width: 500px;
width: 100%;
border: 1px solid #101010;
animation: fadeInSizeUp 0.25s ease-out forwards;
}
h1 {
margin-bottom: 30px;
color: #ffffff;
font-weight: 600;
}
.input-group {
text-align: left;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 600;
color: #aaaaaa;
font-size: 0.9em;
}
input[type="file"] {
display: block;
width: 100%;
padding: 10px;
border: 1px solid #171717;
border-radius: 12px;
background-color: #0f0f0f;
color: #e0e0e0;
box-sizing: border-box;
margin-bottom: 5px;
cursor: pointer;
transition: border-color 0.2s;
}
input[type="file"]::file-selector-button {
font-family: 'Poppins', sans-serif;
padding: 8px 15px;
border: 1px solid #171717;
border-radius: 12px;
background-color: #0f0f0f;
color: #ffffff;
cursor: pointer;
margin-right: 15px;
transition: background-color 0.2s ease;
font-weight: 600;
}
#status {
font-size: 0.95em;
color: #aaaaaa;
min-height: 1.2em;
font-weight: 400;
transition: color 0.3s ease;
}
.download-area {
display: none;
}
.download-area p {
margin-bottom: 15px;
color: #e0e0e0;
font-weight: 400;
}
.download-link {
font-family: 'Poppins', sans-serif;
display: inline-block;
margin: 10px 8px 0 8px;
padding: 12px 22px;
color: #ffffff;
text-decoration: none;
border-radius: 18px;
font-weight: 600;
transition: background-color 0.2s ease, box-shadow 0.2s ease;
font-size: 0.9em;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
border: none;
}
.download-link:hover {
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}
.download-link:active {
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}
.download-link.json {
background-color: #121212;
}
.download-link.mp3 {
background-color: #121212;
}
.error {
color: #ff5555 !important;
font-weight: 600 !important;
}
</style>
</head>
<body>
<div class="container">
<h1>SongLyrics File Decoder</h1>
<div class="input-group">
<input type="file" id="songlyricsFile" accept=".songlyrics">
</div>
<div id="status"></div>
<div id="downloadArea" class="download-area">
<a href="#" id="downloadJsonLink" class="download-link json" download="lyrics.json">JSON</a>
<a href="#" id="downloadMp3Link" class="download-link mp3" download="audio.mp3">MP3</a>
</div>
</div>
<script>
const fileInput = document.getElementById('songlyricsFile');
const statusDiv = document.getElementById('status');
const downloadArea = document.getElementById('downloadArea');
const downloadJsonLink = document.getElementById('downloadJsonLink');
const downloadMp3Link = document.getElementById('downloadMp3Link');
let currentJsonUrl = null;
let currentMp3Url = null;
const MAGIC_BYTES = new Uint8Array([76, 89, 82, 88]);
function cleanupUrls() {
if (currentJsonUrl) {
URL.revokeObjectURL(currentJsonUrl);
currentJsonUrl = null;
}
if (currentMp3Url) {
URL.revokeObjectURL(currentMp3Url);
currentMp3Url = null;
}
}
function resetUI() {
statusDiv.textContent = 'Select a .songlyrics file to decode.';
statusDiv.className = '';
downloadArea.style.display = 'none';
downloadJsonLink.removeAttribute('href');
downloadMp3Link.removeAttribute('href');
fileInput.value = '';
cleanupUrls();
}
fileInput.addEventListener('change', (event) => {
const file = event.target.files[0];
statusDiv.textContent = 'Select a .songlyrics file to decode.';
statusDiv.className = '';
downloadArea.style.display = 'none';
downloadJsonLink.removeAttribute('href');
downloadMp3Link.removeAttribute('href');
cleanupUrls();
if (!file) {
statusDiv.textContent = 'Select a .songlyrics file to decode.';
return;
}
if (!file.name.toLowerCase().endsWith('.songlyrics')) {
statusDiv.textContent = 'Error: Please select a valid .songlyrics file.';
statusDiv.className = 'error';
fileInput.value = '';
return;
}
statusDiv.textContent = ``;
statusDiv.className = '';
const reader = new FileReader();
reader.onload = (e) => {
statusDiv.textContent = '';
try {
const buffer = e.target.result;
const dataView = new DataView(buffer);
const uint8Array = new Uint8Array(buffer);
if (buffer.byteLength < 8) {
throw new Error('File is too small to be a valid .songlyrics file.');
}
const fileMagicBytes = uint8Array.slice(0, MAGIC_BYTES.length);
let magicMatch = true;
for(let i = 0; i < MAGIC_BYTES.length; i++) {
if (fileMagicBytes[i] !== MAGIC_BYTES[i]) {
magicMatch = false;
break;
}
}
if (!magicMatch) {
throw new Error('Invalid file format: Magic bytes "LYRX" not found.');
}
const jsonLength = dataView.getUint32(MAGIC_BYTES.length, false);
const headerLength = MAGIC_BYTES.length + 4;
if (jsonLength < 0 || headerLength + jsonLength > buffer.byteLength) {
throw new Error(`Invalid JSON length read from file: ${jsonLength}. File might be corrupted.`);
}
const jsonBytes = uint8Array.slice(headerLength, headerLength + jsonLength);
const jsonString = new TextDecoder('utf-8').decode(jsonBytes);
let jsonData;
try {
jsonData = JSON.parse(jsonString);
} catch (jsonError) {
throw new Error(`Failed to parse JSON data: ${jsonError.message}`);
}
const mp3StartOffset = headerLength + jsonLength;
if (mp3StartOffset > buffer.byteLength) {
throw new Error('File structure error: JSON length indicates data beyond file size.');
}
const mp3Bytes = buffer.slice(mp3StartOffset);
if (mp3Bytes.byteLength === 0) {
console.warn("Warning: MP3 data part is empty.");
}
const jsonBlob = new Blob([JSON.stringify(jsonData, null, 2)], { type: 'application/json;charset=utf-8' });
const mp3Blob = new Blob([mp3Bytes], { type: 'audio/mpeg' });
cleanupUrls();
currentJsonUrl = URL.createObjectURL(jsonBlob);
currentMp3Url = URL.createObjectURL(mp3Blob);
const baseFileName = file.name.replace(/\.songlyrics$/i, '');
downloadJsonLink.href = currentJsonUrl;
downloadJsonLink.download = `${baseFileName}.json`;
downloadMp3Link.href = currentMp3Url;
downloadMp3Link.download = `${baseFileName}.mp3`;
statusDiv.textContent = ``;
statusDiv.className = '';
downloadArea.style.display = 'block';
} catch (error) {
console.error("Decoding Error:", error);
statusDiv.textContent = `Error: ${error.message}`;
statusDiv.className = 'error';
downloadArea.style.display = 'none';
cleanupUrls();
fileInput.value = '';
}
};
reader.onerror = () => {
statusDiv.textContent = 'Error reading the file.';
statusDiv.className = 'error';
downloadArea.style.display = 'none';
cleanupUrls();
fileInput.value = '';
};
reader.readAsArrayBuffer(file);
});
window.addEventListener('unload', cleanupUrls);
resetUI();
</script>
</body>
</html>