@@ -71,40 +71,40 @@ get_all_channel_video_stats <- function(channel_id = NULL, mine = FALSE, ...) {
7171 vid_ids <- character ()
7272 page_token <- NULL
7373 page_count <- 0
74-
74+
7575 repeat {
7676 page_count <- page_count + 1
7777 if (page_count > 1 ) {
7878 message(" Fetching playlist page " , page_count , " ..." )
7979 }
80-
80+
8181 playlist_items <- get_playlist_items(
8282 filter = c(playlist_id = playlist_id ),
8383 max_results = 50 ,
8484 page_token = page_token ,
8585 simplify = FALSE ,
8686 ...
8787 )
88-
88+
8989 # Extract video IDs from this page
9090 page_video_ids <- vapply(
9191 playlist_items $ items ,
9292 function (x ) x $ contentDetails $ videoId ,
9393 character (1 )
9494 )
9595 vid_ids <- c(vid_ids , page_video_ids )
96-
96+
9797 page_token <- playlist_items $ nextPageToken
9898 if (is.null(page_token )) {
9999 break
100100 }
101101 }
102-
102+
103103 if (length(vid_ids ) == 0 ) {
104104 warning(" No videos found in channel uploads playlist" )
105105 return (data.frame ())
106106 }
107-
107+
108108 message(" Found " , length(vid_ids ), " videos. Fetching video details and statistics..." )
109109
110110 # Use the new unified get_video_details function for efficient batch processing
@@ -115,15 +115,15 @@ get_all_channel_video_stats <- function(channel_id = NULL, mine = FALSE, ...) {
115115 show_progress = TRUE ,
116116 ...
117117 )
118-
118+
119119 if (! is.data.frame(video_data ) || nrow(video_data ) == 0 ) {
120120 warning(" No video data could be retrieved or conversion to data frame failed" )
121121 return (data.frame ())
122122 }
123123
124124 # Map complex column names from get_video_details to expected simple names
125125 result_df <- video_data
126-
126+
127127 # Map column names from get_video_details output to expected names
128128 # Note: json_to_df prefixes nested fields with parent name (e.g., snippet_title, statistics_viewCount)
129129 column_mapping <- c(
@@ -136,33 +136,33 @@ get_all_channel_video_stats <- function(channel_id = NULL, mine = FALSE, ...) {
136136 " like_count" = " statistics_likeCount" ,
137137 " comment_count" = " statistics_commentCount"
138138 )
139-
139+
140140 # Rename columns that exist
141141 for (new_name in names(column_mapping )) {
142142 old_name <- column_mapping [[new_name ]]
143143 if (old_name %in% names(result_df )) {
144144 names(result_df )[names(result_df ) == old_name ] <- new_name
145145 }
146146 }
147-
147+
148148 # Add video URL
149149 result_df $ url <- paste0(" https://www.youtube.com/watch?v=" , result_df $ id )
150-
150+
151151 # Ensure consistent column order
152- final_columns <- c(" id" , " title" , " publication_date" , " description" ,
153- " channel_id" , " channel_title" , " view_count" , " like_count" ,
152+ final_columns <- c(" id" , " title" , " publication_date" , " description" ,
153+ " channel_id" , " channel_title" , " view_count" , " like_count" ,
154154 " comment_count" , " url" )
155-
155+
156156 # Add missing columns as NA if they don't exist
157157 for (col in final_columns ) {
158158 if (! col %in% names(result_df )) {
159159 result_df [[col ]] <- NA
160160 }
161161 }
162-
162+
163163 # Select final columns in the right order
164164 result_df <- result_df [, final_columns , drop = FALSE ]
165-
165+
166166 message(" Successfully retrieved data for " , nrow(result_df ), " videos" )
167167
168168 add_tuber_attributes(
0 commit comments