diff --git a/lrc/README.md b/lrc/README.md new file mode 100644 index 0000000..1a97339 --- /dev/null +++ b/lrc/README.md @@ -0,0 +1,32 @@ +# LRC + +![thumbnail](thumbnail.webp) + +Displays current song lyrics on the bar widget via `lrc_tty`. Works with MPD and Spotify. + +## Plugin + +| Field | Value | +| --- | --- | +| ID | `shin/lrc` | +| Entries | Bar widget: `lrc` | + +## Requirements + +- `lrc_tty` — fetches synchronized lyrics over the network from the configured provider. +- `playerctl` — reads MPRIS player status and metadata. + +## Usage + +Enable `shin/lrc` in Settings → Plugins, then add the **LRC** bar widget. It displays the current lyric line when a track is playing. + +The widget checks MPD first, then falls back to Spotify. + +## Spawned processes + +- `playerctl` — enumerates MPRIS players and queries playback status and metadata. +- `lrc_tty` — fetches synchronized lyrics and outputs them. + +## Network access + +`lrc_tty` connects to remote lyric APIs to fetch synchronized lyrics for the currently playing track. diff --git a/lrc/plugin.toml b/lrc/plugin.toml new file mode 100644 index 0000000..fbfb2d9 --- /dev/null +++ b/lrc/plugin.toml @@ -0,0 +1,15 @@ +id = "shin/lrc" +name = "LRC" +version = "1.0.0" +plugin_api = 3 +author = "shin" +license = "MIT" +icon = "music" +deprecated = false +description = "Displays current song lyrics via lrc_tty." +tags = ["bar", "music"] +dependencies = ["lrc_tty", "playerctl"] + +[[widget]] +id = "lrc" +entry = "widget.luau" diff --git a/lrc/thumbnail.webp b/lrc/thumbnail.webp new file mode 100644 index 0000000..a79151a Binary files /dev/null and b/lrc/thumbnail.webp differ diff --git a/lrc/translations/en.json b/lrc/translations/en.json new file mode 100644 index 0000000..9e26dfe --- /dev/null +++ b/lrc/translations/en.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/lrc/widget.luau b/lrc/widget.luau new file mode 100644 index 0000000..8ccf726 --- /dev/null +++ b/lrc/widget.luau @@ -0,0 +1,56 @@ +noctalia.setUpdateInterval(300) + +local fetching = false +local mpdPlayer = "mpd" + +noctalia.runAsync("playerctl -l 2>/dev/null", function(r) + if r.exitCode == 0 then + for name in r.stdout:gmatch("[^\n]+") do + if name:match("^mpd%.") then + mpdPlayer = name + break + end + end + end +end) + +function update() + if fetching then + return + end + + if not noctalia.commandExists("lrc_tty") then + return + end + + noctalia.runAsync("playerctl status --player " .. mpdPlayer .. " 2>/dev/null", function(r) + if r.exitCode == 0 and r.stdout:gsub("%s+$", "") == "Playing" then + fetchLyrics(mpdPlayer) + return + end + noctalia.runAsync("playerctl status --player spotify 2>/dev/null", function(r2) + if r2.exitCode == 0 and r2.stdout:gsub("%s+$", "") == "Playing" then + fetchLyrics("spotify") + return + end + barWidget.setText("") + end) + end) +end + +function fetchLyrics(player) + fetching = true + + noctalia.runAsync("lrc_tty --raw --player " .. player, function(r) + fetching = false + + if r.exitCode == 0 then + local text = r.stdout:gsub("%s+$", "") + if #text > 0 and text ~= "(no lyrics)" then + barWidget.setText("| " .. text) + return + end + end + barWidget.setText("") + end,30000) +end