Initial Upload

This commit is contained in:
2025-09-14 03:33:41 -04:00
parent 0043d0096e
commit 2e136eeab0
26 changed files with 534 additions and 0 deletions

1
.envrc Normal file
View File

@@ -0,0 +1 @@
use flake

2
.gitignore vendored
View File

@@ -1,3 +1,5 @@
.direnv
.venv
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/

0
__init__.py Normal file
View File

11
build.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env sh
python -m zipapp src --compress --output=release/abstui --python="/usr/bin/env python"
# cp -avR web/ $HOME/.config/pytui/web
# Only make directory if it doesn't exist
# if [ ! -d /var/pytui ]; then
# sudo mkdir -p /var/pytui/
# fi
# if [ ! -d /var/pytui/web ]; then
# sudo mkdir -p /var/pytui/web
# fi
# sudo cp -avR web/* /var/pytui/web/

25
flake.lock generated Normal file
View File

@@ -0,0 +1,25 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1757745802,
"narHash": "sha256-hLEO2TPj55KcUFUU1vgtHE9UEIOjRcH/4QbmfHNF820=",
"rev": "c23193b943c6c689d70ee98ce3128239ed9e32d1",
"revCount": 861038,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.861038%2Brev-c23193b943c6c689d70ee98ce3128239ed9e32d1/01994596-722e-716c-b0eb-e6b07d4de75b/source.tar.gz"
},
"original": {
"type": "tarball",
"url": "https://flakehub.com/f/NixOS/nixpkgs/0.1"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

92
flake.nix Normal file
View File

@@ -0,0 +1,92 @@
{
description = "A Nix-flake-based Python development environment";
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
outputs = inputs:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import inputs.nixpkgs { inherit system; };
});
/*
* Change this value ({major}.{min}) to
* update the Python virtual-environment
* version. When you do this, make sure
* to delete the `.venv` directory to
* have the hook rebuild it for the new
* version, since it won't overwrite an
* existing one. After this, reload the
* development shell to rebuild it.
* You'll see a warning asking you to
* do this when version mismatches are
* present. For safety, removal should
* be a manual step, even if trivial.
*/
version = "3.13";
in
{
devShells = forEachSupportedSystem ({ pkgs }:
let
concatMajorMinor = v:
pkgs.lib.pipe v [
pkgs.lib.versions.splitVersion
(pkgs.lib.sublist 0 2)
pkgs.lib.concatStrings
];
python = pkgs."python${concatMajorMinor version}";
in
{
default = pkgs.mkShell {
env = {
PYTHONBREAKPOINT = "pudb.set_trace";
PYTHONPATH = "$PWD/src:$PYTHONPATH";
};
venvDir = ".venv";
postShellHook = ''
venvVersionWarn() {
local venvVersion
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
[[ "$venvVersion" == "${python.version}" ]] && return
cat <<EOF
Warning: Python version mismatch: [$venvVersion (venv)] != [${python.version}]
Delete '$venvDir' and reload to rebuild for version ${python.version}
EOF
}
venvVersionWarn
'';
packages = with python.pkgs; [
pudb
ptpython
ipython
pytest
pytest-cov
flake8
ptpython
ipython
isort
pynvim
ruff
black
/* Add whatever else you'd like here. */
pkgs.basedpyright
# pkgs.black
/* or */
# python.pkgs.black
# pkgs.ruff
/* or */
# python.pkgs.ruff
];
};
});
};
}

1
node_modules/.bin/pyright generated vendored Symbolic link
View File

@@ -0,0 +1 @@
../pyright/index.js

1
node_modules/.bin/pyright-langserver generated vendored Symbolic link
View File

@@ -0,0 +1 @@
../pyright/langserver.index.js

