How to read and write id3v1 and id3v2 tags in Elixir

I would like to scan music files and read / write metadata using Elixir (this entire project is dedicated to learning Elixir - so please don't tell me to use Python!). As far as I understand, I have two options: to call the system utility or (since there are no libraries in Erlang or Elixir), write the Elixir library. For m4a files, I make an MP4Box system call and write the xml file to disk. Then I read in the file, parse it and load the data into the database.

def parse(file_name) do System.cmd("MP4Box", ["-diso",file_name]) Ainur.XmlParser.parse(xml_file_name(file_name)) |> get_tags end 

Very slow, especially for thousands of files. And I want it to run on every start to check for changed / new files.

Now I'm trying to do the same for mp3 with id3 tags. I tried libid3-tools on Ubuntu and found only id3v1 tags. eyeD3 detected only id3v2 tags. My mp3 has both, so I need to make sure they are the same (I suppose I could remove the id3v1 tags, but I was convinced that the id3v1 tags are necessary for outdated equipment).

Are there Erlang or Elixir libraries for musical metadata? If not, are system calls the ubuntu utilities the best choice (any recommendations for them)?

Or do I need to write a library to get reasonable performance? If so, is there an existing library in a functional language that I could try to execute?

Or can you call a library written in another language directly from Elixir (without a system call)?

+6
source share
4 answers

You can always use erlang NIF ( http://erlang.org/doc/tutorial/nif.html ) to wrap an external library

+1
source

In this project, we have a module written in Elixir that extracts ID3 tags from mp3:

https://github.com/anisiomarxjr/shoutcast_server/blob/master/lib/mp3_file.ex

For use:

 id3 = Mp3File.extract_id3("./test/fixtures/nederland.mp3") 
+1
source

You can also try reading the binary file directly to find the corresponding tag.

Check this out to start with: http://elixir-lang.org/docs/v1.0/elixir/File.html#stream!/3

0
source

I implemented reading the ID3v2 tag (not writing) in Elixir. This is on GitHub and Hex .

The support is very simple; I have met the minimum minimum to support my use case. There are many mistakes, but all the building blocks are there to develop / improve / contribute.

0
source

Source: https://habr.com/ru/post/987804/


All Articles