summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/lua/mtx-flac.lua
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
committerKarl Berry <karl@freefriends.org>2013-04-08 00:43:40 +0000
commit824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch)
treeabfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/scripts/context/lua/mtx-flac.lua
parent689aefb0727676ed3cddf331337b4be226495e72 (diff)
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/context/lua/mtx-flac.lua')
-rw-r--r--Master/texmf-dist/scripts/context/lua/mtx-flac.lua70
1 files changed, 46 insertions, 24 deletions
diff --git a/Master/texmf-dist/scripts/context/lua/mtx-flac.lua b/Master/texmf-dist/scripts/context/lua/mtx-flac.lua
index 37f985654a3..2155b24becb 100644
--- a/Master/texmf-dist/scripts/context/lua/mtx-flac.lua
+++ b/Master/texmf-dist/scripts/context/lua/mtx-flac.lua
@@ -6,17 +6,15 @@ if not modules then modules = { } end modules ['mtx-flac'] = {
license = "see context related readme files"
}
--- Written with Within Temptation's "The Unforgiven" in loopmode on
--- the speakers. The following code is also used for my occasional music
--- repository cleanup session using the code below.
-
--- this can become l-flac.lua
-
local sub, match, byte, lower = string.sub, string.match, string.byte, string.lower
local readstring, readnumber = io.readstring, io.readnumber
-local concat = table.concat
+local concat, sortedpairs = table.concat, table.sortedpairs
local tonumber = tonumber
local tobitstring = number.tobitstring
+local lpegmatch = lpeg.match
+local p_escaped = lpeg.patterns.xml.escaped
+
+-- rather silly: pack info in bits while a flac file is large anyway
flac = flac or { }
@@ -25,7 +23,7 @@ flac.report = string.format
local splitter = lpeg.splitat("=")
local readers = { }
-readers[0] = function(f,size,target) -- not yet ok
+readers[0] = function(f,size,target) -- not yet ok .. todo: use bit32 lib
local info = { }
target.info = info
info.minimum_block_size = readnumber(f,-2)
@@ -78,6 +76,7 @@ function flac.getmetadata(filename)
local reader = readers[flag] or readers.default
reader(f,size,data,banner)
if last then
+ f:close()
return data
end
end
@@ -127,28 +126,29 @@ function flac.savecollection(pattern,filename)
local nofartists, nofalbums, noftracks, noferrors = 0, 0, 0, 0
local f = io.open(filename,"wb")
if f then
+ flac.report("saving data in file %q",filename)
f:write("<?xml version='1.0' standalone='yes'?>\n\n")
f:write("<collection>\n")
- for artist, albums in table.sortedpairs(music) do
+ for artist, albums in sortedpairs(music) do
nofartists = nofartists + 1
f:write("\t<artist>\n")
- f:write("\t\t<name>" .. artist .. "</name>\n")
+ f:write("\t\t<name>",lpegmatch(p_escaped,artist),"</name>\n")
f:write("\t\t<albums>\n")
- for album, data in table.sortedpairs(albums) do
+ for album, data in sortedpairs(albums) do
nofalbums = nofalbums + 1
- f:write("\t\t\t<album year='" .. (data.year or 0) .. "'>\n")
- f:write("\t\t\t\t<name>" .. album .. "</name>\n")
+ f:write("\t\t\t<album year='",data.year or 0,"'>\n")
+ f:write("\t\t\t\t<name>",lpegmatch(p_escaped,album),"</name>\n")
f:write("\t\t\t\t<tracks>\n")
local tracks = data.tracks
for i=1,#tracks do
local track = tracks[i]
if track then
noftracks = noftracks + 1
- f:write("\t\t\t\t\t<track length='" .. track.length .. "'>" .. track.title .. "</track>\n")
+ f:write("\t\t\t\t\t<track length='",track.length,"'>",lpegmatch(p_escaped,track.title),"</track>\n")
else
noferrors = noferrors + 1
- flac.report("error in album: %q of artist",album,artist)
- f:write("\t\t\t\t\t<error track='" .. i .. "'/>\n")
+ flac.report("error in album: %q of %q, no track %s",album,artist,i)
+ f:write("\t\t\t\t\t<error track='",i,"'/>\n")
end
end
f:write("\t\t\t\t</tracks>\n")
@@ -158,20 +158,40 @@ function flac.savecollection(pattern,filename)
f:write("\t</artist>\n")
end
f:write("</collection>\n")
+ f:close()
+ flac.report("%s tracks of %s albums of %s artists saved in %q (%s errors)",noftracks,nofalbums,nofartists,filename,noferrors)
+ else
+ flac.report("unable to save data in file %q",filename)
end
- f:close()
- flac.report("%s tracks of %s albums of %s artists saved in %q (%s errors)",noftracks,nofalbums,nofartists,filename,noferrors)
end
--
local helpinfo = [[
---collect collect albums in xml file
-
-example:
-
-mtxrun --script flac --collect somename.flac
-mtxrun --script flac --collect --pattern="m:/music/**")
+<?xml version="1.0"?>
+<application>
+ <metadata>
+ <entry name="name">mtx-flac</entry>
+ <entry name="detail">ConTeXt Flac Helpers</entry>
+ <entry name="version">0.10</entry>
+ </metadata>
+ <flags>
+ <category name="basic">
+ <subcategory>
+ <flag name="collect"><short>collect albums in xml file</short></flag>
+ </subcategory>
+ </category>
+ </flags>
+ <examples>
+ <category>
+ <title>Example</title>
+ <subcategory>
+ <example><command>mtxrun --script flac --collect somename.flac</command></example>
+ <example><command>mtxrun --script flac --collect --pattern="m:/music/**")</command></example>
+ </subcategory>
+ </category>
+ </examples>
+</application>
]]
local application = logs.application {
@@ -211,6 +231,8 @@ end
if environment.argument("collect") then
scripts.flac.collect()
+elseif environment.argument("exporthelp") then
+ application.export(environment.argument("exporthelp"),environment.files[1])
else
application.help()
end