23
node_modules/.package-lock.json generated vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"name": "abstui",
"lockfileVersion": 3,
"requires": true,
"packages": {
"node_modules/pyright": {
"version": "1.1.405",
"resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.405.tgz",
"integrity": "sha512-hgy12kLZ1oAMtl9LTsByHftg3AD6Pouwu5rBsQlqYQqCCdGBgaQm9XDAPDap7ayWe9W+NWrUwO7Zy1K7uXoE2A==",
"license": "MIT",
"bin": {
"pyright": "index.js",
"pyright-langserver": "langserver.index.js"
},
"engines": {
"node": ">=14.0.0"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
}
}
}
}

22
node_modules/pyright/LICENSE.txt generated vendored Normal file
View File

@@ -0,0 +1,22 @@
MIT License
Pyright - A static type checker for the Python language
Copyright (c) Microsoft Corporation. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

32
node_modules/pyright/README.md generated vendored Normal file
View File

@@ -0,0 +1,32 @@
![Pyright](https://github.com/microsoft/pyright/blob/main/docs/img/PyrightLarge.png)
# Static Type Checker for Python
Pyright is a full-featured, standards-based static type checker for Python. It is designed for high performance and can be used with large Python source bases.
Pyright includes both a [command-line tool](https://microsoft.github.io/pyright/#/command-line) and an [extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright).
## Pyright Playground
Try Pyright in your browser using the [Pyright Playground](https://pyright-play.net/?code=MQAgKgFglgziMEMC2AHANgUxAEw0g9gHYwAuATgiRnBPgO4gDG%2BSBhIGZZ%2BZcjC7AEZZcVRlWzwSlKPzRoAniEFKUCslADmEEgDoAUPtwAzEAmzYAFAA8AXCGNp8lADQgF9x85IBKW-pBAkDIMEgBXMnZrEABqd0NQAAUEGBgoQk0zKTIQdNIBRiwUkBIILBgMZkJJBDJNMKQMQhJg6jC0Ejh0rLIw5qhGjmtClBIoIgNzKwBGNwAiOZ99IA).
## Documentation
Refer to [the documentation](https://microsoft.github.io/pyright) for installation, configuration, and usage details.
## Community
Do you have questions about Pyright or Python type annotations in general? Post your questions in [the discussion section](https://github.com/microsoft/pyright/discussions).
If you would like to report a bug or request an enhancement, file a new issue in either the [pyright](https://github.com/microsoft/pyright/issues) or [pylance-release](https://github.com/microsoft/pylance-release/issues) issue tracker. In general, core type checking functionality is associated with Pyright while language service functionality is associated with Pylance, but the same contributors monitor both repos. For best results, provide the information requested in the issue template.
## Contributing
This project welcomes contributions and suggestions. For feature and complex bug fix contributions, it is recommended that you first discuss the proposed change with Pyrights maintainers before submitting the pull request. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

8
node_modules/pyright/index.js generated vendored Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
// Stash the base directory into a global variable.
global.__rootDirectory = __dirname + '/dist/';
require('./dist/pyright');

8
node_modules/pyright/langserver.index.js generated vendored Executable file
View File

@@ -0,0 +1,8 @@
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
// Stash the base directory into a global variable.
global.__rootDirectory = __dirname + '/dist/';
require('./dist/pyright-langserver');

47
node_modules/pyright/package.json generated vendored Normal file
View File

@@ -0,0 +1,47 @@
{
"name": "pyright",
"displayName": "Pyright",
"description": "Type checker for the Python language",
"version": "1.1.405",
"license": "MIT",
"author": {
"name": "Microsoft Corporation"
},
"publisher": "Microsoft Corporation",
"engines": {
"node": ">=14.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/pyright",
"directory": "packages/pyright"
},
"scripts": {
"build": "webpack --mode production --progress",
"clean": "shx rm -rf ./dist ./out README.md LICENSE.txt",
"prepack": "npm run clean && shx cp ../../README.md . && shx cp ../../LICENSE.txt . && npm run build",
"webpack": "webpack --mode development --progress"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
},
"devDependencies": {
"@types/node": "^22.10.5",
"copy-webpack-plugin": "^11.0.0",
"esbuild-loader": "^3.2.0",
"shx": "^0.3.4",
"ts-loader": "^9.5.1",
"typescript": "~5.5.4",
"webpack": "^5.97.1",
"webpack-cli": "^5.1.4"
},
"files": [
"/dist",
"LICENSE.txt"
],
"main": "index.js",
"bin": {
"pyright": "index.js",
"pyright-langserver": "langserver.index.js"
}
}

42
package-lock.json generated Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "abstui",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"dependencies": {
"pyright": "^1.1.405"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
"hasInstallScript": true,
"license": "MIT",
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/pyright": {
"version": "1.1.405",
"resolved": "https://registry.npmjs.org/pyright/-/pyright-1.1.405.tgz",
"integrity": "sha512-hgy12kLZ1oAMtl9LTsByHftg3AD6Pouwu5rBsQlqYQqCCdGBgaQm9XDAPDap7ayWe9W+NWrUwO7Zy1K7uXoE2A==",
"license": "MIT",
"bin": {
"pyright": "index.js",
"pyright-langserver": "langserver.index.js"
},
"engines": {
"node": ">=14.0.0"
},
"optionalDependencies": {
"fsevents": "~2.3.3"
}
}
}
}

5
package.json Normal file
View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"pyright": "^1.1.405"
}
}

16
pyproject.toml Normal file
View File

@@ -0,0 +1,16 @@
[build-system]
requires = ["setuptools>=45", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "AudioBookShelf-TUI"
version = "0.1.0"
dependencies = []
[tool.setuptools.packages.find]
where = ["."]
include = ["src*"]
# For development/editable install
[tool.setuptools.package-dir]
"" = "src"

BIN
release/abstui Executable file

Binary file not shown.

0
src/__init__.py Normal file
View File

11
src/__main__.py Executable file
View File

@@ -0,0 +1,11 @@
#!/usr/bin/env python3
from .libs.config import Config
from .libs.absapi import ABSApi, Endpoint, ABSResponse
config: Config = Config()
def main() -> None:
pass
if __name__ == "__main__":
main()

0
src/libs/__init__.py Normal file
View File

48
src/libs/absapi.py Normal file
View File

@@ -0,0 +1,48 @@
import urllib.request as req
# import json
# from typing import List, dict, Optional
from enum import Enum
from dataclasses import dataclass
from .config import Config
class Endpoint(Enum):
BOOKS = "/api/v1/book"
AUTHORS = "/api/v1/author"
SERIES = "/api/v1/series"
COVERS = "/api/v1/cover"
GENRES = "/api/v1/genre"
LISTS = "/api/v1/list"
USERS = "/api/v1/user"
SETTINGS = "/api/v1/settings"
STATS = "/api/v1/stats"
PLAYBACK_POSITIONS = "/api/v1/playback-position"
REVIEWS = "/api/v1/review"
TAGS = "/api/v1/tag"
PLUGINS = "/api/v1/plugin"
@dataclass
class ABSResponse:
status: str
data: list[dict[str,str]]|None = None
message: str|None = None
class ABSApi:
"""
A class to interact with the Audiobookshelf (ABS) API.
"""
def __init__(self) -> None:
self.base_url: str = Config().abs_base_url
def test(self, endpoint:Endpoint) -> str:
"""
Test the connection to the ABS API.
Args:
endpoint (Endpoint): The API endpoint to test. Default is Endpoint.BOOKS.
Returns:
ABSResponse: The response from the API.
"""
return f"{self.base_url}{endpoint.value}"

87
src/libs/config.py Normal file
View File

@@ -0,0 +1,87 @@
from pathlib import Path
from dataclasses import dataclass
import json
import os
# Check for environment variable override (used in Docker)
XDG_CONFIG_HOME: Path = Path(Path.home()).joinpath(".config")
ABS_CONFIG_DIR: Path = XDG_CONFIG_HOME.joinpath("abstui")
ABS_CONFIG_FILE: Path = ABS_CONFIG_DIR.joinpath("config.json")
@dataclass
class Config:
"""
Configuration management for the application.
Args:
path (Path): Path to the configuration file.
data_path (Path): Path to the data directory.
host (str): Host address for the application.
abs_api_key (str): API key for accessing ABS services.
Methods:
to_dict() -> dict: Convert configuration to a dictionary.
save() -> bool: Save the configuration to a file.
load() -> "Config": Load the configuration from a file.
Returns:
Config: An instance of the Config class with loaded
"""
path: Path = ABS_CONFIG_FILE
data_path: Path = ABS_CONFIG_DIR.joinpath("data")
abs_base_url: str = "localhost"
abs_api_key: str = ""
def __init__(self, path: Path|None = None):
if path:
self.path = path
self.load()
def to_dict(self) -> dict[str, str]:
"""
Convert configuration to a dictionary.
Returns:
dict: Dictionary representation of the configuration.
"""
return {
"data_path": str(self.data_path),
"abs_base_url": self.abs_base_url,
"abs_api_key": self.abs_api_key,
}
def save(self) -> bool:
"""
Save the configuration to a file.
Returns:
bool: True if the configuration was saved successfully, False otherwise.
"""
# Ensure config directory exists
if not self.path.parent.exists():
self.path.parent.mkdir(parents=True, exist_ok=True)
# Create directories if they don't exist
if not self.data_path.exists():
self.data_path.mkdir(parents=True, exist_ok=True)
# Write configuration to file
try:
with open(self.path, 'w') as f:
json.dump(self.to_dict(), f, indent=4)
return True
except Exception:
return False
def load(self) -> "Config":
"""
Load the configuration from a file.
Returns:
Config: An instance of the Config class with loaded configuration.
"""
if self.path.exists():
with open(self.path, 'r') as f:
data = json.load(f)
self.data_path = Path(data.get("data_path"))
self.abs_base_url = data.get("abs_base_url")
self.abs_api_key = data.get("abs_api_key")
else:
_ =self.save()
return self

3
src/libs/terminal.py Normal file
View File

@@ -0,0 +1,3 @@
import curses
TERMINAL_HEIGHT, TERMINAL_WIDTH = curses.window().getmaxyx()

0
tests/__init__.py Normal file
View File

49
tests/test_config.py Normal file
View File

@@ -0,0 +1,49 @@
import pytest
import os
import sys
from unittest.mock import patch, mock_open
from pathlib import Path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
from ..src.config import Config
class TestConfig:
"""Test suite for the Config class."""
testing_dir = Path(str(os.path.dirname(__file__)))
def test_config_init(self):
self.config = Config(self.testing_dir.joinpath("test_config.json"))
assert self.config is not None
def test_config_to_dict(self):
self.config = Config(self.testing_dir.joinpath("test_config.json"))
config_dict = self.config.to_dict()
assert isinstance(config_dict, dict)
assert "data_path" in config_dict
assert "host" in config_dict
assert "abs_api_key" in config_dict
def test_config_save_and_load(self):
self.config = Config(self.testing_dir.joinpath("test_config.json"))
self.config.data_path = self.testing_dir.joinpath("data")
self.config.host = "testhost"
self.config.abs_api_key = "testkey"
# Save the configuration
save_result = self.config.save()
assert save_result is True
assert self.config.path.exists()
# Load the configuration into a new instance
new_config = Config(self.testing_dir.joinpath("test_config.json"))
assert new_config.data_path == self.config.data_path
assert new_config.host == self.config.host
assert new_config.abs_api_key == self.config.abs_api_key
# Clean up
if self.config.path.exists():
self.config.path.unlink()
if self.config.data_path.exists():
self.config.data_path.rmdir()