###################################
#### YOUTUBE COMMENTS ANALYSIS ####
###################################
library(vosonSML)
## Warning: package 'vosonSML' was built under R version 4.0.5
library(syuzhet)
## Warning: package 'syuzhet' was built under R version 4.0.5
myapikey <- "AIzaSyDz-CElYqyVUwcAMUG5PNd8ogriQYC6dsU"
mykey <- Authenticate("youtube", apiKey = myapikey)
video <- "htqXL94Rza4"
ytdata <- Collect(mykey, video , writeToFile = FALSE)
## Collecting comment threads for youtube videos...
## Video 1 of 1
## ---------------------------------------------------------------
## ** video Id: htqXL94Rza4
## ** Collected threads: 9279
## ** Collecting replies for 392 threads with replies. Please be patient.
## ........................................................................................................................................................................................................................................................................................................................................................................................................
## ** Collected replies: 1478
## ** Total video comments: 10757
## ---------------------------------------------------------------
## ** Total comments collected for all videos 10757.
## (Estimated API unit cost: 1066)
## Done.
## for saving the data, if you want to use the same data again
write.csv(ytdata, 'MoneyHeistPart5Vol1_trailer.06.08.21.csv')
## for reading the data, if you want to use an existing youtube data obtained by above method
ytdata <- read.csv('MoneyHeistPart5Vol1_trailer.06.08.21.csv')
comments <- iconv(ytdata$Comment, to = 'utf-8')
s <- get_nrc_sentiment(comments)
barplot(100*colSums(s)/sum(s), las = 2, col = rainbow(10), ylab = '%', main = 'Sentiment Scores')

get_nrc_values(comments)
## # A tibble: 1 x 10
## anger anticipation disgust fear joy negative positive sadness surprise
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 0 3 3 1 2 3 6 2 1
## # ... with 1 more variable: trust <dbl>