-
Notifications
You must be signed in to change notification settings - Fork 0
/
feeds_requests.R
243 lines (218 loc) · 6.58 KB
/
feeds_requests.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#' Get recent podcast feeds
#'
#' @description `feeds_recent()` retrieves the most recent podcast feeds added
#' to the podcastindex.
#'
#' @param max Maximum number of results to return.
#' Value must be a single integer between 1 and 1000.
#' @param lang optional two-letter language code that when specified will
#' only return podcasts/episodes having that specific language.
#' @param since optional date string in format `YYYY-MM-DD` that when specified
#' will only return podcasts/episodes created since the specified date.
#' @param cat_terms optional character vector of one or more categories that
#' when specified will only return podcasts/episodes under those categories.
#' @param notcat_terms optional character vector of one or more categories that
#' when specified will only return podcasts/episodes not under those
#' categories.
#'
#' @return `tibble` data frame with metadata associated with recent feeds
#' in chronological order
#' @export
#'
#' @examplesIf podindexr::podcastindex_api_isset()
#' # Requires API key and secret
#'
#' feeds_recent()
#'
#' feeds_recent(max = 100, since = "2021-01-01", cat_terms = c("News", "Finance"))
#'
feeds_recent <- function(max = 40, lang = "en", since = NULL, cat_terms = NULL, notcat_terms = NULL) {
# perform checks for key parameters
max <- check_max(max)
if (!is.null(since)) {
since <- check_datetime(since)
}
if (!is.null(cat_terms)) {
cat_terms <- check_cat_terms(cat_terms, "cat_terms")
}
if (!is.null(notcat_terms)) {
notcat_terms <- check_cat_terms(notcat_terms, "notcat_terms")
}
result_query <- req_podcastindex() |>
httr2::req_url_path_append(
"recent",
"feeds"
)
if (!is.null(cat_terms) || !is.null(notcat_terms)) {
result_query <- result_query |>
httr2::req_url_query(
cat = cat_terms,
notcat = notcat_terms
) |>
httr2::req_url(utils::URLdecode(result_query$url))
result_query <- result_query |>
httr2::req_url_query(
max = max,
lang = lang,
since = since)
} else {
result_query <- result_query |>
httr2::req_url_query(
max = max,
lang = lang,
since = since,
cat = cat_terms,
notcat = notcat_terms)
}
result_raw <- httr2::req_perform(result_query)
res_df <- process_podcastindex_req(result_raw, "feeds")
return(res_df)
}
#' Get new podcast feeds
#'
#' @description feeds_recent()` retrieves the newest podcast feeds added
#' to the podcastindex over the past 24 hours.
#' @inheritParams feeds_recent
#' @param feedid string of the Podcastindex Feed ID to start from
#' (or go to if `desc` is set to TRUE). If `since` is specified, `feedid`
#' takes precedence.
#' @param desc boolean to display feeds in descending order. Only applicable
#' when specifying `feedid`.
#'
#' @return `tibble` data frame with metadata associated with new feeds
#' @export
#'
#' @examplesIf podindexr::podcastindex_api_isset()
#' # Requires API key and secret
#'
#' feeds_new(max = 20)
feeds_new <- function(max = 60, since = NULL, feedid = NULL, desc = FALSE) {
# perform checks for key parameters
max <- check_max(max)
if (!is.null(since)) {
since <- check_datetime(since)
}
if (desc) {
if (is.null(feedid)) {
cli::cli_abort("You must specify a {.arg feedid} when utilizing {.arg desc}.")
}
}
desc <- check_boolean(desc, "desc")
result_raw <- req_podcastindex() |>
httr2::req_url_path_append(
"recent",
"newfeeds"
) |>
httr2::req_url_query(
max = max,
since = since,
feedid = feedid,
desc = desc) |>
httr2::req_perform()
res_df <- process_podcastindex_req(result_raw, "feeds")
return(res_df)
}
#' Get podcast feeds supporting value tag
#'
#' `feeds_withvalue` obtains all feeds from the Podcast Index database that
#' support the `value` tag in the podcast namespace
#'
#' @return `tibble` data frame with metadata associated with feeds
#' @export
#'
#' @examples
#' \dontrun{
#' # Requires API key and secret
#'
#' feeds_withvalue()
#' }
feeds_withvalue <- function() {
result_raw <- req_podcastindex() |>
httr2::req_url_path_append(
"podcasts",
"bytag"
) |>
httr2::req_url_query(`podcast-value` = "") |>
httr2::req_perform()
res_df <- process_podcastindex_req(result_raw, "feed")
return(res_df)
}
#' Get podcast feeds by medium
#'
#' `feeds_bymedium` obtains all feeds marked with the specified medium tag
#' value.
#'
#' @param medium character string of medium to search for. Must be one of
#' `audiobook`, `blog`, `film`, `music`, `newsletter`, `podcast,` or `video`
#'
#' @return `tibble` data frame with metadata associated with feeds
#' @export
#'
#' @examples
#' \dontrun{
#' # Requires API key and secret
#'
#' feeds_bymedium(medium = "film")
#' }
feeds_bymedium <- function(medium = c("audiobook", "blog", "film", "music", "newsletter", "podcast", "video")) {
medium <- rlang::arg_match(medium)
result_raw <- req_podcastindex() |>
httr2::req_url_path_append(
"podcasts",
"bytag"
) |>
httr2::req_url_query(medium = medium) |>
httr2::req_perform()
res_df <- process_podcastindex_req(result_raw, "feed")
return(res_df)
}
#' Get trending podcast feeds
#'
#' `feeds_trending()` obtains the feeds in the Podcast Index that are trending.
#'
#' @inheritParams feeds_recent
#'
#' @return `tibble` data frame with metadata associated with feeds
#' @export
feeds_trending <- function(max = 10, lang = "en", since = NULL, cat_terms = NULL, notcat_terms = NULL) {
# perform checks for key parameters
max <- check_max(max)
if (!is.null(since)) {
since <- check_datetime(since)
}
if (!is.null(cat_terms)) {
cat_terms <- check_cat_terms(cat_terms, "cat_terms")
}
if (!is.null(notcat_terms)) {
notcat_terms <- check_cat_terms(notcat_terms, "notcat_terms")
}
result_query <- req_podcastindex() |>
httr2::req_url_path_append(
"podcasts",
"trending"
)
if (!is.null(cat_terms) || !is.null(notcat_terms)) {
result_query <- result_query |>
httr2::req_url_query(
cat = cat_terms,
notcat = notcat_terms
) |>
httr2::req_url(utils::URLdecode(result_query$url))
result_query <- result_query |>
httr2::req_url_query(
lang = lang,
max = max,
since = since)
} else {
result_query <- result_query |>
httr2::req_url_query(
lang = lang,
max = max,
since = since,
cat = cat_terms,
notcat = notcat_terms)
}
result_raw <- httr2::req_perform(result_query)
res_df <- process_podcastindex_req(result_raw, "feeds")
return(res_df)
}