From 2dcb233333ca5c6d8462d54ee313d64245ba2d2b Mon Sep 17 00:00:00 2001 From: AlexandreBrg Date: Thu, 25 Jul 2024 17:03:05 +0200 Subject: [PATCH] chore: add doc on script Signed-off-by: AlexandreBrg --- scripts/youtubeSubtitleEdit.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/scripts/youtubeSubtitleEdit.js b/scripts/youtubeSubtitleEdit.js index baf9841..37a8169 100644 --- a/scripts/youtubeSubtitleEdit.js +++ b/scripts/youtubeSubtitleEdit.js @@ -8,8 +8,24 @@ const GLADIA_KEY_PATH = path.resolve(process.env.HOME, '.credentials', 'gladia_a const OPENAI_KEY_PATH = path.resolve(process.env.HOME, '.credentials', 'openai_api.key') const POLLING_INTERVAL = 5000 // 5 seconds const CONCURRENT_JOBS = 10 +const PLAYLIST_ID = 'replace-me' + +// This whole is here to generate subtitles for a youtube video +// using Gladia & ChatGPT. It won't upload subtitles to youtube +// but only export SRT files into `out_srt` directory. +// +// Configuration: +// - Create a file containing gladia API key in ~/.credentials/gladia_api.key +// - Create a file containing chatgpt API key in ~/.credentials/openai_api.key +// - Ensure you have youtube credentials for API in ~/.credentials/youtube.credentials.json +// - Ensure you have client_secret.json file to bypass Oauth2 from youtube +// - Update const variable PLAYLIST_ID in this script with one containing all videos +// +// Notes: +// - Videos & the playlist MUST not be in private, in "non-visible" at least +// - You change the concurrency to better follow what's happening +// - If any SRT or keywords are already generated, they won't be recreated. -// Function to get API key from a file const getApiKey = (filePath) => { if (!fs.existsSync(filePath)) { console.error(`❌ Error: API key file not found at: ${filePath}`) @@ -216,11 +232,10 @@ const processVideo = async (video, outSrtDir, outKeywordsDir) => { const main = async () => { const { auth, channelId } = await initYoutube() - const playlistId = 'PLz7aCyCbFOu8_3w6EydaKkjHDiZ9Az1XR' const openPlannerFileName = 'openplanner.json' const openPlannerContent = JSON.parse(fs.readFileSync(openPlannerFileName)) - const videos = await getVideosLast72Hours(auth, channelId, playlistId) + const videos = await getVideosLast72Hours(auth, channelId, PLAYLIST_ID) console.log('ℹ️ Retrieved videos: ' + videos.length) const videosWithValidSession = joinYoutubeAndOpenPlannerData(videos, openPlannerContent)