-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
68 lines (53 loc) · 1.96 KB
/
script.js
File metadata and controls
68 lines (53 loc) · 1.96 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
/////////////////////////////// //
// Copyright@SATHIYARAMAN SaRa //
///////////////////////////// //
// create array for store the datas and use data to save file
var dt = new Array();
var songUpload = document.querySelector('#songUpload');
document.addEventListener("change", (event) => {
console.log(songUpload.files.length);
for (var z = 0; z < songUpload.files.length; z++) {
var file = event.target.files[z];
jsmediatags.read(file, {
onSuccess: function (tag) {
try {
// Array buffer to base64
const data = tag.tags.picture.data;
const format = tag.tags.picture.format;
let base64String = "";
for (let i = 0; i < data.length; i++) {
base64String += String.fromCharCode(data[i]);
}
// display the all audio files in html
const ul = document.getElementById("ul");
let lines = ` <aside>
<div id="cover" style="background-image: `+ 'url(data:' + format + ';base64,' + window.btoa(base64String) + ')' + `;"></div>
<p id="title">`+ tag.tags.title + `</p>
<p id="artist">`+ tag.tags.artist + `</p>
<p id="album">`+ tag.tags.album + `</p>
<p id="genre">`+ tag.tags.genre + `</p>
</aside>`;
ul.insertAdjacentHTML("beforeend", lines);
// .slice(0,20) slice 20characters only in view
// create data file
let print = `
{
name: '`+ tag.tags.title + `',
path: '` + songUpload.value.split(/(\\|\/)/g).pop() + `',
movie: '` + tag.tags.album + `',
cover: '`+ 'data:' + format + ';base64,' + window.btoa(base64String) + `'
}`;
dt.push(print);
}
catch (error) {
console.log(error);
}
// file save
uriContent = "data:application/octet-stream," + encodeURIComponent(dt);
document.getElementById("dlink").innerHTML = "<a href=" + uriContent + " download=\"datas.txt\">Here is the download link</a>";
}
})
}
console.log(dt);
alert("Success :)");
})