Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds many podcast 2.0 namespace tags #56

Merged
merged 9 commits into from
Mar 5, 2023
16 changes: 14 additions & 2 deletions R/atom_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ atom_parse <- function(response, list, clean_tags, parse_dates) {
# get default namespace
ns_entry <- xml_ns(res) %>% attributes() %>% .[[1]] %>% .[[1]]

# metadata: id, title, updated necessary
# metadata: id, title, updated necessary,
metadata <- tibble(
feed_title = xml_find_first(res, glue("{ns_entry}:title")) %>% xml_text(),
feed_url = xml_find_first(res, glue("{ns_entry}:id")) %>% xml_text(),
Expand All @@ -18,7 +18,18 @@ atom_parse <- function(response, list, clean_tags, parse_dates) {
link <- xml_find_first(res, glue("{ns_entry}:link")) %>% xml_attr("href")
meta_optional <- tibble(
feed_author = safe_run(res, "first", glue("{ns_entry}:author")),
feed_link = ifelse(!is.null(link), link, def),
feed_transcript = safe_run(res, "first", glue("{ns_entry}:transcript")),
feed_locked = safe_run(res, "first", glue("{ns_entry}:locked")),
feed_funding = safe_run(res, "first", glue("{ns_entry}:funding")),
feed_chapters = safe_run(res, "first", glue("{ns_entry}:chapters")),
feed_soundbite = safe_run(res, "first", glue("{ns_entry}:soundbite")),
feed_person = safe_run(res, "first", glue("{ns_entry}:person")),
feed_location = safe_run(res, "first", glue("{ns_entry}:location")),
feed_season = safe_run(res, "first", glue("{ns_entry}:season")),
feed_episode = safe_run(res, "first", glue("{ns_entry}:episode")),
feed_value = safe_run(res, "first", glue("{ns_entry}:value")),
feed_link = safe_run(res, "first", glue("{ns_entry}:link")),
feed_images = safe_run(res, "first", glue("{ns_entry}:images")),
feed_category = list(category = safe_run(res, "first", glue("{ns_entry}:category"))),
feed_generator = safe_run(res, "first", glue("{ns_entry}:generator")),
feed_icon = safe_run(res, "first", glue("{ns_entry}:icon")),
Expand All @@ -38,6 +49,7 @@ atom_parse <- function(response, list, clean_tags, parse_dates) {
entry_url = safe_run(res_entry, "all", glue("{ns_entry}:id")),
entry_last_updated = safe_run(res_entry, "all", glue("{ns_entry}:updated")),
entry_author = safe_run(res_entry, "all", glue("{ns_entry}:author")),
entry_enclosure = safe_run(res_entry, "all", glue("{ns_entry}:enclosure")),
entry_content = safe_run(res_entry, "all", glue("{ns_entry}:content")),
entry_link = ifelse(!is.null(e_link), e_link, def),
entry_summary = safe_run(res_entry, "all", glue("{ns_entry}:summary")),
Expand Down
7 changes: 6 additions & 1 deletion R/json_parse.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
json_parse <- function(response, list, clean_tags, parse_dates) {
# spec here: https://jsonfeed.org/version/1
# spec here: https://jsonfeed.org/version/1.1/
res <- parse_json(response)
items <- res$items

Expand All @@ -10,6 +10,9 @@ json_parse <- function(response, list, clean_tags, parse_dates) {
description = return_exists(res$description),
feed_author = return_exists(res$author$name),
feed_author_url = return_exists(res$author$url),
next_url = return_exists(res$next_url),
language = return_exists(res$language),
expired = return_exists(res$expired),
icon = return_exists(res$icon),
favicon = return_exists(res$favicon),
expired = return_exists(res$expired)
Expand All @@ -23,12 +26,14 @@ json_parse <- function(response, list, clean_tags, parse_dates) {
item_url = map_chr(items, "url", .default = def),
item_external_url = map_chr(items, "external_url", .default = def),
item_author = map(items, "author", .default = def),
item_authors = map(items, "authors", .default = def),
item_content_html = map_chr(items, "content_html", .default = def),
item_content_text = map_chr(items, "content_text", .default = def),
item_summary = map_chr(items, "summary", .default = def),
item_image = map_chr(items, "image", .default = def),
item_banner_image = map_chr(items, "banner_image", .default = def),
item_tags = map_chr(items, "tags", .default = def),
item_language = map_chr(items, "language", .default = def),
)

for (i in seq_len(nrow(entries))) {
Expand Down
17 changes: 16 additions & 1 deletion R/rss_parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ rss_parse <- function(response, list, clean_tags, parse_dates) {
xml_text()
)
# optional metadata: language, copyright, managingEditor, webMaster, pubDate,
# lastBuildDate; category, generator, docs, cloud, ttl, image, textInput,
# lastBuildDate; category, generator, docs, cloud, link, managingEditor,
# podcast:guid, podcast:license, podcast:locked, podcast:funding,
# podcast:location, podcast:trailer, ttl, image, textInput,
# skipHours, skipDays
meta_optional <- tibble(
feed_language = safe_run(channel, "first", "//*[name()='language']"),
Expand All @@ -27,6 +29,15 @@ rss_parse <- function(response, list, clean_tags, parse_dates) {
)),
feed_generator = safe_run(channel, "first", "//*[name()='generator']"),
feed_docs = safe_run(channel, "first", "//*[name()='docs']"),
feed_link = safe_run(channel, "first", "//*[name()='link']"),
feed_managingEditor = safe_run(channel, "first", "//*[name()='managingEditor']"),
feed_webMaster = safe_run(channel, "first", "//*[name()='webMaster']"),
feed_guid = safe_run(channel, "first", "//*[name()='podcast:guid']"),
feed_license = safe_run(channel, "first", "//*[name()='podcast:license']"),
feed_locked = safe_run(channel, "first", "//*[name()='podcast:locked']"),
feed_funding = safe_run(channel, "first", "//*[name()='podcast:funding']"),
feed_location = safe_run(channel, "first", "//*[name()='podcast:location']"),
feed_trailer = safe_run(channel, "first", "//*[name()='podcast:trailer']"),
feed_ttl = safe_run(channel, "first", "//*[name()='ttl']")
)
meta <- bind_cols(metadata, meta_optional)
Expand All @@ -43,6 +54,10 @@ rss_parse <- function(response, list, clean_tags, parse_dates) {
item_pub_date = map(res_entry, "pubDate", .default = def) %>% unlist(),
item_guid = map(res_entry, "guid", .default = def) %>% unlist(),
item_author = map(res_entry, "author", .default = def),
item_enclosure = map(res_entry, "enclosure", .default = def),
item_season = map(res_entry, "podcast:season", .default = def),
item_episode = map(res_entry, "podcast:episode", .default = def),
item_enclosure = map(res_entry, "enclosure", .default = def),
item_category = map(res_entry_xml, ~ {
xml_find_all(.x, "category") %>% map(xml_text)
}),
Expand Down