1
0
Fork 0
mirror of https://github.com/Reuh/daccord.git synced 2025-10-27 12:49:30 +00:00

Updated to MPD 0.21

This commit is contained in:
Étienne Fildadut 2018-08-29 21:45:03 +02:00
parent 37594f3a65
commit 96e0dc2c83
2 changed files with 44 additions and 28 deletions

12
config.lua.example Normal file
View file

@ -0,0 +1,12 @@
-- Copy this file into config.lua and change according to your tastes.
-- MPD server
host = "localhost"
port = 6600
password = "" -- leave empty if you don't use a password
-- Default behaviour
filenameSearch = false -- instant search search also search in filenames (not only when using the file= syntax), slower
-- Interface
songDisplay = { "Track", { "Title", "file" }, "Artist", "Album" } -- list of tags or list of alternative tags (first one to exist will be used) to display for each song

View file

@ -36,6 +36,9 @@
-- * The endgoal would be that playlists would be entirely determined and contained in a single search query (add some saved storage interface). -- * The endgoal would be that playlists would be entirely determined and contained in a single search query (add some saved storage interface).
-- Which we would therfore mean we can regenerate them on the fly when the MPD database is updated, or probabilities where used in the query. -- Which we would therfore mean we can regenerate them on the fly when the MPD database is updated, or probabilities where used in the query.
-- * A non-console GUI. Should be doable considering everything is neatly contained in gui.can, but damn are thoses text widget I made weird. -- * A non-console GUI. Should be doable considering everything is neatly contained in gui.can, but damn are thoses text widget I made weird.
-- * A real documentation.
-- * Tag!=thing, modified since, and, not, or
-- * File browser
-- --
-- This version of the software is licensed under the terms of the Apache License, version 2 (https://www.apache.org/licenses/LICENSE-2.0.txt). -- This version of the software is licensed under the terms of the Apache License, version 2 (https://www.apache.org/licenses/LICENSE-2.0.txt).
@ -58,20 +61,23 @@ let gui = require("gui")
let mpc = require("mpc") let mpc = require("mpc")
-- Constants -- Constants
let VERSION = "0.0.3" let VERSION = "0.0.4" -- Major.Minor.IdkIChangedSomethingButLetsNotTalkAboutItTooMuch
-- Major bump means that everything major that was planned before I decided to keep programming this shit was implemented, and forms, like, a cohesive whole.
-- Minor bump means I implemented something that's actually useful. Stuff may break, because why not.
-- The other thing bump means I implemented or fixed something. But that's not worth excitement.
-- Configuration -- Configuration file. Yeah.
let config = { let config = {
-- MPD server -- MPD server
host = "localhost", host = "localhost",
port = 6600, port = 6600,
password = "", password = "", -- leave empty if you don't use a password
-- Default behaviour -- Default behaviour
filenameSearch = false, -- instant search search also in filename (not only when using the file= syntax), slower filenameSearch = false, -- instant search search also search in filenames (not only when using the file= syntax), slower
-- Interface -- Interface
songDisplay = { "Track", { "Title", "file" }, "Artist", "Album" } -- list of tags or list of alternative tags (first one to exist will be used) to display for each song songDisplay = { "Track", { "Title", "file" }, "Artist", "Album" } -- list of tags or list of alternative tags (first one to exist will be used) to display for each song
} }
(loadfile("config.lua", "t", config) or () end)() (loadfile("config.lua", "t", config) or () end)() -- GATHER UP EVERYONE! I WANT YOU TO MEET... THE AMAZING CONFIG FILE LOADER!
-- Returns list of fields to display for the song s -- Returns list of fields to display for the song s
let songTable = (s) let songTable = (s)
@ -89,7 +95,7 @@ let songTable = (s)
return t return t
end end
-- Connect -- Connect!
mpc.log = () end mpc.log = () end
mpc = mpc(config.host, config.port) mpc = mpc(config.host, config.port)
if config.password ~= "" then if config.password ~= "" then
@ -106,13 +112,13 @@ let tags = [
-- State -- State
let tagCompleting = { let tagCompleting = {
tag = nil, tag = nil, -- tag name
start = nil, start = nil, -- start position in search input for tag=thing
stop = nil stop = nil -- end position
} }
let results, playlist = {}, {} let results, playlist = {}, {} -- current result in the search view / playlist (list of songs)
let state = "stop" let state = "stop" -- state
gui { gui {
{ {
@ -146,7 +152,7 @@ gui {
else else
start, sel, val, stop = @sub(1, @cursorPosition):match("()([A-Za-z_]+)=\"([^\"]*)()$") start, sel, val, stop = @sub(1, @cursorPosition):match("()([A-Za-z_]+)=\"([^\"]*)()$")
end end
-- TODO: candran "str":thing
-- music tags -- music tags
for _, tag in ipairs(tags) do for _, tag in ipairs(tags) do
if tag:lower() == sel:lower() then if tag:lower() == sel:lower() then
@ -168,18 +174,17 @@ gui {
break break
end end
end end
-- file search -- file search
if sel:lower() == "file" then if sel:lower() == "file" then
let r, songs = mpc:list("file") let r, songs = mpc:search(("(file == %q)"):format(val), "window", "0:"..tostring(list.h))
if r then if r then
results = {} results = {}
for _, s in ipairs(songs) do for _, s in ipairs(songs) do
if s.file:lower():match(val:lower()) then -- filter val
table.insert(results, s) table.insert(results, s)
list:insert{tostring(s.file)} list:insert{tostring(s.file)}
end end
end end
end
tagCompleting.tag = "file" tagCompleting.tag = "file"
tagCompleting.start = start tagCompleting.start = start
@ -193,36 +198,35 @@ gui {
-- Any selectors -- Any selectors
let withoutSel = @content:gsub("[A-Za-z_]+=[^\" ]+", ""):gsub("[A-Za-z_]+=\"[^\"]*\"", "") let withoutSel = @content:gsub("[A-Za-z_]+=[^\" ]+", ""):gsub("[A-Za-z_]+=\"[^\"]*\"", "")
for word in withoutSel:gmatch("[^%s]+") do for word in withoutSel:gmatch("[^%s]+") do
table.insert(query, "any") table.insert(query, ("(any == %q)"):format(word))
table.insert(query, word)
end end
-- Tag selectors -- Tag selectors
for tag, val in @content:gmatch("([A-Za-z_]+)=([^\" ]+)") do for tag, val in @content:gmatch("([A-Za-z_]+)=([^\" ]+)") do
table.insert(query, tag) table.insert(query, ("(%s == %q)"):format(tag, val))
table.insert(query, val)
end end
for tag, val in @content:gmatch("([A-Za-z_]+)=\"([^\"]*)\"") do for tag, val in @content:gmatch("([A-Za-z_]+)=\"([^\"]*)\"") do
table.insert(query, tag) table.insert(query, ("(%s == %q)"):format(tag, val))
table.insert(query, val)
end end
-- Limit
table.insert(query, "window")
table.insert(query, "0:"..tostring(list.h))
-- Search -- Search
let r, songs = mpc:search(unpack(query)) let r, songs = mpc:search(unpack(query))
if r then results = songs end if r then results = songs end
-- Filename search -- Filename search
if config.filenameSearch then if config.filenameSearch then
for i=1, #query, 2 do for i=1, #query, 1 do
if query[i] == "any" then query[i] = query[i]:gsub("^%(any", "(file")
query[i] = "file"
end
end end
let r, songs = mpc:search(unpack(query)) let r, songs = mpc:search(unpack(query))
if r then if r then
-- Merge -- Merge
for _, newSong in ipairs(songs) do for _, newSong in ipairs(songs) do -- TODO more efficient (using a sorted thing)
let found = false let found = false
for _, existingSong in ipairs(results) do for _, existingSong in ipairs(results) do
if newSong.file == existingSong.file then if newSong.file == existingSong.file then