Skip to content

Instantly share code, notes, and snippets.

@borgeslucaz borgeslucaz/yt.py
Created Mar 20, 2019

Embed
What would you like to do?
import urllib
import json
import requests
def download_img(url, filename):
response = requests.get(url)
filename = filename.replace('/', '')
if response.status_code == 200:
with open(F"/srv/nightwing.cloudezapp.io/www/sara_thumbs/{filename}.jpg", 'wb') as f:
f.write(response.content)
def get_all_video_in_channel(channel_id):
api_key = ''
base_video_url = 'https://www.youtube.com/watch?v='
base_search_url = 'https://www.googleapis.com/youtube/v3/search?'
first_url = base_search_url+'key={}&channelId={}&part=snippet,id&order=date&maxResults=25'.format(api_key, channel_id)
video_links = []
url = first_url
while True:
inp = requests.get(url)
print(inp.json())
next_page_token = inp.json()['nextPageToken']
data = inp.json()
for item in data['items']:
title = item['snippet']['title']
url = item['snippet']['thumbnails']['high']['url']
# print(F'{title} - {url}')
download_img(url, title)
url = first_url + '&pageToken={}'.format(next_page_token)
get_all_video_in_channel('UC9kRw3IlSY87yoV7bTZ3piQ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.