Permalink
Browse files

mellow monday tuesday sesshun

  • Loading branch information...
1 parent fdc38f0 commit a7d63c57698f54c473d4a01c6b05f46fde84a435 why committed Oct 16, 2012
Showing with 65 additions and 26 deletions.
  1. +4 −10 web/lib/getracks.lua
  2. +41 −16 web/lib/metadata.lua
  3. +20 −0 web/lib/util.lua
View
@@ -74,19 +74,13 @@ pat = {
end
for path in io.lines() do
+ tag = {}
local tag = meta.gettags(path)
- if tag then
- print(json.encode(tag))
- else
- tag = notag(path)
- tag.tagsource = "path"
- print( "NO TAG: " .. path)
- end
-- need to move the file to the proper place
- tag.path = path
-- need to read the file to get the mdsum
- tag.md5 = u.bintohex(md5.sum('abcdef'))
+ --tag.md5 = u.bintohex(md5.sum('abcdef'))
-- should check if we have that hash
- --id = tracks:add{unpack(info),unpack{info.tags}}
+ print(u.dump(tag))
+ --id = tracks:add{unpack(tag),unpack{tag.tags}}
end
View
@@ -1,25 +1,50 @@
module("metadata",package.seeall)
local types,info,edit = unpack(require ("lamt.mpeg"))
+-- XXX: need vstruct for ogg stuff!
+-- https://github.com/ToxicFrog/vstruct.git
+--local otypes, oinfo, oedit = unpack(require("lamt.ogg"))
+
local u = require "util"
+function pathstuff(path)
+ local tag = {}
+ local spa = u.split(path, '/')
+ spa = spa[#spa] -- drop path stuff
+ spa = u.split(spa, '.')
+ tag.extension = spa[#spa]
+ tag.filename = spa[1]
+ -- initial title from path.. overwritten by tags
+ tag.title = tag.filename:gsub('_', ' ')
+ tag.path = path
+ return tag
+end
+
function gettags(path)
- local ok, intel, err = pcall(info, {path=path})
- if not ok or not intel then
- errcode = intel or err
- return nil, errcode, path
- end
+ local initial = pathstuff(path)
+ local ok, intel, err = pcall(info, {path=path})
+ if not ok or not intel then
+ errcode = intel or err
+ return nil, errcode, path
+ end
- -- clean up tags, unpacking table{table} things
- tag = {}
- if not intel.tags then intel.tags = {} end
- for k,v in pairs(intel.tags) do
- if type(v) == "table" then
- v = u.join(v)
- tag[k] = v
- end
- end
- intel.tags = tag
- return intel
+ -- clean up tags, unpacking table{table} things
+ tag = {}
+ if not intel.tags then intel.tags = {} end
+ for k,v in pairs(intel.tags) do
+ if type(v) == "table" then
+ v = u.join(v)
+ tag[k] = v
+ end
+ end
+ -- merge in initial stuff
+ for k,v in pairs(initial) do
+ if not tag[k] then
+ tag[k] = v
+ end
+ end
+ intel.tags = tag
+ -- flatten out tags and extras
+ return u.flatten(intel)
end
return _M
View
@@ -11,6 +11,26 @@ function join(t, sep)
return table.concat(t,sep) --> "a,b,c"
end
+-- flatten table tree into table
+function flatten(t)
+ local flat = {}
+ for k,v in pairs(t) do
+ if (type(v) == "table") then
+ local realflat = flatten(v)
+ -- merge it in
+ for sk,sv in pairs(realflat) do
+ if not flat[sk] then
+ flat[sk] = sv
+ end
+ end
+ else
+ flat[k] = v
+ end
+ end
+ return flat
+end
+
+
-- dump a table
function dump(o)
local s = ''

0 comments on commit a7d63c5

Please sign in to comment.