diff options
Diffstat (limited to 'apps/plugins/lua/include_lua/playlist.lua')
-rw-r--r-- | apps/plugins/lua/include_lua/playlist.lua | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/apps/plugins/lua/include_lua/playlist.lua b/apps/plugins/lua/include_lua/playlist.lua new file mode 100644 index 0000000000..3952334d9b --- /dev/null +++ b/apps/plugins/lua/include_lua/playlist.lua | |||
@@ -0,0 +1,80 @@ | |||
1 | --[[ Lua RB Playlist Operations | ||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2018 William Wilgus | ||
12 | * | ||
13 | * This program is free software; you can redistribute it and/or | ||
14 | * modify it under the terms of the GNU General Public License | ||
15 | * as published by the Free Software Foundation; either version 2 | ||
16 | * of the License, or (at your option) any later version. | ||
17 | * | ||
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
19 | * KIND, either express or implied. | ||
20 | * | ||
21 | ****************************************************************************/ | ||
22 | ]] | ||
23 | |||
24 | -- [[ conversion to old style playlist_ functions ]] | ||
25 | if not rb.playlist then rb.splash(rb.HZ, "No Support!") return nil end | ||
26 | |||
27 | rb.playlist_amount = function() | ||
28 | return rb.playlist("amount") | ||
29 | end | ||
30 | rb.playlist_add = function (filename) | ||
31 | return rb.playlist("add", filename) | ||
32 | end | ||
33 | rb.playlist_create = function(dir, filename) | ||
34 | return rb.playlist("create", dir, filename) | ||
35 | end | ||
36 | rb.playlist_start = function(index, elapsed, offset) | ||
37 | rb.playlist("start", index, elapsed, offset) | ||
38 | end | ||
39 | rb.playlist_resume_track = function(index, crc, elapsed, offset) | ||
40 | rb.playlist("resumetrack", index, crc, elapsed, offset) | ||
41 | end | ||
42 | rb.playlist_resume = function() return rb.playlist("resume") end | ||
43 | rb.playlist_shuffle = function(random_seed, index) | ||
44 | rb.playlist("shuffle", random_seed, index) | ||
45 | end | ||
46 | rb.playlist_sync = function () rb.playlist("sync") end | ||
47 | rb.playlist_remove_all_tracks = function() return rb.playlist("removealltracks") end | ||
48 | rb.playlist_insert_track = function(filename, pos, bqueue, bsync) | ||
49 | return rb.playlist("inserttrack", filename, pos, bqueue, bsync) | ||
50 | end | ||
51 | rb.playlist_insert_directory = function(dir, pos, bqueue, brecurse) | ||
52 | return rb.playlist("insertdirectory", dir, pos, bqueue, brecurse) | ||
53 | end | ||
54 | rb.playlist_tracks = function(dir, filename) | ||
55 | local tracks = {} | ||
56 | local count = 0 | ||
57 | local fullpath = dir .. "/" .. filename | ||
58 | local file = io.open('/' .. fullpath, "r") | ||
59 | |||
60 | if not file then | ||
61 | rb.splash(rb.HZ, "Error opening /" .. fullpath) | ||
62 | return tracks | ||
63 | end | ||
64 | |||
65 | -- strip BOM --"\xEF\xBB\xBF" | ||
66 | local bom = file:read(3) | ||
67 | if not string.find(bom, "\239\187\191") then | ||
68 | file:seek("set", 0) | ||
69 | end | ||
70 | |||
71 | for line in file:lines() do | ||
72 | if string.len(line) > 3 and (not string.find(line, "%s*#.*")) then | ||
73 | count = count + 1 | ||
74 | tracks[count] = line | ||
75 | end | ||
76 | end | ||
77 | file:close() | ||
78 | return tracks | ||
79 | end | ||
80 | |||