museria 0.2.48 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.eslintrc +10 -2
- package/.github/workflows/build.yml +3 -3
- package/.github/workflows/publish.yml +3 -3
- package/README.md +56 -60
- package/bin/actions.js +28 -28
- package/bin/index.js +4 -4
- package/bin/runner.js +1 -1
- package/bin/utils.js +6 -2
- package/dist/client/museria.client.js +7 -7
- package/dist/face/45a265d0f07b31cde85f.ttf +0 -0
- package/dist/face/6205fd00fb1b573e9f0f.ttf +0 -0
- package/dist/face/8d3cabfc66809162fb4d.woff2 +0 -0
- package/dist/face/fb8184add5a3101ad0a3.woff2 +0 -0
- package/dist/face/museria.face.js +33 -13
- package/dist/face/style.css +13 -11
- package/package.json +41 -40
- package/src/browser/client/index.js +2 -1
- package/src/browser/face/client.js +2 -1
- package/src/browser/face/controllers/app/app.html +77 -69
- package/src/browser/face/controllers/app/app.js +14 -7
- package/src/browser/face/controllers/app/app.scss +2 -22
- package/src/browser/face/index.js +3 -3
- package/src/browser/face/styles/main.scss +91 -11
- package/src/browser/face/styles/vars.scss +0 -1
- package/src/client.js +73 -74
- package/src/collection/transports/music/index.js +20 -18
- package/src/db/transports/database/index.js +7 -5
- package/src/db/transports/loki/index.js +30 -25
- package/src/errors.js +2 -1
- package/src/index.js +8 -6
- package/src/node.js +315 -323
- package/src/schema.js +27 -29
- package/src/server/transports/express/api/butler/controllers.js +7 -10
- package/src/server/transports/express/api/butler/routes.js +5 -5
- package/src/server/transports/express/api/master/controllers.js +7 -10
- package/src/server/transports/express/api/master/routes.js +5 -5
- package/src/server/transports/express/api/node/controllers.js +52 -61
- package/src/server/transports/express/api/node/routes.js +10 -10
- package/src/server/transports/express/api/routes.js +1 -1
- package/src/server/transports/express/api/slave/controllers.js +7 -10
- package/src/server/transports/express/api/slave/routes.js +6 -6
- package/src/server/transports/express/client/controllers.js +40 -61
- package/src/server/transports/express/client/routes.js +33 -39
- package/src/server/transports/express/controllers.js +10 -21
- package/src/server/transports/express/index.js +23 -20
- package/src/server/transports/express/midds.js +67 -67
- package/src/server/transports/express/routes.js +12 -12
- package/src/utils.js +175 -184
- package/test/client.js +311 -305
- package/test/db/database.js +32 -28
- package/test/db/loki.js +78 -74
- package/test/group.js +161 -156
- package/test/index.js +20 -10
- package/test/node.js +461 -460
- package/test/routes.js +404 -399
- package/test/server/express.js +35 -31
- package/test/services.js +25 -18
- package/test/tools.js +8 -6
- package/test/utils.js +236 -234
- package/webpack.client.js +9 -7
- package/webpack.face.js +8 -6
- package/dist/face/fa-brands-400.eot +0 -0
- package/dist/face/fa-brands-400.svg +0 -3717
- package/dist/face/fa-brands-400.ttf +0 -0
- package/dist/face/fa-brands-400.woff +0 -0
- package/dist/face/fa-brands-400.woff2 +0 -0
- package/dist/face/fa-solid-900.eot +0 -0
- package/dist/face/fa-solid-900.svg +0 -5034
- package/dist/face/fa-solid-900.ttf +0 -0
- package/dist/face/fa-solid-900.woff +0 -0
- package/dist/face/fa-solid-900.woff2 +0 -0
- /package/dist/face/{open-sans.ttf → 17e98b9e5586529b13cc.ttf} +0 -0
- /package/dist/face/{proxima-nova.ttf → 326601dfabd91e3f016c.ttf} +0 -0
- /package/dist/face/{logo.svg → ee9c6af64aa224827cec.svg} +0 -0
package/test/utils.js
CHANGED
@@ -1,270 +1,272 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
describe('
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
describe('.isValidSongAudioLink()', () => {
|
17
|
-
it('should return true', () => {
|
18
|
-
assert.isTrue(utils.isValidSongAudioLink('http://localhost:80/audio/hash.mp3'), 'check http and mp3');
|
19
|
-
assert.isTrue(utils.isValidSongAudioLink('https://192.0.0.1:3000/audio/hash.mpga'), 'check https and mpga');
|
20
|
-
});
|
21
|
-
|
22
|
-
it('should return false', () => {
|
23
|
-
assert.isFalse(utils.isValidSongAudioLink('http://localhost/audio/hash'), 'check without an extenstion');
|
24
|
-
assert.isFalse(utils.isValidSongAudioLink('http://localhost/audio/hash.mp3'), 'check without a port');
|
25
|
-
assert.isFalse(utils.isValidSongAudioLink('ftp://localhost/audio/hash'), 'check the wrong protocol');
|
26
|
-
assert.isFalse(utils.isValidSongAudioLink('http://192.0.0.1:80/cover/hash'), 'check the wrong path');
|
27
|
-
});
|
28
|
-
});
|
29
|
-
|
30
|
-
describe('.isValidSongCoverLink()', () => {
|
31
|
-
it('should return true', () => {
|
32
|
-
assert.isTrue(utils.isValidSongCoverLink('http://localhost:80/cover/hash.jpg'), 'check http and jpg');
|
33
|
-
assert.isTrue(utils.isValidSongCoverLink('https://192.0.0.1:3000/cover/hash.png'), 'check https and png');
|
34
|
-
});
|
35
|
-
|
36
|
-
it('should return false', () => {
|
37
|
-
assert.isFalse(utils.isValidSongCoverLink('http://localhost/cover/hash'), 'check without an extenstion');
|
38
|
-
assert.isFalse(utils.isValidSongCoverLink('http://localhost/cover/hash.mp3'), 'check without a port');
|
39
|
-
assert.isFalse(utils.isValidSongCoverLink('ftp://localhost/cover/hash'), 'check the wrong protocol');
|
40
|
-
assert.isFalse(utils.isValidSongCoverLink('http://192.0.0.1:80/audio/hash'), 'check the wrong path');
|
41
|
-
});
|
42
|
-
});
|
43
|
-
|
44
|
-
describe('.beautifySongTitle()', () => {
|
45
|
-
it('should camalize the title', () => {
|
46
|
-
assert.equal(utils.beautifySongTitle('artist - good title (feat. artist2)'), 'Artist - Good Title (feat. Artist2)');
|
1
|
+
import { assert } from "chai";
|
2
|
+
import fse from "fs-extra";
|
3
|
+
import path from "path";
|
4
|
+
import utils from "../src/utils.js";
|
5
|
+
import tools from "./tools.js";
|
6
|
+
|
7
|
+
export default function () {
|
8
|
+
describe('utils', () => {
|
9
|
+
describe('.splitSongTitle()', () => {
|
10
|
+
it('should return the right array', () => {
|
11
|
+
const arr = utils.splitSongTitle('x - a, - b - c');
|
12
|
+
assert.equal(arr[0], 'x', 'the first part');
|
13
|
+
assert.equal(arr[1], 'a, - b - c', 'the second part');
|
14
|
+
});
|
47
15
|
});
|
48
16
|
|
49
|
-
|
50
|
-
|
51
|
-
|
17
|
+
describe('.isValidSongAudioLink()', () => {
|
18
|
+
it('should return true', () => {
|
19
|
+
assert.isTrue(utils.isValidSongAudioLink('http://localhost:80/audio/hash.mp3'), 'check http and mp3');
|
20
|
+
assert.isTrue(utils.isValidSongAudioLink('https://192.0.0.1:3000/audio/hash.mpga'), 'check https and mpga');
|
21
|
+
});
|
22
|
+
|
23
|
+
it('should return false', () => {
|
24
|
+
assert.isFalse(utils.isValidSongAudioLink('http://localhost/audio/hash'), 'check without an extenstion');
|
25
|
+
assert.isFalse(utils.isValidSongAudioLink('http://localhost/audio/hash.mp3'), 'check without a port');
|
26
|
+
assert.isFalse(utils.isValidSongAudioLink('ftp://localhost/audio/hash'), 'check the wrong protocol');
|
27
|
+
assert.isFalse(utils.isValidSongAudioLink('http://192.0.0.1:80/cover/hash'), 'check the wrong path');
|
28
|
+
});
|
52
29
|
});
|
53
30
|
|
54
|
-
|
55
|
-
|
56
|
-
|
31
|
+
describe('.isValidSongCoverLink()', () => {
|
32
|
+
it('should return true', () => {
|
33
|
+
assert.isTrue(utils.isValidSongCoverLink('http://localhost:80/cover/hash.jpg'), 'check http and jpg');
|
34
|
+
assert.isTrue(utils.isValidSongCoverLink('https://192.0.0.1:3000/cover/hash.png'), 'check https and png');
|
35
|
+
});
|
36
|
+
|
37
|
+
it('should return false', () => {
|
38
|
+
assert.isFalse(utils.isValidSongCoverLink('http://localhost/cover/hash'), 'check without an extenstion');
|
39
|
+
assert.isFalse(utils.isValidSongCoverLink('http://localhost/cover/hash.mp3'), 'check without a port');
|
40
|
+
assert.isFalse(utils.isValidSongCoverLink('ftp://localhost/cover/hash'), 'check the wrong protocol');
|
41
|
+
assert.isFalse(utils.isValidSongCoverLink('http://192.0.0.1:80/audio/hash'), 'check the wrong path');
|
42
|
+
});
|
57
43
|
});
|
58
44
|
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
describe('.beautifySongTitle()', () => {
|
46
|
+
it('should camalize the title', () => {
|
47
|
+
assert.equal(utils.beautifySongTitle('artist - good title (feat. artist2)'), 'Artist - Good Title (feat. Artist2)');
|
48
|
+
});
|
49
|
+
|
50
|
+
it('should remove excess spaces', () => {
|
51
|
+
const res = utils.beautifySongTitle(' artist - good title ( feat. artist2 ) ( remix ) [2019 ] ( europe)');
|
52
|
+
assert.equal(res, 'Artist - Good Title (remix) [2019] (europe) (feat. Artist2)');
|
53
|
+
});
|
54
|
+
|
55
|
+
it('should remove links', () => {
|
56
|
+
const res = utils.beautifySongTitle('почта.рф artist google.com - mail.com good www.mail.ru title http://example.ru');
|
57
|
+
assert.equal(res, 'Artist - Good Title');
|
58
|
+
});
|
59
|
+
|
60
|
+
it('should remove empty braces', () => {
|
61
|
+
const res = utils.beautifySongTitle('artist [] - () title');
|
62
|
+
assert.equal(res, 'Artist - Title');
|
63
|
+
});
|
64
|
+
|
65
|
+
it('should keep unusual signs but remove emojis and slashes', () => {
|
66
|
+
assert.equal(utils.beautifySongTitle(`MrkeyØ - #$-&^@+_*&%'.\\/Song 😀 good`), `Mrkeyø - #$-&^@+_*&%'.\\/song Good`);
|
67
|
+
});
|
68
|
+
|
69
|
+
it('should place feats together', () => {
|
70
|
+
const res = utils.beautifySongTitle('artist1, artist2,artist3 - title (feat. artist4, artist5,artist6)');
|
71
|
+
assert.equal(res, 'Artist1 - Title (feat. Artist2, Artist3, Artist4, Artist5, Artist6)');
|
72
|
+
});
|
73
|
+
|
74
|
+
it('should bring all feats to a single form', () => {
|
75
|
+
assert.equal(utils.beautifySongTitle('artist - title (ft. Artist)'), 'Artist - Title (feat. Artist)', 'check "ft"');
|
76
|
+
assert.equal(utils.beautifySongTitle('artist - title (feat. Artist)'), 'Artist - Title (feat. Artist)', 'check "feat"');
|
77
|
+
assert.equal(utils.beautifySongTitle('artist - title ft. Artist'), 'Artist - Title (feat. Artist)', 'check without brackets');
|
78
|
+
});
|
79
|
+
|
80
|
+
it('should change the dash type', () => {
|
81
|
+
assert.equal(utils.beautifySongTitle('artist — title'), 'Artist - Title', 'check the long dash');
|
82
|
+
assert.equal(utils.beautifySongTitle('artist – title'), 'Artist - Title', 'check the short dash');
|
83
|
+
});
|
84
|
+
|
85
|
+
it('should return an empty string', () => {
|
86
|
+
assert.isEmpty(utils.beautifySongTitle('wrong song title'), 'check the wrong title');
|
87
|
+
assert.isEmpty(utils.beautifySongTitle(' - no song artist'), 'check the wrong artist');
|
88
|
+
});
|
62
89
|
});
|
63
90
|
|
64
|
-
|
65
|
-
|
91
|
+
describe('.isSongTitle()', () => {
|
92
|
+
it('should return true', () => {
|
93
|
+
assert.isTrue(utils.isSongTitle('artist - title'), 'check the simple case');
|
94
|
+
assert.isTrue(utils.isSongTitle('artist - title (ft. artist, artist2)'), 'check with the feats');
|
95
|
+
assert.isTrue(utils.isSongTitle('artist, artist2 - title (ft. artist)'), 'check with the feats in the beginning');
|
96
|
+
assert.isTrue(utils.isSongTitle('artist - title (remix) (ft. artist2)'), 'check the additional info');
|
97
|
+
});
|
98
|
+
|
99
|
+
it('should return false', () => {
|
100
|
+
assert.isFalse(utils.isSongTitle({}), 'check an object');
|
101
|
+
assert.isFalse(utils.isSongTitle(0), 'check an integer');
|
102
|
+
assert.isFalse(utils.isSongTitle('wrong'), 'check without dash');
|
103
|
+
assert.isFalse(utils.isSongTitle('wrong title -'), 'check without a name');
|
104
|
+
assert.isFalse(utils.isSongTitle('artist -title'), 'check without spaces');
|
105
|
+
});
|
66
106
|
});
|
67
107
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
108
|
+
describe('.getSongName()', () => {
|
109
|
+
it('should return an empty string because of a wrong title', () => {
|
110
|
+
assert.isEmpty(utils.getSongName('artist'));
|
111
|
+
});
|
72
112
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
assert.equal(utils.beautifySongTitle('artist - title ft. Artist'), 'Artist - Title (feat. Artist)', 'check without brackets');
|
77
|
-
});
|
113
|
+
it('should return the right name in simple case', () => {
|
114
|
+
assert.equal(utils.getSongName('artist - title'), 'Title');
|
115
|
+
});
|
78
116
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
});
|
117
|
+
it('should return the right name with feats', () => {
|
118
|
+
assert.equal(utils.getSongName('artist - title ft. artist2, artist3'), 'Title');
|
119
|
+
});
|
83
120
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
});
|
88
|
-
});
|
121
|
+
it('should return the right name with a lot artists', () => {
|
122
|
+
assert.equal(utils.getSongName('artist, artist2 - title ft. artist3, artist4'), 'Title');
|
123
|
+
});
|
89
124
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
assert.isTrue(utils.isSongTitle('artist - title (ft. artist, artist2)'), 'check with the feats');
|
94
|
-
assert.isTrue(utils.isSongTitle('artist, artist2 - title (ft. artist)'), 'check with the feats in the beginning');
|
95
|
-
assert.isTrue(utils.isSongTitle('artist - title (remix) (ft. artist2)'), 'check the additional info');
|
96
|
-
});
|
97
|
-
|
98
|
-
it('should return false', () => {
|
99
|
-
assert.isFalse(utils.isSongTitle({}), 'check an object');
|
100
|
-
assert.isFalse(utils.isSongTitle(0), 'check an integer');
|
101
|
-
assert.isFalse(utils.isSongTitle('wrong'), 'check without dash');
|
102
|
-
assert.isFalse(utils.isSongTitle('wrong title -'), 'check without a name');
|
103
|
-
assert.isFalse(utils.isSongTitle('artist -title'), 'check without spaces');
|
125
|
+
it('should return the right name with additional data', () => {
|
126
|
+
assert.equal(utils.getSongName('artist - song title (remix) [1999]'), 'Song Title (remix) [1999]');
|
127
|
+
});
|
104
128
|
});
|
105
|
-
});
|
106
|
-
|
107
|
-
describe('.getSongName()', () => {
|
108
|
-
it('should return an empty string because of a wrong title', () => {
|
109
|
-
assert.isEmpty(utils.getSongName('artist'));
|
110
|
-
});
|
111
129
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
it('should return the right name with feats', () => {
|
117
|
-
assert.equal(utils.getSongName('artist - title ft. artist2, artist3'), 'Title');
|
118
|
-
});
|
119
|
-
|
120
|
-
it('should return the right name with a lot artists', () => {
|
121
|
-
assert.equal(utils.getSongName('artist, artist2 - title ft. artist3, artist4'), 'Title');
|
122
|
-
});
|
123
|
-
|
124
|
-
it('should return the right name with additional data', () => {
|
125
|
-
assert.equal(utils.getSongName('artist - song title (remix) [1999]'), 'Song Title (remix) [1999]');
|
126
|
-
});
|
127
|
-
});
|
128
|
-
|
129
|
-
describe('.getSongArtists()', () => {
|
130
|
-
it('should return an empty array because of a wrong title', () => {
|
131
|
-
assert.lengthOf(utils.getSongArtists('artist'), 0);
|
132
|
-
});
|
130
|
+
describe('.getSongArtists()', () => {
|
131
|
+
it('should return an empty array because of a wrong title', () => {
|
132
|
+
assert.lengthOf(utils.getSongArtists('artist'), 0);
|
133
|
+
});
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
135
|
+
it('should return the right array', () => {
|
136
|
+
const artists = utils.getSongArtists('artist,artist2 - title ft. artist3, artist4');
|
137
|
+
assert.equal(artists.join(','), 'Artist,Artist2,Artist3,Artist4');
|
138
|
+
});
|
137
139
|
});
|
138
|
-
});
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
141
|
+
describe('.getSongSimilarity()', () => {
|
142
|
+
it('should return 0 because of wrong titles', () => {
|
143
|
+
assert.equal(utils.getSongSimilarity('wrong', 'artist - title'), 0, 'check the wrong first argument');
|
144
|
+
assert.equal(utils.getSongSimilarity('artist - title', 'wrong'), 0, 'check the wrong secong argument');
|
145
|
+
});
|
145
146
|
|
146
|
-
|
147
|
-
|
148
|
-
|
147
|
+
it('should return 1', () => {
|
148
|
+
assert.equal(utils.getSongSimilarity('Artist - Title', 'artist - title'), 1);
|
149
|
+
});
|
149
150
|
|
150
|
-
|
151
|
-
|
152
|
-
|
151
|
+
it('should return > 0.8', () => {
|
152
|
+
const res = utils.getSongSimilarity('Artist - Title', 'artist - title 1');
|
153
|
+
assert.isTrue(res > 0.8 && res < 1);
|
154
|
+
});
|
153
155
|
});
|
154
|
-
});
|
155
|
-
|
156
|
-
describe('.prepareSongTagsToGet()', () => {
|
157
|
-
it('should return buffer APIC', async () => {
|
158
|
-
const tags = {
|
159
|
-
APIC: {
|
160
|
-
imageBuffer: Buffer.from('1')
|
161
|
-
}
|
162
|
-
};
|
163
|
-
const res = await utils.prepareSongTagsToGet(tags);
|
164
|
-
assert.instanceOf(res.APIC, Buffer);
|
165
|
-
});
|
166
|
-
});
|
167
|
-
|
168
|
-
describe('.prepareSongTagsToSet()', () => {
|
169
|
-
it('should change "image" to "APIC"', async () => {
|
170
|
-
const val = Buffer.from('1');
|
171
|
-
const tags = { image: val };
|
172
|
-
const res = await utils.prepareSongTagsToSet(tags);
|
173
|
-
assert.strictEqual(res.APIC, val);
|
174
|
-
});
|
175
|
-
|
176
|
-
it('should change fs.ReadStream to a string path', async () => {
|
177
|
-
const val = path.join(tools.tmpPath, 'audio.mp3');
|
178
|
-
const tags = { APIC: fse.createReadStream(val) };
|
179
|
-
const res = await utils.prepareSongTagsToSet(tags);
|
180
|
-
assert.equal(res.APIC, val);
|
181
|
-
});
|
182
|
-
});
|
183
156
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
const res = utils.encodeSongTitle(title);
|
195
|
-
assert.equal(utils.decodeSongTitle(res), title);
|
196
|
-
});
|
197
|
-
});
|
198
|
-
|
199
|
-
describe('tags manipulation', () => {
|
200
|
-
it('should set the tags', async () => {
|
201
|
-
const file = path.join(tools.tmpPath, 'audio.mp3');
|
202
|
-
const title = 'artist - title';
|
203
|
-
const tags = { fullTitle: title };
|
204
|
-
await utils.setSongTags(file, tags)
|
205
|
-
const res = await utils.getSongTags(file);
|
206
|
-
assert.equal(res.fullTitle, utils.beautifySongTitle(title), 'check the title');
|
207
|
-
assert.lengthOf(Object.keys(res), 2, 'check the length');
|
208
|
-
});
|
209
|
-
|
210
|
-
it('should reset the tags', async () => {
|
211
|
-
const file = path.join(tools.tmpPath, 'audio.mp3');
|
212
|
-
const title = 'artist - title';
|
213
|
-
const tags = { TIT3: title };
|
214
|
-
await utils.setSongTags(file, tags)
|
215
|
-
const res = await utils.getSongTags(file);
|
216
|
-
assert.equal(res.TIT3, title, 'check the title');
|
217
|
-
assert.lengthOf(Object.keys(res), 1, 'check the length');
|
157
|
+
describe('.prepareSongTagsToGet()', () => {
|
158
|
+
it('should return buffer APIC', async () => {
|
159
|
+
const tags = {
|
160
|
+
APIC: {
|
161
|
+
imageBuffer: Buffer.from('1')
|
162
|
+
}
|
163
|
+
};
|
164
|
+
const res = await utils.prepareSongTagsToGet(tags);
|
165
|
+
assert.instanceOf(res.APIC, Buffer);
|
166
|
+
});
|
218
167
|
});
|
219
168
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
169
|
+
describe('.prepareSongTagsToSet()', () => {
|
170
|
+
it('should change "image" to "APIC"', async () => {
|
171
|
+
const val = Buffer.from('1');
|
172
|
+
const tags = { image: val };
|
173
|
+
const res = await utils.prepareSongTagsToSet(tags);
|
174
|
+
assert.strictEqual(res.APIC, val);
|
175
|
+
});
|
176
|
+
|
177
|
+
it('should change fse.ReadStream to a string path', async () => {
|
178
|
+
const val = path.join(tools.tmpPath, 'audio.mp3');
|
179
|
+
const tags = { APIC: fse.createReadStream(val) };
|
180
|
+
const res = await utils.prepareSongTagsToSet(tags);
|
181
|
+
assert.equal(res.APIC, val);
|
182
|
+
});
|
228
183
|
});
|
229
184
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
assert.equal(tags.TIT3, 'z', 'check the source keys');
|
236
|
-
assert.equal(tags.YYY, 'y', 'check the dest keys');
|
237
|
-
assert.isUndefined(tags.XXX, 'check the inheritance');
|
185
|
+
describe('.encodeSongTitle()', () => {
|
186
|
+
it('should include right symbols', () => {
|
187
|
+
const res = utils.encodeSongTitle(`${Math.random()} - ${Math.random()}`);
|
188
|
+
assert.match(res, /[a-z0-9_]/i);
|
189
|
+
});
|
238
190
|
});
|
239
191
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
192
|
+
describe('.decodeSongTitle()', () => {
|
193
|
+
it('should include right symbols', () => {
|
194
|
+
const title = 'artist - title';
|
195
|
+
const res = utils.encodeSongTitle(title);
|
196
|
+
assert.equal(utils.decodeSongTitle(res), title);
|
197
|
+
});
|
245
198
|
});
|
246
|
-
});
|
247
199
|
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
200
|
+
describe('tags manipulation', () => {
|
201
|
+
it('should set the tags', async () => {
|
202
|
+
const file = path.join(tools.tmpPath, 'audio.mp3');
|
203
|
+
const title = 'artist - title';
|
204
|
+
const tags = { fullTitle: title };
|
205
|
+
await utils.setSongTags(file, tags);
|
206
|
+
const res = await utils.getSongTags(file);
|
207
|
+
assert.equal(res.fullTitle, utils.beautifySongTitle(title), 'check the title');
|
208
|
+
assert.lengthOf(Object.keys(res), 2, 'check the length');
|
209
|
+
});
|
210
|
+
|
211
|
+
it('should reset the tags', async () => {
|
212
|
+
const file = path.join(tools.tmpPath, 'audio.mp3');
|
213
|
+
const title = 'artist - title';
|
214
|
+
const tags = { TIT3: title };
|
215
|
+
await utils.setSongTags(file, tags);
|
216
|
+
const res = await utils.getSongTags(file);
|
217
|
+
assert.equal(res.TIT3, title, 'check the title');
|
218
|
+
assert.lengthOf(Object.keys(res), 1, 'check the length');
|
219
|
+
});
|
220
|
+
|
221
|
+
it('should add the tags', async () => {
|
222
|
+
const file = path.join(tools.tmpPath, 'audio.mp3');
|
223
|
+
const tags = { TIT1: '1', TIT2: '2' };
|
224
|
+
await utils.addSongTags(file, tags);
|
225
|
+
const res = await utils.getSongTags(file);
|
226
|
+
assert.equal(res.TIT3, 'artist - title', 'check the TIT3');
|
227
|
+
assert.equal(res.TIT1, tags.TIT1, 'check the TIT1');
|
228
|
+
assert.equal(res.TIT2, tags.TIT2, 'check the TIT2');
|
229
|
+
});
|
230
|
+
|
231
|
+
it('should merge the tags', async () => {
|
232
|
+
const source = { fullTitle: 'Artist - Song', XXX: 'x', TIT3: 'z' };
|
233
|
+
const dest = { TIT2: 'Song1', TPE1: 'Artist1', YYY: 'y' };
|
234
|
+
const tags = await utils.mergeSongTags(source, dest);
|
235
|
+
assert.equal(tags.fullTitle, utils.beautifySongTitle(dest.TPE1 + ' - ' + dest.TIT2), 'check the full title');
|
236
|
+
assert.equal(tags.TIT3, 'z', 'check the source keys');
|
237
|
+
assert.equal(tags.YYY, 'y', 'check the dest keys');
|
238
|
+
assert.isUndefined(tags.XXX, 'check the inheritance');
|
239
|
+
});
|
240
|
+
|
241
|
+
it('should remove the tags', async () => {
|
242
|
+
const file = path.join(tools.tmpPath, 'audio.mp3');
|
243
|
+
await utils.removeSongTags(file);
|
244
|
+
const res = await utils.getSongTags(file);
|
245
|
+
assert.lengthOf(Object.keys(res), 0);
|
246
|
+
});
|
252
247
|
});
|
253
248
|
|
254
|
-
|
255
|
-
|
256
|
-
|
249
|
+
describe('.getSongMetadata()', () => {
|
250
|
+
it('should return a right object from the file path', async () => {
|
251
|
+
const res = await utils.getSongMetadata(path.join(tools.tmpPath, 'audio.mp3'));
|
252
|
+
assert.containsAllKeys(res, ['bitrate', 'duration', 'sampleRate']);
|
253
|
+
});
|
254
|
+
|
255
|
+
it('should return a right object from the buffer', async () => {
|
256
|
+
const res = await utils.getSongMetadata(await fse.readFile(path.join(tools.tmpPath, 'audio.mp3')));
|
257
|
+
assert.containsAllKeys(res, ['bitrate', 'duration', 'sampleRate']);
|
258
|
+
});
|
259
|
+
|
260
|
+
it('should return a right object from the file stream', async () => {
|
261
|
+
const res = await utils.getSongMetadata(fse.createReadStream(path.join(tools.tmpPath, 'audio.mp3')));
|
262
|
+
assert.containsAllKeys(res, ['bitrate', 'duration', 'sampleRate']);
|
263
|
+
});
|
257
264
|
});
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
265
|
+
|
266
|
+
describe('.normalizeString()', () => {
|
267
|
+
it('should remove accents', () => {
|
268
|
+
assert.equal(utils.normalizeString('Mylène Farmer'), 'Mylene Farmer');
|
269
|
+
});
|
262
270
|
});
|
263
271
|
});
|
264
|
-
|
265
|
-
describe('.normalizeString()', () => {
|
266
|
-
it('should remove accents', () => {
|
267
|
-
assert.equal(utils.normalizeString('Mylène Farmer'), 'Mylene Farmer');
|
268
|
-
});
|
269
|
-
});
|
270
|
-
});
|
272
|
+
}
|
package/webpack.client.js
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
import path from "path";
|
2
|
+
import merge from "lodash-es/merge.js";
|
3
|
+
import stWebpackConfig from "storacle/webpack.client.js";
|
4
|
+
import mtWebpackConfig from "metastocle/webpack.client.js";
|
5
5
|
|
6
|
-
|
6
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
7
|
+
|
8
|
+
export default (options = {}, wp) => {
|
7
9
|
options = merge({
|
8
10
|
include: [],
|
9
11
|
mock: {
|
10
12
|
'music-metadata': true,
|
11
13
|
'base64url': true
|
12
|
-
}
|
14
|
+
}
|
13
15
|
}, options);
|
14
16
|
options.include.push([path.resolve(__dirname, 'src/browser/client')]);
|
15
17
|
return wp? mtWebpackConfig(stWebpackConfig(options), wp): options;
|
16
|
-
};
|
18
|
+
};
|
package/webpack.face.js
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
import path from "path";
|
2
|
+
import merge from "lodash-es/merge.js";
|
3
|
+
import spWebpackConfig from "spreadable/webpack.common.js";
|
4
4
|
|
5
|
-
|
5
|
+
const __dirname = new URL('.', import.meta.url).pathname;
|
6
|
+
|
7
|
+
export default (options = {}, wp) => {
|
6
8
|
options = merge({
|
7
9
|
name: 'face',
|
8
|
-
include: []
|
10
|
+
include: []
|
9
11
|
}, options);
|
10
12
|
options.include.push([
|
11
13
|
path.resolve(__dirname, 'src/browser/face'),
|
12
14
|
path.resolve(__dirname, 'node_modules/akili')
|
13
15
|
]);
|
14
16
|
return wp? spWebpackConfig(options, wp): options;
|
15
|
-
};
|
17
|
+
};
|
Binary file
|