from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer analyser = SentimentIntensityAnalyzer() api_key = 'AIzaSyBR2kc8R5EzD1rnOjyXZfEL1FOGLKojsg4' yt = YouTubeDataAPI(api_key) sonic_search = yt.search(q="Sonic The Headgehog", max_results=5, parser=None) spy df_sonic = pd.DataFrame(sonic_search) df_sonic.head(5) trailer = df_sonic.iloc[0] trailer.video_id comments = yt.get_video_comments(trailer.video_id, max_results=10) df_comments = pd.DataFrame(comments) df_graph_data = pd.DataFrame(columns=[ 'comment_id', 'commenter_channel_id', 'channel_country', 'text', 'date', 'neg', 'neu', 'pos', 'compound' ]) channel_id = df_comments.iloc[0].commenter_channel_id channel_data = yt.get_channel_metadata(channel_id) # for index, row in df_comments.iterrows(): # channel_id = df_comments.iloc[0].commenter_channel_id # channel_data = yt.get_channel_metadata(channel_id) # print
def get_comments(video_id, api_key): yt = YouTubeDataAPI(api_key) return pd.DataFrame(yt.get_video_comments(video_id, get_replies=True))
from youtube_api import YouTubeDataAPI from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer analyser = SentimentIntensityAnalyzer() api_key = 'AIzaSyBR2kc8R5EzD1rnOjyXZfEL1FOGLKojsg4' yt = YouTubeDataAPI(api_key) #video parts video_parts = ['statistics', 'snippet', 'contentDetails', 'topicDetails'] #check api key is valid if yt.verify_key(): sonic = yt.get_video_metadata('szby7ZHLnkA', parser=None, part=video_parts) sonic_comments = yt.get_video_comments('szby7ZHLnkA', max_results=100) df_comments = pd.DataFrame(sonic_comments) df_graph_data = pd.DataFrame(columns=[ 'comment_id', 'commenter_channel_id', 'channel_country', 'text', 'date', 'neg', 'neu', 'pos', 'compound' ]) for index, row in df_comments.iterrows(): channel_id = df_comments.iloc[0].commenter_channel_id channel_data = yt.get_channel_metadata(channel_id) score = analyser.polarity_scores(row['text']) graph_row = { 'comment_id': row['comment_id'], 'commenter_channel_id': row['commenter_channel_id'],