-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomiclib.lua
More file actions
49 lines (35 loc) · 1.11 KB
/
comiclib.lua
File metadata and controls
49 lines (35 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
local Archiver = require("ffi/archiver")
local XmlObject = require("comicxml")
local ComicInfo = {}
function ComicInfo:new(archive_path)
local arc = Archiver.Reader:new()
local xml_content = nil
-- Save current locale and set locale to a "implementation-defined native locale"
local locale = os.setlocale(nil, "all")
os.setlocale("", "all")
if arc:open(archive_path) then
for entry in arc:iterate() do
if entry.mode == "file" and entry.path == "ComicInfo.xml" then
xml_content = arc:extractToMemory(entry.index)
break
end
end
arc:close()
end
-- Restore previous locale
os.setlocale(locale, "all")
if not xml_content or #xml_content == 0 then
return nil, false
end
local parser = XmlObject:new()
local root = parser:parse(xml_content)
local comic_metadata = parser:toTable(root)
local o = {
archive_path = archive_path,
metadata = comic_metadata,
}
setmetatable(o, self)
self.__index = self
return o, true
end
return { ComicInfo = ComicInfo }