Here is an example python script that uses the YouTube API to retrieve the titles, descriptions, and URLs of all the videos in a given YouTube channel:
import requests
import json
import csv
def get_channel_info(channel_id, api_key):
# Make an API call to retrieve channel information
url = "https://www.googleapis.com/youtube/v3/search?key={}&channelId={}&part=snippet&order=date&maxResults=50".format(api_key, channel_id)
response = requests.get(url)
data = json.loads(response.text)
# Extract the relevant information from the API response
videos = []
for item in data["items"]:
if item['id']['kind'] == 'youtube#video':
video = {}
video["title"] = item["snippet"]["title"]
video["description"] = item["snippet"]["description"]
video["url"] = "https://www.youtube.com/watch?v={}".format(item['id']['videoId'])
videos.append(video)
return videos
if __name__ == "__main__":
# Replace channel_id and api_key with your own values
channel_id = "YOUR_CHANNEL_ID"
api_key = "YOUR_API_KEY"
videos = get_channel_info(channel_id, api_key)
# Write the results to a CSV file
with open("videos.csv", "w", newline="") as csvfile:
fieldnames = ["title", "description", "url"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for video in videos:
writer.writerow(video)
Remember to replace YOUR_CHANNEL_ID
and YOUR_API_KEY
with your own YouTube channel ID and API key, respectively.
π Join the DevOps Dojo! π
Are you passionate about growth, learning, and collaboration in the world of DevOps? The DevOps Dojo is your new home! Whether you’re just starting out or looking to refine your skills, this vibrant community is here to support your journey.
π§ What You’ll Get:
- Access to expert-led discussions
- Hands-on learning opportunities
- Networking with like-minded professionals
Ready to take your DevOps game to the next level? Click below to learn more and join the community!
π Join the DevOps Dojo Today
Letβs build, grow, and thrive together! π