Skip to content

Instantly share code, notes, and snippets.

@Srinjoy-Santra
Created August 7, 2021 19:59
"use strict"
const fs = require("fs")
const path = require("path")
const srcPath = "file/Path/"
fs.readFile(path.join(srcPath, "yi-note.json"), (err, data) => {
if (err) throw err
const yin = JSON.parse(data)
const { timestamp, ...rest } = yin.data[1]
yin.data.map(video => {
writeMd(video)
})
})
const writeMd = (video) => {
const urlId = video.meta.url.split("=")[1]
const fileName = video.meta.title
const filePath = path.join(srcPath,`${fileName} ${urlId}.md`)
const [day, time] = new Date(video.createdAt).toISOString().split("T")
const tags = video.meta.keywords.map((tag) => tag.replace(/\s/g, "-"))
if (!fs.existsSync(filePath) && video.tags && video.tags.includes('1')) {
const frontmatter = `---
type: videos
status:
title:
source: ${video.meta.url}
creator: "@ Someone"s
file.cday: ${day}
modifiedOn:
publishedOn:
tags: ${tags}
aliases: []
---`
const title = `# ${fileName}`
const hhmm = time.match(/[^:]+(\:[^:]+)?/g)[0]
const sub = `${day} ${hhmm} | [[+]] [source](${video.meta.url}) | #youtube
by [[@ Someone]]`
const iframe = `
<div class="videoWrapper">
<iframe src="https://www.youtube.com/embed/${urlId}" allow\="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</div>
${video.meta.description}
`
const subhead = `## Highlights`
let highlights = ''
video.notes.map(note =>
{
const ts = new Date(note.timestamp * 1000).toISOString().substr(11, 8);
highlights += `
- [${ts}](${video.meta.url}&t=${note.timestamp})
- ${note.content}`
}
)
const md = `${frontmatter}\n${title}\n${sub}\n${iframe}\n${subhead}\n${highlights}`
fs.writeFile(filePath, md, function (err) {
if (err) {
return console.log(err)
}
console.log(`The "${fileName}" was saved!`)
})
}
}
@profucius
Copy link

profucius commented Feb 7, 2022

Hi, I found this file on your dev.to blog (https://dev.to/srinjoysantra/how-i-use-yinote-to-take-notes-for-youtube-videos-4d6p)

I want to try using it for myself, but can you please explain which tool I need to run this with? I see that it is a js/javascript file, but I am not yet understanding how to run this, to convert the JSON file to a MD file for Obsidian to read. Thanks for your help.

@Srinjoy-Santra
Copy link
Author

Hey, you can use Nodejs to run this. Change the srcPath to where you have the downloaded json. The markdown notes will be created in the same path.

@profucius
Copy link

profucius commented Feb 7, 2022

Ah I see. Okay I tried editing the srcPath as you said to point to the exported json file, and then ran the script with NodeJS via CMD "node yinote2md.js" and I get this error. I tried both NodeJS v16 and v17, same error. I only edited the srcPath to be "F:"
Thoughts?

node yinote2md.js
F:\node-v16\yinote2md.js:10
const { timestamp, ...rest } = yin.data[1]

TypeError: Cannot destructure property 'timestamp' of 'yin.data[1]' as it is undefined.
at F:\node-v16\yinote2md.js:10:11
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment