In [31]:
import csv
import numpy as np
# Load Dataset
with open("./Youtube History Data.csv") as f:
reader = csv.reader(f)
raw_data = [list(x) for x in reader]
data = np.array(raw_data[1:])
In [32]:
from apiclient.discovery import build
import json
# Youtube Data Collection
with open('youtube_config.json') as f:
DEVELOPER_KEY = json.loads(f.read())['api_key']
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
def get_video_tags(id_):
search_response = youtube.videos().list(
id=id_,
part="snippet",
).execute()
if 'tags' in search_response['items'][0]['snippet']:
return search_response['items'][0]['snippet']['tags']
In [41]:
video_tags = [(x[2], x[1], get_video_tags(x[2])) for x in data]
In [ ]: