Skip to content

Instantly share code, notes, and snippets.

@tayiorbeii
Created November 9, 2022 20:33
Show Gist options
  • Save tayiorbeii/cf26e94e1b9bb73b262a97cdf8475759 to your computer and use it in GitHub Desktop.
Save tayiorbeii/cf26e94e1b9bb73b262a97cdf8475759 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/tubnkpbcvvndmke/20-type-helpers-pattern.problem.mp4?raw=1",
"https://www.dropbox.com/s/c499l4t0ze43zbb/20-type-helpers-pattern.solution.mp4?raw=1",
"https://www.dropbox.com/s/z4th5rt6b689012/21-conditional-types.problem.mp4?raw=1",
"https://www.dropbox.com/s/9hr75e51wio9gw9/21-conditional-types.solution.mp4?raw=1",
"https://www.dropbox.com/s/04mxsrx76skv7k6/22-returning-never.problem.mp4?raw=1",
"https://www.dropbox.com/s/pmsoibnbrtpwe43/22-returning-never.solution.mp4?raw=1",
"https://www.dropbox.com/s/7b5jp9biqew5yop/23-infer-with-raw-values.problem.mp4?raw=1",
"https://www.dropbox.com/s/mv3jnnrl1mcboat/23-infer-with-raw-values.solution.2.mp4?raw=1",
"https://www.dropbox.com/s/naut2fv405vzimz/24-infer-with-generics.problem.mp4?raw=1",
"https://www.dropbox.com/s/ooc33jct40g3hne/24-infer-with-generics.solution.mp4?raw=1",
"https://www.dropbox.com/s/5n3jjfc9kba8st6/25-template-literal-value-extraction.problem.mp4?raw=1",
"https://www.dropbox.com/s/vua1arez7n8zbmc/25-template-literal-value-extraction.solution.1.mp4?raw=1",
"https://www.dropbox.com/s/r3lvd3ec6gscnvh/26-get-result-from-async-function.problem.mp4?raw=1",
"https://www.dropbox.com/s/da1vg7sk5i18aec/26-get-result-from-async-function.solution.mp4?raw=1",
"https://www.dropbox.com/s/djf69c86kb6pg3x/27-infer-in-union-types.problem.mp4?raw=1",
"https://www.dropbox.com/s/oz8ftxou5d83897/27-infer-in-union-types.solution.mp4?raw=1 ",
"https://www.dropbox.com/s/01vzcs8aqfxc2us/28-distributive-conditional-types.problem.mp4?raw=1",
"https://www.dropbox.com/s/m77mp0rhp9dysht/28-distributive-conditional-types.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}\n\n`
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