mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41:00 +00:00
Uploads WIP
This commit is contained in:
parent
da7a54a1c3
commit
65bf0c0c8a
1 changed files with 38 additions and 0 deletions
38
lib/live_beats/id3.ex
Normal file
38
lib/live_beats/id3.ex
Normal file
|
@ -0,0 +1,38 @@
|
|||
defmodule LiveBeats.ID3 do
|
||||
alias LiveBeats.ID3
|
||||
|
||||
defstruct title: nil,
|
||||
artist: nil,
|
||||
album: nil,
|
||||
year: nil
|
||||
|
||||
def parse(path) do
|
||||
binary = File.read!(path)
|
||||
size = byte_size(binary) - 128
|
||||
<<_::binary-size(size), id3_tag::binary>> = binary
|
||||
|
||||
case id3_tag do
|
||||
<<
|
||||
"TAG",
|
||||
title::binary-size(30),
|
||||
artist::binary-size(30),
|
||||
album::binary-size(30),
|
||||
year::binary-size(4),
|
||||
_comment::binary-size(30),
|
||||
_rest::binary
|
||||
>> ->
|
||||
{:ok,
|
||||
%ID3{
|
||||
title: strip(title),
|
||||
artist: strip(artist),
|
||||
album: strip(album),
|
||||
year: year
|
||||
}}
|
||||
|
||||
_invalid ->
|
||||
{:error, :invalid}
|
||||
end
|
||||
end
|
||||
|
||||
defp strip(binary), do: String.trim_trailing(binary, <<0>>)
|
||||
end
|
Loading…
Reference in a new issue