diff options
| author | William Wilgus <me.theuser@yahoo.com> | 2018-10-24 21:40:01 -0400 |
|---|---|---|
| committer | William Wilgus <me.theuser@yahoo.com> | 2018-10-25 05:59:42 -0400 |
| commit | e4c5f5d412d94b10545980eea0b47d98e79712da (patch) | |
| tree | 407022885faeda259ab40192dd74cae1a477f3f3 /apps/plugins/lua/include_lua | |
| parent | b670fcd50d42085a2db978bbcf2ccfd889d740ef (diff) | |
| download | rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.zip rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.tar.gz rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.tar.bz2 rockbox-e4c5f5d412d94b10545980eea0b47d98e79712da.tar.xz | |
lua consolidate playlist_ functions
The way to call the playlist functions has changed
rb.playlist("option", var)
rb.playlist_add(filename) = becomes rb.playlist("add", filename)
added playlist.lua to the includes for conversion to old functions
if your script is broken by this change you simply add `require("playlist")`
to the top for the old functionality
added rb.playlist_tracks(dir, filename) to playlist.lua
this will allow you to add all tracks in a playlist.m3u8
to a lua table
Change-Id: I87fcc56be365d8495d214f069331b6ddbfbef1db
Diffstat (limited to 'apps/plugins/lua/include_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 0000000..3952334 --- /dev/null +++ b/apps/plugins/lua/include_lua/playlist.lua @@ -0,0 +1,80 @@ +--[[ Lua RB Playlist Operations +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2018 William Wilgus + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +]] + +-- [[ conversion to old style playlist_ functions ]] +if not rb.playlist then rb.splash(rb.HZ, "No Support!") return nil end + +rb.playlist_amount = function() + return rb.playlist("amount") + end +rb.playlist_add = function (filename) + return rb.playlist("add", filename) + end +rb.playlist_create = function(dir, filename) + return rb.playlist("create", dir, filename) + end +rb.playlist_start = function(index, elapsed, offset) + rb.playlist("start", index, elapsed, offset) + end +rb.playlist_resume_track = function(index, crc, elapsed, offset) + rb.playlist("resumetrack", index, crc, elapsed, offset) + end +rb.playlist_resume = function() return rb.playlist("resume") end +rb.playlist_shuffle = function(random_seed, index) + rb.playlist("shuffle", random_seed, index) + end +rb.playlist_sync = function () rb.playlist("sync") end +rb.playlist_remove_all_tracks = function() return rb.playlist("removealltracks") end +rb.playlist_insert_track = function(filename, pos, bqueue, bsync) + return rb.playlist("inserttrack", filename, pos, bqueue, bsync) + end +rb.playlist_insert_directory = function(dir, pos, bqueue, brecurse) + return rb.playlist("insertdirectory", dir, pos, bqueue, brecurse) + end +rb.playlist_tracks = function(dir, filename) + local tracks = {} + local count = 0 + local fullpath = dir .. "/" .. filename + local file = io.open('/' .. fullpath, "r") + + if not file then + rb.splash(rb.HZ, "Error opening /" .. fullpath) + return tracks + end + + -- strip BOM --"\xEF\xBB\xBF" + local bom = file:read(3) + if not string.find(bom, "\239\187\191") then + file:seek("set", 0) + end + + for line in file:lines() do + if string.len(line) > 3 and (not string.find(line, "%s*#.*")) then + count = count + 1 + tracks[count] = line + end + end + file:close() + return tracks + end + |