@makefully/dutifully 1.10.1 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,17 @@
1
- const
2
- TextToSpeech = require('./TextToSpeech');
3
-
4
- module.exports = class ElevenLabs extends TextToSpeech {
5
- constructor (data) {
6
- const
7
- {id, elevenLabsApiKey} = data.contents;
8
-
9
- data.album = id;
10
- data.encodedBy = 'ElevenLabs';
11
- if (elevenLabsApiKey) {
12
- data.config.apiKey = elevenLabsApiKey;
13
- }
14
-
15
- super(data);
16
- }
1
+ const
2
+ TextToSpeech = require('./TextToSpeech');
3
+
4
+ module.exports = class ElevenLabs extends TextToSpeech {
5
+ constructor (data) {
6
+ const
7
+ {id, elevenLabsApiKey} = data.contents;
8
+
9
+ data.album = id;
10
+ data.encodedBy = 'ElevenLabs';
11
+ if (elevenLabsApiKey) {
12
+ data.config.apiKey = elevenLabsApiKey;
13
+ }
14
+
15
+ super(data);
16
+ }
17
17
  };
@@ -1,13 +1,13 @@
1
- const
2
- Cheer = require('./Cheer'),
3
- FFMPEG = class FFMPEG extends Cheer {
4
- beforeSend (archive) {
5
- const
6
- {src} = this.config;
7
-
8
- archive.directory(src, false);
9
- super.beforeSend(archive);
10
- }
11
- };
12
-
1
+ const
2
+ Cheer = require('./Cheer'),
3
+ FFMPEG = class FFMPEG extends Cheer {
4
+ beforeSend (archive) {
5
+ const
6
+ {src} = this.config;
7
+
8
+ archive.directory(src, false);
9
+ super.beforeSend(archive);
10
+ }
11
+ };
12
+
13
13
  module.exports = FFMPEG;
@@ -1,133 +1,141 @@
1
- const
2
- Cheer = require('./Cheer'),
3
- fs = require('fs').promises,
4
- getJSON = require('../helpers/getJSON'),
5
- id3 = require('node-id3').Promise,
6
- filter = (fileType, file) => (file.indexOf('.') !== 0) && (file.slice(-(fileType.length + 1)) === `.${fileType}`),
7
- combine = async (path, fileType) => {
8
- const
9
- files = (await fs.readdir(path)).filter(filter.bind(null, fileType)),
10
- list = [];
11
-
12
- for (let i = 0; i < files.length; i++) {
13
- const
14
- file = files[i];
15
-
16
- if (fileType === 'mp3') { // check id3 for lyrics presence.
17
- const
18
- {synchronisedLyrics} = await id3.read(`${path}${file}`);
19
-
20
- if (synchronisedLyrics) {
21
- const
22
- index = synchronisedLyrics.map(({shortText}) => shortText).indexOf('lipsync');
23
-
24
- if (index >= 0) {
25
- list.push(file.substring(0, file.length - fileType.length - 1));
26
- }
27
- }
28
- } else {
29
- list.push(file.substring(0, file.length - fileType.length - 1));
30
- }
31
- }
32
-
33
- return list;
34
- },
35
- sortKeys = (obj) => Object.keys(obj).sort().reduce((s, key) => {
36
- s[key] = obj[key];
37
- return s;
38
- }, {}),
39
- mapReduction = (map, list) => list.reduce((obj, file) => {
40
- const
41
- id = file.substring(0, file.length - 4);
42
-
43
- obj[id] = map[id];
44
- return obj;
45
- }, {}),
46
- LipSync = class LipSync extends Cheer {
47
- async prepare (data) {
48
- this.differenceOnly = false;
49
- this.updateList = null;
50
- await this.replaceConfigPathWithJSON('script', 'files');
51
- return super.prepare(data);
52
- }
53
-
54
- async checkDifference () {
55
- const
56
- {config} = this,
57
- {files = {}, options = {}, output, src} = config,
58
- {exportFormat = 'json', output: outputType = 'json'} = options,
59
- file = 'mouthCues.json',
60
- raw = outputType === 'json' && exportFormat !== 'mp3' ? await getJSON(`${output}${file}`) ?? {} : null,
61
- alreadyLipSynced = raw ? Object.keys(raw) : await combine(output, exportFormat),
62
- check = (id) => {
63
- const
64
- index = alreadyLipSynced.indexOf(id);
65
-
66
- if (index >= 0) {
67
- alreadyLipSynced.splice(index, 1);
68
- return true;
69
- } else {
70
- return false;
71
- }
72
- },
73
- mergeLipSync = async (newLipSync = false) => { // Must run _after_ all checks and will remove what's left.
74
- for (let i = 0; i < alreadyLipSynced.length; i++) {
75
- const
76
- key = alreadyLipSynced[i];
77
-
78
- if (raw) {
79
- delete raw[key];
80
- } else {
81
- await fs.rm(`${output}${key}.${exportFormat}`);
82
- }
83
- console.log(`Removed "${key}"`);
84
- }
85
- if (raw) {
86
- await fs.writeFile(`${output}${file}`, JSON.stringify(sortKeys({
87
- ...raw,
88
- ...newLipSync ? await getJSON(`${output}${file}`) ?? {} : {} // get new version.
89
- }), null, 4));
90
- }
91
-
92
- return alreadyLipSynced.length;
93
- },
94
- list = (await fs.readdir(src)).filter(filter.bind(null, 'mp3')).filter((file) => !check(file.substring(0, file.length - 4)));
95
-
96
- this.differenceOnly = true;
97
-
98
- if (list.length === 0) {
99
- // We'll still run the merge in case any have been removed.
100
- if (await mergeLipSync()) {
101
- throw Error('Old lip-sync removed, but no new ones required generation.');
102
- } else {
103
- throw Error('Lip-sync already up to date.');
104
- }
105
- }
106
- this.updateList = list;
107
- config.files = mapReduction(files, list);
108
- this.mergeLipSync = mergeLipSync;
109
- }
110
-
111
- beforeSend (archive) {
112
- const
113
- {src} = this.config;
114
-
115
- if (this.differenceOnly) {
116
- this.updateList.forEach((file) => archive.file(`${src}${file}`, {
117
- name: file
118
- }));
119
- } else {
120
- archive.directory(src, false);
121
- }
122
- super.beforeSend(archive);
123
- }
124
-
125
- afterExport (...args) {
126
- if (this.mergeLipSync) {
127
- this.mergeLipSync(true);
128
- }
129
- super.afterExport(...args)
130
- }
131
- };
132
-
1
+ const
2
+ Cheer = require('./Cheer'),
3
+ fs = require('fs').promises,
4
+ getJSON = require('../helpers/getJSON'),
5
+ {ensureDir, ensureParentDir, readdirOrEmpty} = require('../helpers/dirs'),
6
+ id3 = require('node-id3').Promise,
7
+ filter = (fileType, file) => (file.indexOf('.') !== 0) && (file.slice(-(fileType.length + 1)) === `.${fileType}`),
8
+ combine = async (path, fileType) => {
9
+ const
10
+ files = (await readdirOrEmpty(path)).filter(filter.bind(null, fileType)),
11
+ list = [];
12
+
13
+ for (let i = 0; i < files.length; i++) {
14
+ const
15
+ file = files[i];
16
+
17
+ if (fileType === 'mp3') { // check id3 for lyrics presence.
18
+ const
19
+ {synchronisedLyrics} = await id3.read(`${path}${file}`);
20
+
21
+ if (synchronisedLyrics) {
22
+ const
23
+ index = synchronisedLyrics.map(({shortText}) => shortText).indexOf('lipsync');
24
+
25
+ if (index >= 0) {
26
+ list.push(file.substring(0, file.length - fileType.length - 1));
27
+ }
28
+ }
29
+ } else {
30
+ list.push(file.substring(0, file.length - fileType.length - 1));
31
+ }
32
+ }
33
+
34
+ return list;
35
+ },
36
+ sortKeys = (obj) => Object.keys(obj).sort().reduce((s, key) => {
37
+ s[key] = obj[key];
38
+ return s;
39
+ }, {}),
40
+ mapReduction = (map, list) => list.reduce((obj, file) => {
41
+ const
42
+ id = file.substring(0, file.length - 4);
43
+
44
+ obj[id] = map[id];
45
+ return obj;
46
+ }, {}),
47
+ LipSync = class LipSync extends Cheer {
48
+ async prepare (data) {
49
+ this.differenceOnly = false;
50
+ this.updateList = null;
51
+ await this.replaceConfigPathWithJSON('script', 'files');
52
+ return super.prepare(data);
53
+ }
54
+
55
+ async checkDifference () {
56
+ const
57
+ {config} = this,
58
+ {files = {}, options = {}, output, src} = config,
59
+ {exportFormat = 'json', output: outputType = 'json'} = options,
60
+ file = 'mouthCues.json';
61
+
62
+ if (output) {
63
+ await ensureDir(output);
64
+ }
65
+
66
+ const
67
+ raw = outputType === 'json' && exportFormat !== 'mp3' ? await getJSON(`${output}${file}`) ?? {} : null,
68
+ alreadyLipSynced = raw ? Object.keys(raw) : await combine(output, exportFormat),
69
+ check = (id) => {
70
+ const
71
+ index = alreadyLipSynced.indexOf(id);
72
+
73
+ if (index >= 0) {
74
+ alreadyLipSynced.splice(index, 1);
75
+ return true;
76
+ } else {
77
+ return false;
78
+ }
79
+ },
80
+ mergeLipSync = async (newLipSync = false) => { // Must run _after_ all checks and will remove what's left.
81
+ for (let i = 0; i < alreadyLipSynced.length; i++) {
82
+ const
83
+ key = alreadyLipSynced[i];
84
+
85
+ if (raw) {
86
+ delete raw[key];
87
+ } else {
88
+ await fs.rm(`${output}${key}.${exportFormat}`);
89
+ }
90
+ console.log(`Removed "${key}"`);
91
+ }
92
+ if (raw) {
93
+ await ensureParentDir(`${output}${file}`);
94
+ await fs.writeFile(`${output}${file}`, JSON.stringify(sortKeys({
95
+ ...raw,
96
+ ...newLipSync ? await getJSON(`${output}${file}`) ?? {} : {} // get new version.
97
+ }), null, 4));
98
+ }
99
+
100
+ return alreadyLipSynced.length;
101
+ },
102
+ list = (await readdirOrEmpty(src)).filter(filter.bind(null, 'mp3')).filter((file) => !check(file.substring(0, file.length - 4)));
103
+
104
+ this.differenceOnly = true;
105
+
106
+ if (list.length === 0) {
107
+ // We'll still run the merge in case any have been removed.
108
+ if (await mergeLipSync()) {
109
+ throw Error('Old lip-sync removed, but no new ones required generation.');
110
+ } else {
111
+ throw Error('Lip-sync already up to date.');
112
+ }
113
+ }
114
+ this.updateList = list;
115
+ config.files = mapReduction(files, list);
116
+ this.mergeLipSync = mergeLipSync;
117
+ }
118
+
119
+ beforeSend (archive) {
120
+ const
121
+ {src} = this.config;
122
+
123
+ if (this.differenceOnly) {
124
+ this.updateList.forEach((file) => archive.file(`${src}${file}`, {
125
+ name: file
126
+ }));
127
+ } else {
128
+ archive.directory(src, false);
129
+ }
130
+ super.beforeSend(archive);
131
+ }
132
+
133
+ afterExport (...args) {
134
+ if (this.mergeLipSync) {
135
+ this.mergeLipSync(true);
136
+ }
137
+ super.afterExport(...args)
138
+ }
139
+ };
140
+
133
141
  module.exports = LipSync;
@@ -1,10 +1,10 @@
1
- const
2
- TextToSpeech = require('./TextToSpeech');
3
-
4
- module.exports = class Polly extends TextToSpeech {
5
- constructor (data) {
6
- data.album = data.contents.id;
7
- data.encodedBy = 'Amazon Polly';
8
- super(data);
9
- }
1
+ const
2
+ TextToSpeech = require('./TextToSpeech');
3
+
4
+ module.exports = class Polly extends TextToSpeech {
5
+ constructor (data) {
6
+ data.album = data.contents.id;
7
+ data.encodedBy = 'Amazon Polly';
8
+ super(data);
9
+ }
10
10
  };
@@ -1,13 +1,13 @@
1
- const
2
- Cheer = require('./Cheer'),
3
- Rasterize = class Rasterize extends Cheer {
4
- beforeSend (archive) {
5
- const
6
- {src} = this.config;
7
-
8
- archive.directory(src, false);
9
- super.beforeSend(archive);
10
- }
11
- };
12
-
1
+ const
2
+ Cheer = require('./Cheer'),
3
+ Rasterize = class Rasterize extends Cheer {
4
+ beforeSend (archive) {
5
+ const
6
+ {src} = this.config;
7
+
8
+ archive.directory(src, false);
9
+ super.beforeSend(archive);
10
+ }
11
+ };
12
+
13
13
  module.exports = Rasterize;