Implemented privacy guides tasks
This commit is contained in:
parent
3020080acd
commit
35ea7a7b16
7 changed files with 6865 additions and 0 deletions
57
tasks/update-youtube-players.js
Normal file
57
tasks/update-youtube-players.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
"use strict"
|
||||
|
||||
import readdirp from "readdirp"
|
||||
import fsExtra from "fs-extra"
|
||||
import { parse, join } from "path"
|
||||
import execa from "execa"
|
||||
|
||||
const { readFile, writeFile, remove } = fsExtra
|
||||
|
||||
const playerRegExp = /\[\!\[.*?\]\((.*?\.png)\)\]\((.*?) ".*?"\)/
|
||||
|
||||
;(async () => {
|
||||
try {
|
||||
console.info("Updating YouTube players…")
|
||||
const options = {
|
||||
fileFilter: "*.md",
|
||||
directoryFilter: "!node_modules",
|
||||
}
|
||||
for await (const file of readdirp(process.cwd(), options)) {
|
||||
const content = await readFile(file.fullPath, "utf8")
|
||||
const lines = content.split("\n")
|
||||
let updatedContent = ""
|
||||
for (const [index, line] of lines.entries()) {
|
||||
let lineBreak = "\n"
|
||||
if (index === lines.length - 1) {
|
||||
lineBreak = ""
|
||||
}
|
||||
let match
|
||||
if ((match = line.match(playerRegExp))) {
|
||||
const dir = parse(file.fullPath).dir
|
||||
const imagePath = match[1]
|
||||
const youtubeWatchUrl = match[2]
|
||||
console.info(`Processing ${file.path}…`)
|
||||
await remove(join(dir, imagePath))
|
||||
const { stdout } = await execa("node", [
|
||||
"node_modules/youtube-player-screenshot/bin/youtube-player-screenshot.js",
|
||||
"--url",
|
||||
youtubeWatchUrl,
|
||||
"--type",
|
||||
"jpeg",
|
||||
"--output",
|
||||
dir,
|
||||
"--privacy",
|
||||
"--stdout",
|
||||
])
|
||||
updatedContent += `${stdout}${lineBreak}`
|
||||
} else {
|
||||
updatedContent += `${line}${lineBreak}`
|
||||
}
|
||||
}
|
||||
await writeFile(file.fullPath, updatedContent)
|
||||
}
|
||||
console.info("Done")
|
||||
} catch (error) {
|
||||
console.error(error.message)
|
||||
}
|
||||
})()
|
Loading…
Add table
Add a link
Reference in a new issue