Reputation: 25326
I've got a bunch of audio files (let's say ogg or mp3), with metadata.
I wish to read their metadata into R so to create a data.frame with:
Any way you know of for doing that ?
Upvotes: 3
Views: 2734
Reputation: 12528
As suggested in this answer, you can use exiftool.
To use it within R, you can use exifr
(exiftoolr
is also good):
# download a public domain mp3 file from The Internet Archive
download.file("https://archive.org/download/Jazz_Sampler-9619/Kevin_MacLeod_-_AcidJazz.mp3", "jazz.mp3", mode = "wb")
install.packages("exifr") # if necessary
exifr::read_exif("jazz.mp3") |>
mutate(location = ls()) |> # this is assuming that the file is in the working directory. If not, then you want to replace ls() with "Directory"
select(name = SourceFile,
location,
artist = Artist,
album = Album)
# Output:
# A tibble: 1 × 4
name location artist album
<chr> <chr> <chr> <chr>
1 jazz.mp3 ~ Kevin MacLeod Jazz Sampler
Upvotes: 2
Reputation: 712
Out here in 2021, I wanted to do this so I did the following...
Upvotes: 0
Reputation: 36080
You can use exiftool
with system
command available in R. Optionally, you can create regexp to handle the fields you need... If I were you, I'd stick with Dirk's advice (as usual) =)!
Upvotes: 1
Reputation: 108537
Possible, yes, easy, no.
You "could" use a combination of readChar and/or readBin on the file and parse out the contents. This would be highly dependent, though, on parsing the frame tags from the raw bytes of the ID3v2 tag (and mind you it would change if it was a version 1 tag). If would certainly be a lot of work to implement a straight R solution. Take this Python code for example, it's very clean straight python code but a lot of branching and parsing.
Upvotes: 1
Reputation: 368261
You take an existing mp3 or ogg client, look at what library it uses and then write a binding for said library to R, using the existing client as guide for that side -- and something like Rcpp as a guide on the other side to show you how to connect C/C++ libraries to R.
No magic bullet.
A cheaper and less reliable way is to use a cmdline tool that does what you want and write little helper functions that use system()
to run that tool over the file, re-reading the output in R. Not pretty, not reliable, but possibly less challenging.
Upvotes: 3