commit 8663ff8969e0d11135109ebc96af434a98684387 Author: Shobu Ser'Hao Date: Tue Nov 26 13:19:11 2024 +0100 init diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cafc1c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/barmanager.py b/barmanager.py new file mode 100644 index 0000000..5b77ff1 --- /dev/null +++ b/barmanager.py @@ -0,0 +1,65 @@ +"""barmanager +helper script for eww bar from Shobu Ser'Hao + +Usage: + barmanager player get [-f --follow] + +Options: + -h --help Show Help screen + -f --follow Loop on the output +""" +from docopt import docopt +from subprocess import run, Popen, PIPE +import json +import sys + +def main(): + arguments = docopt(__doc__) + if arguments["player"]: + run(["echo", json.dumps(handle_player(arguments))]) + +def handle_player(arguments): + if arguments["get"]: + + raw_metadata = run(["playerctl", "metadata"], capture_output=True).stdout.decode() + metadata = parse_player_metadata(raw_metadata) + if not arguments["--follow"]: + return metadata + + if arguments["--follow"]: + process = Popen(["playerctl", "metadata", "--follow"], stdout=PIPE) + chars = b'' + row_count = 0 + for char in iter(lambda: process.stdout.read(1), b""): + if char: + chars += char + if char == b"\n": + row_count += 1 + if row_count == len(metadata): + run(["echo", json.dumps(parse_player_metadata(chars.decode()))]) + string = '' + row_count = 0 + +def parse_player_metadata(raw_string): + metadata = {} + for i in raw_string.strip().split("\n"): + head = '' + tail = '' + spaces = 0 + for j in i: + if spaces < 2: + if j == " ": + spaces += 1 + else: + spaces = 0 + head += j + else: + tail += j + metadata[head.strip().split(":")[-1]] = tail.strip() + return metadata + + + +if __name__ == "__main__": + main() + diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..ce34ee8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,25 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1732014248, + "narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=", + "rev": "23e89b7da85c3640bbc2173fe04f4bd114342367", + "revCount": 710087, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.710087%2Brev-23e89b7da85c3640bbc2173fe04f4bd114342367/01934abf-23ee-7550-90cc-767601bc14b7/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.%2A.tar.gz" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8d1c56f --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "A Nix-flake-based Python development environment"; + + inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.*.tar.gz"; + + outputs = { self, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in + { + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell { + venvDir = ".venv"; + packages = with pkgs; [ python311 poetry ] ++ + (with pkgs.python311Packages; [ + pip + venvShellHook + black + docopt + ]); + }; + }); + + packages = forEachSupportedSystem ({pkgs}: { + default = pkgs.python311Packages.buildPythonPackage rec { + pname = "barManager"; + version = "0.1"; + pyproject = true; + + src = ./.; + build-system = with pkgs; [ + python311Packages.poetry-core + ]; + dependencies = [ + + ] ++ (with pkgs.python311Packages; [ + docopt + ]); + + meta = with pkgs.lib; { + description = ""; + mainProgram = "barmanager"; + homepage = ""; + changelog = ""; + license = licenses.mit; + }; + }; + }); + }; +} diff --git a/poetry.lock b/poetry.lock new file mode 100644 index 0000000..83f88ff --- /dev/null +++ b/poetry.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. + +[[package]] +name = "docopt" +version = "0.6.2" +description = "Pythonic argument parser, that will make you smile" +optional = false +python-versions = "*" +files = [ + {file = "docopt-0.6.2.tar.gz", hash = "sha256:49b3a825280bd66b3aa83585ef59c4a8c82f2c8a522dbe754a8bc8d08c85c491"}, +] + +[metadata] +lock-version = "2.0" +python-versions = "^3.11" +content-hash = "020d3e03335e70ca8b1cfd769838e50546a63b9ed4e4034ba584fd3a3ec497fd" diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d1da0a2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "barmanager" +version = "0.1.0" +description = "" +authors = ["Shobu Ser'Hao "] +readme = "README.md" + +[tool.poetry.dependencies] +python = "^3.11" +docopt = "^0.6.2" + + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +barmanager = "barmanager:main"