-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·69 lines (62 loc) · 2.21 KB
/
main.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
import pickle
import requests
import json
import time
from urllib import request
from urllib.error import HTTPError
from json import loads
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
def main():
channel = 'youtube_channel_id'
commenttext = 'your_comment'
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secret.json" # your client_secrets_file google console
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
x = 50
while x < 100:
try:
id = pickle.load(open("comment", "rb"))
except (OSError, IOError) as e:
foo = 3
pickle.dump(foo, open("comment", "wb"))
API_ENDPOINT = 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&playlistId=<PLAYLIST ID>&key=<API ACCESS KEY>&maxResults=1'
r = requests.get(url = API_ENDPOINT)
video = loads(r.text)['items'][0]['snippet']['resourceId']['videoId']
try:
request = youtube.commentThreads().insert(
part="snippet",
body={
"snippet": {
"channelId": channel,
"videoId": video,
"topLevelComment": {
"snippet":{
"textOriginal": commenttext
}
}
}
}
)
if video:
if video != id :
response = request.execute() # Send comment
youtube.videos().rate(rating='like', id=video).execute() # Auto like your video
print("http://youtube.com/watch?v={0}".format(video)) # show video link in console
with open('comment', 'wb') as f:
pickle.dump(video, f)
except:
pass
#print("Searching video...")
time.sleep(60)
if __name__ == "__main__":
main()