Skip to content

Refactor CLI interface and make project uv-first#24

Draft
aviiciii with Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-cli-interface
Draft

Refactor CLI interface and make project uv-first#24
aviiciii with Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-cli-interface

Conversation

Copilot AI commented Mar 1, 2026

Copy link
Copy Markdown

Codebase cleanup: add proper CLI interface via argparse, fix bugs, and make uv the primary package manager.

CLI interface

  • argparse-based CLI with positional url, -o/--output, -c/--chapters, and metadata override flags (--title, --author, --narrator, --year, --cover-url)
  • No-args invocation preserves the original interactive experience
  • When URL is passed as arg, interactive prompts are skipped
uv run audiobook-downloader https://tokybook.com/post/project-hail-mary-94ed6d -c "1-5,8" -o ~/audiobooks

uv-first packaging

  • pyproject.toml: Removed 10 transitive/unused deps (bs4, certifi, lxml, tqdm, websockets, etc.), switched from == pins to >= bounds (lockfile handles pinning), added [project.scripts] entry point and [build-system] with hatchling
  • Removed requirements.txt: was stale (still referenced old "tokybook" name); uv.lock is the source of truth
  • Regenerated uv.lock

uv run audiobook-downloader and uv run main.py both work. pip install . still works as fallback.

Bug fixes

  • book_data["title"] was accessed before the None check on book_data — moved the check first
  • subprocess.run(["open", url]) was macOS-only — now dispatches via platform.system() for macOS/Windows/Linux

Code cleanup

  • Extracted __main__ block into main(args=None) — testable, importable
  • Added output_dir param to download_and_tag_audiobook() (backward-compatible default)
  • 33 unit tests covering CLI parsing, scraper factory, sanitize_book_title, parse_chapter_ranges
  • README updated with CLI usage table, uv-first instructions, corrected Python 3.11+ badge

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add argparse-based CLI with URL, --output, --chapters, metadata overrides
- Wrap __main__ block into main() function with args parameter
- Fix bug: book_data accessed before None check
- Fix platform-specific subprocess.run(["open", url]) for cross-platform
- Add output_dir parameter to download_and_tag_audiobook
- Fix project name in pyproject.toml
- Add unit tests for CLI parsing, scraper selection, and utilities
- Update README with CLI usage documentation

Co-authored-by: aviiciii <88141521+aviiciii@users.noreply.github.com>
Copilot AI changed the title [WIP] Clean up code base and enhance CLI interface Add argparse CLI interface and clean up codebase Mar 1, 2026
Copilot AI and others added 2 commits March 1, 2026 13:15
…requirements.txt

- Remove transitive/unused deps (bs4, certifi, charset-normalizer, idna,
  lxml, soupsieve, tqdm, typing-extensions, urllib3, websockets)
- Use >= version specs instead of == pins (uv.lock handles pinning)
- Add [project.scripts] entry point: uv run audiobook-downloader
- Add [build-system] with hatchling for installable package
- Remove stale requirements.txt (referenced old "tokybook" project name)
- Regenerate uv.lock
- Update README: uv-first instructions, Python 3.11+ badge

Co-authored-by: aviiciii <88141521+aviiciii@users.noreply.github.com>
Co-authored-by: aviiciii <88141521+aviiciii@users.noreply.github.com>
Copilot AI changed the title Add argparse CLI interface and clean up codebase Refactor CLI interface and make project uv-first Mar 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants