change youtube/index.mjs to not confuse chatgpt or run out of tokens (#205 @iamsirsammy)

* change youtube/index.mjs to not confuse chatgpt or run out of tokens

* Update index.mjs
This commit is contained in:
iamsirsammy
2023-04-14 07:28:03 -04:00
committed by GitHub
parent ba94457ba3
commit b2cd54e9c4
@@ -1,6 +1,11 @@
import { cropText } from '../../../utils'
import { config } from '../index.mjs'
function replaceHtmlEntities(htmlString) { // This function was written by ChatGPT and modified by me (iamsirsammy)
const doc = new DOMParser().parseFromString(htmlString.replace("&", "&"), 'text/html');
return doc.documentElement.innerText;
}
export default {
init: async (hostname, userConfig, getInput, mountComponent) => {
try {
@@ -41,12 +46,14 @@ export default {
let subtitleContent = ''
while (subtitleData.indexOf('">') !== -1) {
subtitleData = subtitleData.substring(subtitleData.indexOf('">') + 2)
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ','
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ' '
}
subtitleContent = replaceHtmlEntities(subtitleContent)
return cropText(
`Provide a brief summary of the video using concise language and incorporating the video title.` +
`The video title is:"${title}".The subtitle content is as follows:\n${subtitleContent}`,
`Provide a brief summary of the following video using concise language, still including all the important details, and incorporating the video title.` +
`The video title is "${title}". The subtitle content is as follows:\n${subtitleContent}`,
)
} catch (e) {
console.log(e)