Skip to content

Instantly share code, notes, and snippets.

@tayiorbeii
Created November 2, 2022 06:13
Show Gist options
  • Save tayiorbeii/97abc25377aa4e00493c8f11dd22c3f0 to your computer and use it in GitHub Desktop.
Save tayiorbeii/97abc25377aa4e00493c8f11dd22c3f0 to your computer and use it in GitHub Desktop.
import "@johnlindquist/kit"
// Name: stub-total-typescript-drafts
/**
* Copy all transcript .srt and .txt files into local repo directory
* so that .ts, .srt, and .txt files are all together.
* Run the `srt-to-text` script to format the transcript txt files.
*/
let directory = await arg('Transcript directory: ')
await cd(directory)
let {_stdout} = await $`ls`
let allFiles = _stdout.split('\n')
let videoLinks = [
"https://www.dropbox.com/s/yp8t00k75ipxrt6/14-template-literal-with-string.problem.mp4?raw=1",
"https://www.dropbox.com/s/dw6rvoscq06bugx/14-template-literal-with-string.solution.mp4?raw=1",
"https://www.dropbox.com/s/fj0251njvr8ny8y/15-extract-with-template-literals.problem.mp4?raw=1",
"https://www.dropbox.com/s/t10q1zfgq3o3upg/15-extract-with-template-literals.solution.mp4?raw=1",
"https://www.dropbox.com/s/4tped9pyv5ubl19/16-unions-in-template-literals.problem.mp4?raw=1",
"https://www.dropbox.com/s/d6fp61v1w9184tq/16-unions-in-template-literals.solution.mp4?raw=1",
"https://www.dropbox.com/s/h44tnblwg30lx20/17-splitting-strings.problem.mp4?raw=1",
"https://www.dropbox.com/s/vsdstox5hji9a2x/17-splitting-strings.solution.mp4?raw=1",
"https://www.dropbox.com/s/eosl8v0k8wlaujr/18-template-literals-in-object-keys.problem.mp4?raw=1",
"https://www.dropbox.com/s/6cfnibye0u8e0ry/18-template-literals-in-object-keys.solution.mp4?raw=1"
]
// Read the URL backwards to get video filename
function getFileNameFromPath(path) {
let index = path.length - 1
while (path[index] !== '/') {
index--
}
return path.slice(index + 1)
}
let groupedFiles = videoLinks.map(link => {
let fileName = getFileNameFromPath(link)
let regex = /^(\d+)-/
let number = fileName.match(regex)[1]
let matchedFiles = allFiles.filter(file => file.includes(number))
if (fileName.includes('problem')) {
return [link, ...allFiles.filter(file => file.includes(number) && file.includes('problem'))]
} else {
return [link, ...allFiles.filter(file => file.includes(number) && file.includes('solution'))]
}
})
for (let [videoLink, ...files] of groupedFiles) {
let fileName = ''
let transcript = ''
for (let file of files) {
if (file.includes('.txt')) {
let text = await readFile(file)
transcript += text
fileName = file.replace('srt-transcript.txt', 'template')
}
}
let problemOrSolution = videoLink.includes('problem') ? 'Problem' : 'Solution'
let markdown = `# Title\n\n# ${problemOrSolution}\n/embed ${videoLink}\n\n## Lesson Description\n\n## Body\n\n## Transcript\n\n${transcript}`
await writeFile(`${fileName}.md`, markdown)
}
async function getMdFiles() {
let {_stdout} = await $`ls`
let allFiles = _stdout.split('\n')
return allFiles.filter(file => file.includes('.md'))
}
let allMdFiles = await getMdFiles()
let groupedMdFiles = allMdFiles.reduce((acc, file) => {
let regex = /^(\d+)-/
let number = file.match(regex)[1]
if (acc[number]) {
acc[number].push(file)
} else {
acc[number] = [file]
}
return acc
}, {})
// iterate over groupedMdFiles and combine the files into one markdown file with the correct order
for (let [key, files] of Object.entries(groupedMdFiles)) {
let content = ''
let fileName = files[0].replace('.problem.template.md', '.md').replace('.solution.template.md', '.md')
for (let file of files) {
let text = await readFile(file)
content += text
}
debugger;
await writeFile(`${fileName}`, content)
}
await $`rm *.template.md`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment