Hi
I want to update description of all my youtube videos with Headings
Thanks
Hi
I want to update description of all my youtube videos with Headings
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Tuhin PaulRank #7 · 71.9K reputationPosted Feb 9, 2025, 11:03 AM EST
Part -1
To update the descriptions of all your YouTube videos with headings, you can use the YouTube Data API. If you want to do it programatically. An example implementation in Python using the
google-api-python-clientlibrary.This script will fetch all your videos, append a heading to their descriptions, and update them.
Before running the script:
credentials.jsonfile.pip install google-api-python-client google-auth-oauthlib google-auth-httplib2.import os import pickle from googleapiclient.discovery import build from google_auth_oauthlib.flow import InstalledAppFlow from google.auth.transport.requests import Request # Define the scope and API service name SCOPES = ['https://www.googleapis.com/auth/youtube'] API_SERVICE_NAME = 'youtube' API_VERSION = 'v3' def get_authenticated_service(): """Authenticate and return the YouTube API client.""" creds = None if os.path.exists('token.pickle'): with open('token.pickle', 'rb') as token: creds = pickle.load(token) if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SCOPES) creds = flow.run_local_server(port=0) with open('token.pickle', 'wb') as token: pickle.dump(creds, token) return build(API_SERVICE_NAME, API_VERSION, credentials=creds) def update_video_descriptions(youtube): """Fetch all videos and update their descriptions with headings.""" # Fetch the list of videos request = youtube.channels().list( part='contentDetails', mine=True ) response = request.execute() # Get the uploads playlist ID uploads_playlist_id = response['items'][0]['contentDetails']['relatedPlaylists']['uploads'] # Fetch all video IDs from the uploads playlist video_ids = [] next_page_token = None while True: playlist_request = youtube.playlistItems().list( part='contentDetails', playlistId=uploads_playlist_id, maxResults=50, pageToken=next_page_token ) playlist_response = playlist_request.execute() for item in playlist_response['items']: video_ids.append(item['contentDetails']['videoId']) next_page_token = playlist_response.get('nextPageToken') if not next_page_token: break # Update each video's description for video_id in video_ids: video_request = youtube.videos().list( part='snippet', id=video_id ) video_response = video_request.execute() if video_response['items']: video = video_response['items'][0] snippet = video['snippet'] original_description = snippet.get('description', '') # Add a heading to the description new_description = f"=== Video Description ===\n\n{original_description}" # Update the video's description snippet['description'] = new_description update_request = youtube.videos().update( part='snippet', body={ 'id': video_id, 'snippet': snippet } ) update_response = update_request.execute() print(f"Updated description for video ID: {video_id}") if __name__ == '__main__': # Authenticate and get the YouTube service youtube = get_authenticated_service() # Update video descriptions update_video_descriptions(youtube)=== Video Description ===) to the existing description and updates it using the YouTube Data API.Steps to Run:
update_youtube_descriptions.py.credentials.jsonfile in the same directory.python update_youtube_descriptions.py.Tuhin PaulRank #7 · 71.9K reputationPosted Feb 9, 2025, 11:07 AM EST
Below is a JavaScript implementation using Node.js and the
googleapislibrary to update the descriptions of all your YouTube videos with headings.credentials.jsonfile.const fs = require('fs'); const { google } = require('googleapis'); // Define the scope and API service name const SCOPES = ['https://www.googleapis.com/auth/youtube']; const TOKEN_PATH = 'token.json'; /** * Authenticate and return the YouTube API client. */ async function getAuthenticatedClient() { const content = fs.readFileSync('credentials.json'); const credentials = JSON.parse(content); const { client_secret, client_id, redirect_uris } = credentials.installed; const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]); // Check if we have previously stored a token if (fs.existsSync(TOKEN_PATH)) { const token = fs.readFileSync(TOKEN_PATH, 'utf8'); oAuth2Client.setCredentials(JSON.parse(token)); } else { const authUrl = oAuth2Client.generateAuthUrl({ access_type: 'offline', scope: SCOPES, }); console.log('Authorize this app by visiting this URL:', authUrl); const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout, }); const code = await new Promise((resolve) => { rl.question('Enter the authorization code: ', (code) => { rl.close(); resolve(code); }); }); const { tokens } = await oAuth2Client.getToken(code); oAuth2Client.setCredentials(tokens); // Store the token for future use fs.writeFileSync(TOKEN_PATH, JSON.stringify(tokens)); console.log('Token stored to', TOKEN_PATH); } return google.youtube({ version: 'v3', auth: oAuth2Client }); } /** * Fetch all video IDs from the uploads playlist. */ async function fetchVideoIds(youtube) { const channelResponse = await youtube.channels.list({ part: 'contentDetails', mine: true, }); const uploadsPlaylistId = channelResponse.data.items[0].contentDetails.relatedPlaylists.uploads; let videoIds = []; let nextPageToken = null; do { const playlistResponse = await youtube.playlistItems.list({ part: 'contentDetails', playlistId: uploadsPlaylistId, maxResults: 50, pageToken: nextPageToken, }); videoIds = videoIds.concat(playlistResponse.data.items.map(item => item.contentDetails.videoId)); nextPageToken = playlistResponse.data.nextPageToken; } while (nextPageToken); return videoIds; } /** * Update the description of each video with a heading. */ async function updateVideoDescriptions(youtube) { const videoIds = await fetchVideoIds(youtube); for (const videoId of videoIds) { const videoResponse = await youtube.videos.list({ part: 'snippet', id: videoId, }); const video = videoResponse.data.items[0]; const snippet = video.snippet; const originalDescription = snippet.description || ''; // Add a heading to the description snippet.description = `=== Video Description ===\n\n${originalDescription}`; // Update the video's description await youtube.videos.update({ part: 'snippet', requestBody: { id: videoId, snippet: snippet, }, }); console.log(`Updated description for video ID: ${videoId}`); } } (async () => { try { const youtube = await getAuthenticatedClient(); await updateVideoDescriptions(youtube); } catch (error) { console.error('Error:', error); } })();=== Video Description ===) to the existing description and updates it using the YouTube Data API.Steps to Run:
update_youtube_descriptions.js.credentials.jsonfile in the same directory.node update_youtube_descriptions.js