add new video and test
This commit is contained in:
1 parent
2d18c9b3d6
commit
dc432844e7
267 files changed
+969
-17
No files matched your search
@@ -30,44 +30,47 @@ wss.on('connection', (ws) => {
|
||||
const { q, duration } = payload;
|
||||
console.log(`Start ${q}`)
|
||||
|
||||
const q_stem = q.replace(/\.[a-z0-9]+$/, "");
|
||||
const q_stem = q.replace(/\.[a-z0-9]+$/, "").replace(/\[.+?\]/g, '').trim();
|
||||
|
||||
try {
|
||||
mkdirSync(joinPath(ROOT_DIR, q_stem));
|
||||
} catch (e) {}
|
||||
|
||||
let outMd = "";
|
||||
let isChanged = false;
|
||||
|
||||
const re = /^(?<min>\d{1,2}):(?<sec>\d{2})\s*$/;
|
||||
const ts = [];
|
||||
|
||||
const { data, content } = matter(readFileSync(joinPath(ROOT_DIR, `${q_stem}.md`), 'utf-8'));
|
||||
let { data, content } = matter(readFileSync(joinPath(ROOT_DIR, `${q_stem}.md`), 'utf-8'));
|
||||
data.video = '/' + q;
|
||||
|
||||
for (const line of content.split("\n")) {
|
||||
const interval = data.interval;
|
||||
if (typeof interval === 'number') {
|
||||
for (let t = 0; t < duration; t += interval) {
|
||||
const min = Math.floor(t / 60)
|
||||
const sec = Math.floor(t - min * 60)
|
||||
|
||||
content += `\n${min}:${sec.toString().padStart(2, '0')}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
const re = /^(?<min>\d{1,2}):(?<sec>\d{2})\s*$/;
|
||||
const lines = content.split('\n')
|
||||
content = ''
|
||||
for (const line of lines) {
|
||||
const m = re.exec(line);
|
||||
if (m?.groups) {
|
||||
const { min, sec } = m.groups;
|
||||
const t = `${min}_${sec}`;
|
||||
ts.push(t);
|
||||
outMd += `\n\n\n`;
|
||||
content += `\n\n\n`;
|
||||
isChanged = true;
|
||||
} else {
|
||||
outMd += `${line}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
const interval = data.interval;
|
||||
if (typeof interval === 'number') {
|
||||
for (let t = 0; t < duration; t += interval) {
|
||||
ts.push(t);
|
||||
isChanged = true;
|
||||
content += `${line}\n`;
|
||||
}
|
||||
}
|
||||
|
||||
if (isChanged){
|
||||
writeFileSync(joinPath(ROOT_DIR, `${q_stem}.md`), matter.stringify(outMd, data));
|
||||
writeFileSync(joinPath(ROOT_DIR, `${q_stem}.md`), matter.stringify(content, data));
|
||||
ws.send(JSON.stringify({ name: "seek_q_ts", q, ts }));
|
||||
}
|
||||
} break;
|
||||
|
||||
Reference in new issue
Block a user