Skip to content

Instantly share code, notes, and snippets.

@Yonaba
Created June 29, 2011 14:12
Show Gist options
  • Save Yonaba/1053909 to your computer and use it in GitHub Desktop.
Save Yonaba/1053909 to your computer and use it in GitHub Desktop.
Retrieve ID3 tags from MP3
--Custom function that collects ID3 tag from mp3 File
function getID3(filename)
local ID3 = {}
local file = assert(io.open(filename,"rb"))
file:seek("end")
file:seek("cur",-128)
ID3.TAG = file:read(3)
ID3.TITLE = file:read(30)
ID3.INTERPRET = file:read(30)
ID3.ALBUM = file:read(30)
ID3.YEAR = tonumber(file:read(4))
ID3.COMMENT = file:read(30)
file:close()
for k in pairs(ID3) do
if not ID3[k] then table.remove(ID3,k) end
end
return ID3
end
--Example
local tag = getID3("mp3.mp3")
for k,v in pairs(tag) do print(k,v) end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment