-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixxxLibraryBuilder.js
128 lines (103 loc) · 4.49 KB
/
mixxxLibraryBuilder.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
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
/*
Copyright 2018 Nik Martin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/**
* Mixxx Library Builder
* using the smallest playable mp3 file (144 bytes), this script will generate a configurable amount of
* tracks, in a configurable amount of genres, organized by genre/artist
*/
// how many tracks to generate
const trackCount = 1000;
//how many artists per genre
const artistCount = 8;
//how many albums per artist
const albumCount = 2;
// the BPM range to tag each track with
const minBPM = 50;
const maxBPM = 180;
//where to build the library. To avoid thrassing SSDs, use a memory mapped temp file system if possible
const libraryPath = '/tmp/library';
// the list of genres to assign. Each genre gets evenly distrubuted across the library. Add more to get more
const genreList = [
'Alternative',
'Blues',
'Country',
'Disco',
'Electronic',
'Funk',
'Goth',
'Hip-Hop',
'Industrial',
'Jazz',
'K-Pop',
'Latino',
'Merengue',
];
/* === HERE BE DRAGONS. THERE AREN"T (M)ANY CONFIGURABLE ITEMS BELOW HERE === */
var fs = require('fs');
const id3 = require('node-id3');
// the mp3 file as a base64 string.
// Its an 8kbps mono file with just 2 samples of complete silence.
// the smallest file mixx will read
const mp3Base64String =
'/+MYxAAAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV/+MYxDsAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV';
const buff = Buffer.alloc(mp3Base64String.length, mp3Base64String, 'base64');
const tracksPerGenre = Math.floor(trackCount / genreList.length);
genreList.forEach(genre => {
console.log('creating', genre, 'genre');
// make a dir for the genre
try {
fs.mkdirSync(`${libraryPath}/${genre}`);
} catch (error) {
// don't care
}
// for each genre, create artistCount artists
for (let i = 0; i < artistCount; i++) {
let artist = makeRandomString(20);
try {
fs.mkdirSync(`${libraryPath}/${genre}/${artist}`);
} catch (error) {}
//evenly distribute the tracks across each artist/genre/album
let tracksPerArtist = Math.floor(tracksPerGenre / artistCount);
let tracksPerAlbum = tracksPerArtist / albumCount;
for (let i = 0; i < albumCount; i++) {
let albumTitle = makeRandomString(13);
try {
fs.mkdirSync(`${libraryPath}/${genre}/${artist}/${albumTitle}`);
} catch (error) {}
//generate the mp3 tags
for (let i = 0; i < tracksPerAlbum; i++) {
//generate a random song title
let title = makeRandomString(16);
// generate random bpm
let bpm = (Math.random() * (maxBPM - minBPM) + minBPM).toFixed(2);
let tags = {
TIT2: title,
TPE1: artist,
TALB: albumTitle,
TYER: 2018,
TKEY: 'Ab',
TBPM: bpm,
TCON: genre,
COMM: { language: 'eng', text: makeRandomString(20) },
};
// write tags into mp3 buffer
let outBuff = id3.write(tags, buff);
// write mp3 buffer to file
// do it synchronously because having too many file open < performance
fs.writeFileSync(`${libraryPath}/${genre}/${artist}/${albumTitle}/${artist} - ${title}.mp3`, outBuff);
} // track
} //album
} // artist
}); //genre
function makeRandomString(length) {
let text = [];
const allowedChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (var i = 0; i < length; i++) {
text.push(allowedChars.charAt(Math.floor(Math.random() * allowedChars.length)));
}
return text.join('');
}