Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

mooney moonlighting hack nite mooning. moo.

  • Loading branch information...
commit b4120ba4576cf3a9e8fd91e1c0812cb89d216f5e 1 parent e5d6bad
@comotion authored
View
10 web/hangover.lua
@@ -12,7 +12,7 @@ local cache = ocash.new(hangover, cache_path)
local tracks = require "tracks"
local u = require "util"
local io = require "io"
-local md5 = require "md5"
+local crypto = require "crypto"
local meta = require "metadata"
require "config"
@@ -81,7 +81,7 @@ function getfile(file)
dest:close()
print("["..os.date("%c", t.submitted).. "] '"..t.filename.."' -> "..tname)
print("'"..t.filename .. "'".." " .. os.difftime(os.time(), t.submitted).."s")
- t.md5 = u.bintohex(md5.sum(bytes))
+ t.md5 = crypto.digest("md5", bytes)
local destname = t.md5..t.contenttype -- krav's pathless filename
t.path = tracks_path .. "/" .. destname
local rc, err = os.rename(tname, t.path)
@@ -100,17 +100,17 @@ function post_db(web,...)
if file then -- someone is uploading a mix
t, some = getfile(file)
-- attempt id3 extraction / file metadata
- tags, failure = gettags(t.path)
+ tags, failure = gettags(t.path, t)
if not tags then
return failure
end
print("'"..destname.. "'".." " .. os.difftime(os.time(), t.submitted).."s")
-- add to database, tags and all
- id = tracks:add({unpack(t), unpack(tags)})
+ id = tracks:add(tags)
-- add to database, tags and all
return json.encode{tracks=t,id=id,tags=tags}
elseif id then -- just editing the node
- tracks:put(id,web.POST)
+ return tracks:put(id,web.POST)
else -- not an upload, we have no id-ea
web.status = 400
return "Not enough, try harder."
View
23 web/lib/getracks.lua
@@ -12,7 +12,7 @@ package.path = package.path..";lib/?.lua;lib/?/?.lua"
local u = require "util"
local meta = require "metadata"
local tracks = require "tracks"
-local md5 = require "md5"
+local crypto = require "crypto"
local json = require "cjson"
local p = require "lamt.tagfrompath"
@@ -21,12 +21,21 @@ local BUFSIZE = 1048576
for path in io.lines() do
tag = {}
- local tag = meta.gettags(path)
- -- need to move the file to the proper place
- -- need to read the file to get the mdsum
- --tag.md5 = u.bintohex(md5.sum('abcdef'))
- -- should check if we have that hash
+ local initial = meta.pathstuff(path)
+ tag = meta.gettags(path, initial)
+ -- read the file to get the mdsum
+ md5 = crypto.digest.new("md5")
+ fd = io.open(path)
+ local block = fd:read(BUFSIZE)
+ while block do
+ md5:update(block)
+ block = fd:read(BUFSIZE)
+ end
+ tag.md5 = md5:final()
+ -- check if we have that hash
print(u.dump(tag))
- --id = tracks:add{unpack(tag),unpack{tag.tags}}
+ --id = tracks:add(tag)
+ -- move the file to the proper place
+ -- symlink to canonical name? (for ease)
end
View
8 web/lib/metadata.lua
@@ -16,15 +16,17 @@ function pathstuff(path)
-- initial title from path.. overwritten by tags
tag.title = tag.filename:gsub('_', ' ')
tag.path = path
+ tag.tagtype = 'none'
return tag
end
-function gettags(path)
- local initial = pathstuff(path)
+function gettags(path, initial)
local ok, intel, err = pcall(info, {path=path})
if not ok or not intel then
errcode = intel or err
- return nil, errcode, path
+ initial.tagtype = 'fail'
+ -- instead of nil, wrap error, don't want to delegate fails to caller
+ return initial, errcode, path
end
-- clean up tags, unpacking table{table} things
View
5 web/lib/tracks.lua
@@ -42,9 +42,14 @@ function tracks:add(cols)
local pkey = trk:genuid()
cols.added = os.time()
cols.station = cols.station or default_station
+ if cols.md5 then
+ id = tracks:ssearch({md5=md5})
+ if id then return id end
+ end
return tracks:put(pkey, cols)
end
+-- the simple search
function tracks:ssearch(query, qop, order)
local query = query or {station=default_station}
local qop = qop or db.op.equal
Please sign in to comment.
Something went wrong with that request. Please try again.