Skip to content

Instantly share code, notes, and snippets.

View XWilliamY's full-sized avatar

William Yang XWilliamY

View GitHub Profile
from urllib.parse import urlparse, parse_qs
# adopted from:
# https://stackoverflow.com/questions/45579306/get-youtube-video-url-or-youtube-video-id-from-a-string-using-regex
def get_id(url):
u_pars = urlparse(url)
quer_v = parse_qs(u_pars.query).get('v')
if quer_v:
return quer_v[0]
pth = u_pars.path.split('/')
from urllib.parse import urlparse, parse_qs
# source:
# https://stackoverflow.com/questions/45579306/get-youtube-video-url-or-youtube-video-id-from-a-string-using-regex
def get_id(url):
u_pars = urlparse(url)
quer_v = parse_qs(u_pars.query).get('v')
if quer_v:
return quer_v[0]
pth = u_pars.path.split('/')
from apiclient.discovery import build
def build_service(filename):
with open(filename) as f:
key = f.readline()
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
return build(YOUTUBE_API_SERVICE_NAME,
YOUTUBE_API_VERSION,
for item in response['items']:
comment = item['snippet']['topLevelComment']['snippet']['textDisplay']
comment_id = item['snippet']['topLevelComment']['id']
reply_count = item['snippet']['totalReplyCount']
like_count = item['snippet']['topLevelComment']['snippet']['likeCount']
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Working With Youtube Comments\n",
"\n",
"## Introduction\n",
"\n",
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#1 import required libraries
import json
from csv import writer
from apiclient.discovery import build
#2 configure function parameters for required variables to pass to service
def get_comments(part='snippet',
maxResults=100,
textFormat='plainText',
order='time',
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.