~ubuntu-branches/ubuntu/intrepid/luatex/intrepid

« back to all changes in this revision

Viewing changes to src/libs/luasocket/samples/cddb.lua

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2008-07-07 11:01:13 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707110113-1y7lam37zbbb7bbt
Tags: 0.28.0-1
* two new upstream releases, see the respective ANNOUCE files
* add luasocket license statement to debian/copyright
* activate the pdfluatex format
* prepare for latex based formats
  - add the ini files from TeX Live
  - add debian/formats file
  - adjust dh_installtex incantation
  the problem is that luatex dies when loading ukrhypmp.tex from 
  texlive-lang-cyrillic, but we don't want to conflict with it by now.
* policy 3.8.0, rename README.Debian-source to README.source, and add
  notes about quilt usage
* disable patch fix-pwd-inclusion (it was from svn)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
local socket = require("socket")
 
2
local http = require("socket.http")
 
3
 
 
4
if not arg or not arg[1] or not arg[2] then
 
5
    print("luasocket cddb.lua <category> <disc-id> [<server>]")
 
6
    os.exit(1)
 
7
end
 
8
 
 
9
local server = arg[3] or "http://freedb.freedb.org/~cddb/cddb.cgi"
 
10
 
 
11
function parse(body)
 
12
    local lines = string.gfind(body, "(.-)\r\n")
 
13
    local status = lines()
 
14
    local code, message = socket.skip(2, string.find(status, "(%d%d%d) (.*)"))
 
15
    if tonumber(code) ~= 210 then
 
16
        return nil, code, message
 
17
    end
 
18
    local data = {}
 
19
    for l in lines do
 
20
        local c = string.sub(l, 1, 1)
 
21
        if c ~= '#' and c ~= '.' then
 
22
            local key, value = socket.skip(2, string.find(l, "(.-)=(.*)"))
 
23
            value = string.gsub(value, "\\n", "\n")
 
24
            value = string.gsub(value, "\\\\", "\\")
 
25
            value = string.gsub(value, "\\t", "\t")
 
26
            data[key] = value
 
27
        end
 
28
    end
 
29
    return data, code, message 
 
30
end
 
31
 
 
32
local host = socket.dns.gethostname()
 
33
local query = "%s?cmd=cddb+read+%s+%s&hello=LuaSocket+%s+LuaSocket+2.0&proto=6"
 
34
local url = string.format(query, server, arg[1], arg[2], host)
 
35
local body, headers, code = http.get(url)
 
36
 
 
37
if code == 200 then
 
38
    local data, code, error = parse(body)
 
39
    if not data then
 
40
        print(error or code)
 
41
    else
 
42
        for i,v in pairs(data) do
 
43
            io.write(i, ': ', v, '\n')
 
44
        end
 
45
    end
 
46
else print(error) end