Untitled
unknown
plain_text
2 years ago
1.2 kB
4
Indexable
import requests import json def extract_video_info(video_id): api_key = "YOUR_API_KEY" base_url = "https://www.googleapis.com/youtube/v3/videos?" url = f"{base_url}id={video_id}&key={api_key}&part=snippet,statistics,contentDetails" response = requests.get(url) data = json.loads(response.text) video = data["items"][0] snippet = video["snippet"] statistics = video["statistics"] contentDetails = video["contentDetails"] views = statistics["viewCount"] thumbnail = snippet["thumbnails"]["default"]["url"] comments = statistics["commentCount"] likes = statistics["likeCount"] dislikes = statistics["dislikeCount"] date_published = snippet["publishedAt"] length = contentDetails["duration"] date_uploaded = contentDetails["uploaded"] video_info = { "views": views, "thumbnail": thumbnail, "comments": comments, "likes": likes, "dislikes": dislikes, "date_published": date_published, "length": length, "date_uploaded": date_uploaded } return video_info video_id = "video_id_goes_here" info = extract_video_info(video_id) print(info)
Editor is loading...