Skip to content

Commit

Permalink
chore: add doc on script
Browse files Browse the repository at this point in the history
Signed-off-by: AlexandreBrg <burgoni@pm.me>
  • Loading branch information
alexandrebrg committed Jul 25, 2024
1 parent 2980e8a commit 2dcb233
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions scripts/youtubeSubtitleEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2dcb233

Please sign in to comment.