Skip to content

Commit 388bc39

Browse files
committed
linting
1 parent 9112999 commit 388bc39

33 files changed

+220
-220
lines changed

.lintr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
linters: linters_with_defaults(object_name_linter = object_name_linter(styles = c("snake_case", "camelCase", "dotted.case", "symbols")), commented_code_linter = NULL, line_length_linter = line_length_linter(120), cyclocomp_linter = NULL, return_linter = NULL, object_usage_linter = NULL)
2-
exclusions: list("R/zzz.R")
1+
linters: linters_with_defaults(object_name_linter = NULL, commented_code_linter = NULL, line_length_linter = NULL, return_linter = NULL, object_usage_linter = NULL, indentation_linter = NULL, trailing_blank_lines_linter = NULL, brace_linter = NULL)
2+
exclusions: list("R/zzz.R", "tests/_covrpage.Rmd")

R/add_video_to_playlist.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ add_video_to_playlist <- function(playlist_id, video_id, position = NULL, ...) {
3030
}
3131

3232
# Prepare the request body
33-
if(is.null(position)){
33+
if (is.null(position)) {
3434
body <- list(
3535
snippet = list(
3636
playlistId = playlist_id,

R/error_handling.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ with_retry <- function(expr,
202202
# Calculate delay with exponential backoff and optional jitter
203203
delay <- min(base_delay * (backoff_factor ^ (attempt - 1)), max_delay)
204204
if (jitter) {
205-
delay <- delay * (0.5 + 0.5 * runif(1)) # Add 0-50% jitter
205+
delay <- delay * (0.5 + 0.5 * runif(1))
206206
}
207207

208208
# Call retry callback if provided
@@ -568,7 +568,7 @@ validate_youtube_params <- function(params, endpoint = NULL) {
568568
channelId = validate_channel_id(param_value, "channel_id"),
569569
playlist_id = validate_playlist_id(param_value, param_name),
570570
playlistId = validate_playlist_id(param_value, "playlist_id"),
571-
part = if(!is.null(endpoint)) validate_part_parameter(param_value, endpoint, param_name),
571+
part = if (!is.null(endpoint)) validate_part_parameter(param_value, endpoint, param_name),
572572
region_code = validate_region_code(param_value, param_name),
573573
regionCode = validate_region_code(param_value, "region_code"),
574574
hl = validate_language_code(param_value, "language_code"),

R/get_all_channel_video_stats.R

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)