summaryrefslogtreecommitdiff
path: root/apps/plugins/lua_scripts
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2019-09-06 19:24:26 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2019-09-07 03:10:59 +0200
commit267d04d2bd2a7681c8bbcfbb655612101440b765 (patch)
treea518b4c10244cc77a5eee636132031c5a542c00a /apps/plugins/lua_scripts
parenta3cbd86a5193e5227344db360f45f114fda10aab (diff)
downloadrockbox-267d04d2bd2a7681c8bbcfbb655612101440b765.tar.gz
rockbox-267d04d2bd2a7681c8bbcfbb655612101440b765.zip
Lua add metadata and settings reading helper module
Adds example scripts for reading track metadata + dumping albumart and rockbox settings settings are now stored as a table of strings rather than a table of tables as it saves ~15 kb of ram without adding much complexity Change-Id: I611c312b2a60ab96e595e4710b17aedbd6c0689b
Diffstat (limited to 'apps/plugins/lua_scripts')
-rw-r--r--apps/plugins/lua_scripts/dump_rbsettings.lua49
-rw-r--r--apps/plugins/lua_scripts/track_metadata.lua90
2 files changed, 139 insertions, 0 deletions
diff --git a/apps/plugins/lua_scripts/dump_rbsettings.lua b/apps/plugins/lua_scripts/dump_rbsettings.lua
new file mode 100644
index 0000000000..2811d27487
--- /dev/null
+++ b/apps/plugins/lua_scripts/dump_rbsettings.lua
@@ -0,0 +1,49 @@
1require("rbsettings")
2require("settings")
3rb.metadata = nil -- remove track metadata settings
4-------------------------------------------------------------------------------
5
6local function print_setting_table(t_tbl, s_sep)
7 s_sep = s_sep or ""
8 local str = ""
9 local function pfunct(t, sep, s, n) -- recursive print function
10 local vtype
11 for k, v in pairs(t) do
12 vtype = type(v)
13 if vtype == "table" then
14 local f = string.format("%s[%s]", n, k)
15 s = pfunct(v, sep, s, f)
16 elseif vtype == "boolean" then
17 v = v and "true" or "false"
18 s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep)
19 elseif v then
20 s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep)
21 end
22 end
23 return s
24 end
25 return pfunct(t_tbl, s_sep, str, "")
26end
27
28local filename = "/settings.txt"
29local file = io.open(filename, "w+") -- overwrite
30local t_settings
31
32if not file then
33 rb.splash(rb.HZ, "Error writing " .. filename)
34 return
35end
36
37t_settings = rb.settings.dump('global_settings', "system")
38file:write("global_settings:\n")
39file:write(print_setting_table(t_settings, "\n"))
40file:write("\n\n")
41
42t_settings = rb.settings.dump('global_status', "system")
43file:write("global_status:\n")
44file:write(print_setting_table(t_settings, "\n"))
45file:write("\n\n")
46
47file:close()
48
49rb.splash(100, "rb settings dumped: " .. filename)
diff --git a/apps/plugins/lua_scripts/track_metadata.lua b/apps/plugins/lua_scripts/track_metadata.lua
new file mode 100644
index 0000000000..08c1c865f3
--- /dev/null
+++ b/apps/plugins/lua_scripts/track_metadata.lua
@@ -0,0 +1,90 @@
1require("rbsettings")
2require("settings") --settings.lua
3rb.system = nil -- remove system settings
4-------------------------------------------------------------------------------
5local track_data = rb.metadata.mp3_entry
6local cur_trk = "audio_current_track"
7-------------------------------------------------------------------------------
8local trackname = rb.settings.read(cur_trk, track_data.title) or
9 rb.settings.read(cur_trk, track_data.path)
10if not trackname or trackname == "" then
11 os.exit(1, "No track loaded")
12else
13 rb.splash(100, trackname)
14end
15-------------------------------------------------------------------------------
16local function dump_albumart(fileout)
17 local t_albumart = rb.settings.read(cur_trk, track_data.albumart, "metadata")
18 local t_aaext = {".bmp",".png", ".jpg"}
19 local path = rb.settings.read(cur_trk, track_data.path)
20 if t_albumart.pos > 0 and t_albumart.size > 0 and t_albumart.type > 0 then
21
22 if t_aaext[t_albumart.type] then
23 local filename = "/" .. fileout .. t_aaext[t_albumart.type]
24 local aa = io.open(filename, "w+") -- overwrite
25 if not aa then
26 rb.splash(rb.HZ, "Error writing " .. filename)
27 return
28 end
29
30 local track = io.open(path, "r")
31 if not track then
32 rb.splash(rb.HZ, "Error opening " .. path)
33 return
34 end
35 track:seek("set", t_albumart.pos )
36 for i = 0, t_albumart.size, 32 do
37 aa:write(track:read(32))
38 end
39 rb.splash(rb.HZ, "Saved: " .. filename)
40 track:close()
41 aa:close()
42 else
43
44 end
45 end
46end
47
48local function print_setting_table(t_tbl, s_sep)
49 s_sep = s_sep or ""
50 local str = ""
51 local function pfunct(t, sep, s, n) -- recursive print function
52 local vtype
53 for k, v in pairs(t) do
54 vtype = type(v)
55 if vtype == "table" then
56 local f = string.format("%s[%s]", n, k)
57 s = pfunct(v, sep, s, f)
58 elseif vtype == "boolean" then
59 v = v and "true" or "false"
60 s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep)
61 elseif v then
62 s = string.format("%s%s[%s] = %s%s", s, n, k, v, sep)
63 end
64 end
65 return s
66 end
67 return pfunct(t_tbl, s_sep, str, "")
68end
69
70local filename = "/metadata.txt"
71local file = io.open(filename, "w+") -- overwrite
72local t_settings
73
74if not file then
75 rb.splash(rb.HZ, "Error writing " .. filename)
76 return
77end
78
79---[[
80t_settings = rb.settings.dump(cur_trk, "metadata", "mp3_entry")
81file:write(trackname .. ":\n")
82file:write(print_setting_table(t_settings, "\n"))
83file:write("\n\n")
84file:close()
85
86rb.splash(100, "metadata dumped: " .. filename)
87
88if rb.settings.read(cur_trk, track_data.has_embedded_albumart) then
89 dump_albumart("/albumart")
90end