-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_scrapping.py
More file actions
56 lines (44 loc) · 1.41 KB
/
API_scrapping.py
File metadata and controls
56 lines (44 loc) · 1.41 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import googleapiclient.discovery as g
import sys
from key import secret_key
yk = secret_key
# Setting up the youtube requester
youtube = g.build("youtube", "v3", developerKey= yk)
def requests_thumbnails(username, pageToken, uploads_id):
# Third request for the videos
request3 = youtube.playlistItems().list(
part = "Snippet",
playlistId = uploads_id,
pageToken= pageToken
)
response3 = request3.execute()
# Checking if there is a nextPageToken
try:
nextPageToken = response3["nextPageToken"]
except:
nextPageToken = None
return response3, nextPageToken
def errorMessage(error):
# Inspects error
if error == 1:
print("There are no account with that username or videos uploaded to this username. Please try another username")
sys.exit()
def get_thumbnail_Id(username):
# First request to grab id
try:
request1 = youtube.channels().list(
part= "statistics",
forUsername= username,
)
response1 = request1.execute()
youtuber_id = response1["items"][0]["id"]
except:
return 1
# Second request to grab uploads
request2 = youtube.channels().list(
part= "contentDetails",
id = youtuber_id
)
response2 = request2.execute()
uploads_id = response2["items"][0]["contentDetails"]["relatedPlaylists"]["uploads"]
return uploads_id