forked from IsaacChan721/GDSC-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_videos.py
37 lines (33 loc) · 991 Bytes
/
fetch_videos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import webbrowser
from googleapiclient.discovery import build
from settings import API_KEY
from pprint import pprint
# Build the YouTube API client
youtube = build('youtube', 'v3', developerKey=API_KEY)
# Example API call
response = youtube.search().list(
part="snippet",
channelType="any",
maxResults=10,
order="relevance",
q="chemistry|stoichiometry",
relevanceLanguage="en",
safeSearch="moderate",
type="video"
).execute()
# Extract video IDs and construct video URLs
video_urls = []
for item in response['items']:
video_id = item['id']['videoId']
vid = youtube.videos().list(
part = "statistics",
id = video_id
).execute()
if int(vid["items"][0]["statistics"]["viewCount"]) > 1000000:
pprint(vid)
video_url = f"https://www.youtube.com/watch?v={video_id}"
video_urls.append(video_url)
# Open each video URL in a web browser
for url in video_urls:
print(url)
#webbrowser.open(url)