Initial commit
This commit is contained in:
commit
6112eb4db1
|
@ -0,0 +1 @@
|
|||
syndicate_svg_mpd
|
|
@ -0,0 +1,57 @@
|
|||
# SPDX-FileCopyrightText: ☭ 2021 Emery Hemingway
|
||||
# SPDX-License-Identifier: Unlicense
|
||||
|
||||
import std/[asyncdispatch, options, streams, strtabs, times, xmltree]
|
||||
import preserves
|
||||
import syndicate, syndicate/[actors, capabilities, relay]
|
||||
# TODO: move the exported Syndicate stuff to the top module
|
||||
import nimsvg
|
||||
import mpdclient
|
||||
|
||||
import svui
|
||||
|
||||
proc generateSvg(mpd: MPDClient): string =
|
||||
var
|
||||
s = newStringStream()
|
||||
status = mpd.status
|
||||
if status.state in {statePlay, statePause}:
|
||||
if status.song.isSome:
|
||||
s.writeLine "song: " & $status.song.get.pos
|
||||
s.writeLine "elapsedTime: " & $(status.elapsed.inSeconds)
|
||||
s.writeLine "totalTime: " & $(status.duration.inSeconds)
|
||||
map(mpd.currentSong) do (song: Song):
|
||||
s.writeLine "uri: ", song.file
|
||||
if song.artists.len > 0:
|
||||
s.writeLine "artist: ", song.artists[0]
|
||||
s.writeLine "album: ", song.tags.getOrDefault $tagAlbum
|
||||
s.writeLine "title: ", song.title
|
||||
s.writeLine "track: ", song.tags.getOrDefault $tagTrack
|
||||
s.writeLine "name: ", song.name
|
||||
s.writeLine "date: ", song.tags.getOrDefault $tagDate
|
||||
else:
|
||||
s.writeLine "MPD inactive"
|
||||
s.setPosition 0
|
||||
var nodes = buildSvg:
|
||||
svg(width=400, height=300):
|
||||
g:
|
||||
text(`font-family` = "Verdana", x="30", y="30", `font-size`="20"):
|
||||
t: s.readAll.escape
|
||||
render nodes
|
||||
|
||||
when isMainModule:
|
||||
proc quitHook() {.noconv.} = quit()
|
||||
setControlCHook(quitHook)
|
||||
|
||||
waitFor runActor("client") do (turn: var Turn):
|
||||
|
||||
let
|
||||
cap = mint()
|
||||
mpd = newMPDClient()
|
||||
var svuiHandle: Handle
|
||||
|
||||
connectUnix(turn, "/run/syndicate/ds", cap) do (turn: var Turn; a: Assertion) -> TurnAction:
|
||||
let ds = unembed a
|
||||
|
||||
svuiHandle = replace(turn, ds, svuiHandle, Svui(svg: generateSvg(mpd)))
|
||||
# TODO: poll MPD with idle messages,
|
||||
# not sure how to do that with the Syndicate Nim DSL
|
|
@ -0,0 +1,13 @@
|
|||
# Package
|
||||
|
||||
version = "0.1.0"
|
||||
author = "Emery Hemingway"
|
||||
description = "Syndicate SVG generator for MPD"
|
||||
license = "Unlicense"
|
||||
srcDir = "src"
|
||||
bin = @["syndicate_svg_mpd"]
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
||||
requires "nim >= 1.6.0", "mpdclient", "svui"
|
Loading…
Reference in New Issue