~hrbrmstr/wand

wand/tools/build-ext-db.R -rw-r--r-- 792 bytes
1f89bed4boB Rudis NEWS 1 year, 3 months ago
                                                                                
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
library(tidyverse)

a <- jsonlite::fromJSON("https://s-randomfiles.s3.amazonaws.com/mime/allMimeTypes.json")
b <- jsonlite::fromJSON("https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json")

aa <- map(a, compact)
aa <- keep(aa, lengths(aa)>0)

bb <- keep(b, ~"extensions" %in% names(.x))

map_df(names(aa), ~{
  tibble(
    extension = aa[[.x]],
    mime_type = .x
  ) %>% unnest()
}) -> aa_df

map_df(names(bb), ~{
  tibble(
    extension = bb[[.x]][["extensions"]],
    mime_type = .x
  ) %>% unnest()
}) -> bb_df

bind_rows(aa_df, bb_df, read_csv("tools/orig-db.csv", col_types = "cc")) %>%
  distinct() %>%
  arrange(extension, mime_type) %>%
  mutate_all(as.character) %>%
  mutate_all(trimws) -> simplemagic_mime_db

use_data(simplemagic_mime_db, internal = TRUE, overwrite = TRUE)