Something went wrong. Try again.
A modern, network-enabled music player platform built on Rockbox technology. rockboxd.tsiry-sandratraina.com
rust deno navidrome airplay libadwaita zig mpris snapcast mpd rockbox audio subsonic
Something went wrong. Try again.
5.2 kB · 171 lines
Lua
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172--[[/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * * Copyright (C) 2017 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. * ****************************************************************************/]]
local scrpath = rb.current_path()
package.path = scrpath .. "/?.lua;" .. package.path --add lua_scripts directory to pathrequire("printmenus")
rb.actions = nilpackage.loaded["actions"] = nil
--------------------------------------------------------------------------------local Icon_Plugin = 0x9
local function get_files(path, norecurse, finddir, findfile, f_t, d_t)
local quit = false
local files = f_t or {} local dirs = d_t or {}
local function f_filedir(name) --default find function -- example: return name:find(".mp3", 1, true) ~= nil if name:len() <= 2 and (name == "." or name == "..") then return false end if string.sub(name, 1, 1) == '.' then return false end if string.sub(name, -4) == ".lua" then return true end return false end local function d_filedir(name) --default discard function return false end
if finddir == nil then finddir = f_filedir elseif type(finddir) ~= "function" then finddir = d_filedir end
if findfile == nil then findfile = f_filedir elseif type(findfile) ~= "function" then findfile = d_filedir end
local function _get_files(path, cancelbtn) local sep = "" if string.sub(path, - 1) ~= "/" then sep = "/" end for fname, isdir in luadir.dir(path) do
if isdir and finddir(fname) then table.insert(dirs, path .. sep ..fname) elseif not isdir and findfile(fname) then table.insert(files, path .. sep ..fname) end
if rb.get_plugin_action(0) == cancelbtn then return true end end end
local function cmp_alphanum (op1, op2) local type1= type(op1) local type2 = type(op2)
if type1 ~= type2 then return type1 < type2 else if type1 == "string" then op1 = op1:upper() op2 = op2:upper() end return op1 < op2 end end
table.insert(dirs, path) -- root
for key,value in pairs(dirs) do --luadir.dir may error out so we need to do the call protected _, quit = pcall(_get_files, value, CANCEL_BUTTON)
if quit == true or norecurse then break; end end
table.sort(files, cmp_alphanum) table.sort(dirs, cmp_alphanum)
return dirs, filesend -- get_files--------------------------------------------------------------------------------
function icon_fn(item, icon) if item ~= 0 then icon = Icon_Plugin else icon = -1 end return iconend
-- uses print_table and get_files to display simple file browserfunction script_choose(dir, title) local dstr local hstr = title
local norecurse = true local f_finddir = false -- function to match directories; nil all, false none local f_findfile = nil -- function to match files; nil all, false none local t_linedesc = {show_icons = true, icon_fn = icon_fn} local p_settings = {wrap = true, hasheader = true, justify = "left", linedesc = t_linedesc} local files = {} local dirs = {} local item = 1 rb.lcd_clear_display()
while item > 0 do dirs, files = get_files(dir, norecurse, f_finddir, f_findfile, dirs, files) for i=1, #dirs do dirs[i] = nil end -- empty table for reuse table.insert(dirs, 1, hstr) for i = 1, #files do table.insert(dirs, "\t" .. string.gsub(files[i], ".*/","")) end --print_menu(menu_t, func_t, selected, settings, copy_screen) _, item = print_menu(dirs, nil, 0, p_settings)
-- If item was selected follow directory or return filename item = item or -1 if item > 0 then dir = files[item - 1] if not rb.dir_exists("/" .. dir) then return dir end end
endend -- file_choose--------------------------------------------------------------------------------
local script_path = script_choose(scrpath, "lua scripts")if script_path then rb.restart_lua(script_path) end