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]


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-41-af0317e616ed> in <module>()
----> 1 video_tags = [(x[2], x[1], get_video_tags(x[2])) for x in data]

<ipython-input-32-96c547a47443> in get_video_tags(id_)
     16         part="snippet",
     17       ).execute()
---> 18     if 'tags' in search_response['items'][0]['snippet']:
     19         return search_response['items'][0]['snippet']['tags']

IndexError: list index out of range

In [ ]: