-
-
Save event15/e94b759496c5e35afd893a078653cba2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(xlsx) | |
get_video_stats <- function(videoId) { | |
URL <- NULL | |
stats <- NULL | |
oki <- NULL | |
videoId <- paste(c(videoId), collapse = ",") | |
URL <- paste0("https://www.googleapis.com/youtube/v3/videos?part=statistics&id=", | |
videoId = videoId, | |
"&key=AIzaSyD2IYTzb5BfVprlqw82ptFwEj021IhZfec") | |
oki <- jsonlite::fromJSON(URL) | |
stats <- data.frame( | |
oki$items$statistics$viewCount, | |
oki$items$statistics$likeCount, | |
oki$items$statistics$commentCount | |
) | |
return(stats) | |
} | |
get_playlists <- function(id) { | |
MisJson <- NULL | |
URL <- NULL | |
video <- NULL | |
videoStats <- NULL | |
URL <- paste0("https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=", | |
id = id, | |
"&key=AIzaSyD2IYTzb5BfVprlqw82ptFwEj021IhZfec") | |
MisJson <- jsonlite::fromJSON(URL) | |
videoStats <- get_video_stats(MisJson$items$snippet$resourceId$videoId) | |
video <- data.frame( | |
MisJson$items$snippet$publishedAt, | |
MisJson$items$snippet$title, | |
MisJson$items$snippet$position, | |
MisJson$items$snippet$resourceId$videoId, | |
id, | |
videoStats$oki.items.statistics.viewCount, | |
videoStats$oki.items.statistics.likeCount, | |
videoStats$oki.items.statistics.commentCount | |
) | |
id <- NULL | |
return(video) | |
} | |
file <- read.csv("Projekty/Youtube/playlists.csv", sep = ";") | |
playlists <- data.frame(file) | |
filmy <- get_playlists("PLW0kJB6mYV46UR6jp8sWAZOkeBPn7lCIp") | |
licznik <- 0 | |
for(listaId in playlists$id) { | |
if(listaId != "PLW0kJB6mYV46UR6jp8sWAZOkeBPn7lCIp" & | |
listaId != "PLW0kJB6mYV47ONa3PFdG-jpBefBFFRqIw" & | |
listaId != "PLW0kJB6mYV47N7l3C1k1kjmZlKeTuWy4g" & | |
listaId != "PLW0kJB6mYV44Fh3vk8GF5vo8UiRgiX7tM") { | |
print(paste('Nr.', licznik, ':', listaId)) | |
filmy <- rbind(filmy, get_playlists(listaId)) | |
licznik <- licznik + 1 | |
} | |
for(i in 1:10000) { i <- i + i } | |
} | |
names(filmy) <- c("publishedAt", "videoTitle", "videoPosition", "videoId", 'playlistId', 'views', 'likes', 'comments') | |
#print(paste(playlists$id)) | |
write.xlsx(filmy, "mydata1.xlsx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment