-
Notifications
You must be signed in to change notification settings - Fork 3
/
liked.py
36 lines (24 loc) · 859 Bytes
/
liked.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
from googleapiclient.discovery import HttpError
from helpers import get
def like_videos(service, videos: list):
if len(videos) == 0:
print('No videos to like.')
return
print('Liking {} videos.'.format(len(videos)))
for index, video in enumerate(videos):
print('#{} '.format(index), end = '')
video_id = get(video, 'snippet.resourceId.videoId')
video_title = get(video, 'snippet.title')
if not video_id:
print('wrong video format.')
continue
print('ID: {}, title: "{}"'.format(video_id, video_title), end = '')
try:
service.videos().rate(
id = video_id,
rating = 'like'
).execute()
print(' liked.')
except HttpError as e:
print(' error:')
print(e)