-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmusic-tags.js
49 lines (43 loc) · 1.18 KB
/
music-tags.js
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
const fs = require("fs");
const NodeID3 = require("node-id3");
const {
execSync
} = require("child_process");
export default function musicTagEditor(directory) {
fs.readdir(directory, function (err, files) {
if (err) throw err;
files
.filter(function (file) {
return file.match(/\.zip$/g);
})
.forEach(function (file) {
extractMusic(file);
fs.readdir(`./${directory}/musics`, function (err, musics) {
if (err) throw err;
musics
.filter(function (music) {
return music.match(/\.mp3$/g);
})
.forEach(function (music) {
editMusicTags(music, directory);
});
});
});
});
}
function extractMusic(file) {
const directory = file.replace('.zip', '');
if (fs.existsSync(directory))
execSync(`rm -rf "${directory}"`);
execSync(`unzip "${file}"`);
if (fs.existsSync(`./${directory}/musics`))
execSync(`rm -rf musics`);
execSync(`mv "${directory}" musics`);
}
function editMusicTags(music, directory) {
let tags = NodeID3.read(`./${directory}/musics/${music}`);
tags.copyright = "Gerama.ir";
tags.comment.text = "Gerama.ir";
tags.image.description = "Gerama.ir";
NodeID3.update(tags, `./${directory}/musics/${music}`);
}