JlSonic/JlSonic/beethelpers.jl

45 lines
1.1 KiB
Julia

playlistfile(path) = joinpath(path, "playlists.jsonl")
function saveplaylists(; file = playlistfile(Beets.confdir()))
global user_playlists
open(file, "w") do f
write(f,
join(JSON2.write.(user_playlists), "\n"))
end
end
function loadplaylists(; file = playlistfile(Beets.confdir()))
global user_playlists
isfile(file) || touch(file)
ps = JSON2.readlines(file)
empty!(user_playlists)
for p in ps
try
pl = JSON2.read(p, Playlist)
push!(user_playlists, pl)
catch e
@warn "Failed to read with error $e"
isa(e, ArgumentError) && continue
end
end
end
function saveusers(file = expanduser("~/.config/beets/users.jsonl"))
global users
open(file, "w") do f
write(f, join(JSON2.write.(users), "\n"))
end
end
function loadusers(; file = expanduser("~/.config/beets/users.jsonl"))
global users
isfile(file) || touch(file)
ps = JSON2.readlines(file)
p = JSON2.read.(ps, JlSonic.User)
empty!(users)
for pl in p
push!(users, pl)
end
end