# Youtube crawler
```python=
import os
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
DEVELOPER_KEY = os.getenv("YOUTUBE_TOKEN")
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
def youtube_search(channel_id, max_results=50, order="date", token=None, location=None, location_radius=None):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, developerKey=DEVELOPER_KEY)
search_response = youtube.search().list(
channelId=channel_id,
type="video",
pageToken=token,
order=order,
part="id,snippet",
maxResults=max_results,
location=location,
locationRadius=location_radius
).execute()
videos = {}
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
videos[search_result["snippet"]["title"]] = search_result["id"]["videoId"]
return videos, search_response.get('nextPageToken')
channel_id = 'UC23rnlQU_qE3cec9x709peA'
video_links = {}
next_page_token = None
while True:
results, next_page_token = youtube_search(channel_id, token=next_page_token)
video_links.update(results)
if next_page_token is None:
break
with open('links.json', 'w') as f:
json.dump(video_links, f, ensure_ascii=False)
```
## missing
- EP232
- EP340