123456789101112131415161718192021222324252627282930313233343536373839 |
- import requests
- import json
- import redis
- api_key = 'AIzaSyDzDM2u5Ru6ld1Imz0pUrTFL1n-gll9q1U'
- def collect_video():
- all_video_id = []
- video_list = f"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails,status&playlistId=UU2Qda9PhJWuiMTCZ-j7K_hg&key={api_key}&maxResults=50"
- r = requests.get(video_list)
- res = json.loads(r.content)
- next_page = res['nextPageToken']
- for i in res['items']:
- all_video_id.append(i['snippet']['resourceId']['videoId'])
- while True:
- next_video_list = f"https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails,status&playlistId=UU2Qda9PhJWuiMTCZ-j7K_hg&key={api_key}&maxResults=50&pageToken={next_page}"
- r = requests.get(next_video_list)
- res = json.loads(r.content)
- for i in res['items']:
- all_video_id.append(i['snippet']['resourceId']['videoId'])
- try:
- next_page = res['nextPageToken']
- except:
- break
- print(len(all_video_id))
- r = redis.Redis(host='db.ptt.cx', port=6379, db=0,password='choozmo9')
- js = json.dumps(all_video_id)
- r.set('yt_video',js)
-
-
- if __name__ == '__main__':
- collect_video()
-
- "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails,status&playlistId=UU2Qda9PhJWuiMTCZ-j7K_hg&key=AIzaSyDzDM2u5Ru6ld1Imz0pUrTFL1n-gll9q1U&maxResults=50&pageToken=EAAaBlBUOkNESQ"
- "https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UC2Qda9PhJWuiMTCZ-j7K_hg&key=AIzaSyDzDM2u5Ru6ld1Imz0pUrTFL1n-gll9q1U"
- "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet,contentDetails,status&playlistId=UU2Qda9PhJWuiMTCZ-j7K_hg&key=AIzaSyDzDM2u5Ru6ld1Imz0pUrTFL1n-gll9q1U&maxResults=50"
- '''觀看率'''"https://www.googleapis.com/youtube/v3/videos?part=statistics&id=eFZckOTi24c&key=AIzaSyDzDM2u5Ru6ld1Imz0pUrTFL1n-gll9q1U"
|