A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 80 lines 4.2 kB view raw
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 ]] 25if not rb.playlist then rb.splash(rb.HZ, "No Support!") return nil end 26 27rb.playlist_amount = function() 28 return rb.playlist("amount") 29 end 30rb.playlist_add = function (filename) 31 return rb.playlist("insert_track", filename, rb.PLAYLIST_INSERT_LAST, false, true) 32 end 33rb.playlist_create = function(dir, filename) 34 return rb.playlist("create", dir, filename) 35 end 36rb.playlist_start = function(index, elapsed, offset) 37 rb.playlist("start", index, elapsed, offset) 38 end 39rb.playlist_resume_track = function(index, crc, elapsed, offset) 40 rb.playlist("resume_track", index, crc, elapsed, offset) 41 end 42rb.playlist_resume = function() return rb.playlist("resume") end 43rb.playlist_shuffle = function(random_seed, index) 44 rb.playlist("shuffle", random_seed, index) 45 end 46rb.playlist_sync = function () rb.playlist("sync") end 47rb.playlist_remove_all_tracks = function() return rb.playlist("remove_all_tracks") end 48rb.playlist_insert_track = function(filename, pos, bqueue, bsync) 49 return rb.playlist("insert_track", filename, pos, bqueue, bsync) 50 end 51rb.playlist_insert_directory = function(dir, pos, bqueue, brecurse) 52 return rb.playlist("insert_directory", dir, pos, bqueue, brecurse) 53 end 54rb.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