Metadata-Version: 2.4
Name: manga-termux
Version: 1.0.6
Summary: Manga downloader CLI for Termux — weebcentral.com, CBZ/PDF/images, chapter ranges, live search, aria2c.
License: MIT
Keywords: manga,downloader,termux,weebcentral,android,cli,aria2c
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Environment :: Console
Classifier: Topic :: Multimedia
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: prompt_toolkit>=3.0.0
Requires-Dist: Pillow>=9.0.0

# manga-termux 1.0.6 — fixed

Repairs a broken `pip install manga-termux` (v1.0.5). The tool could not build a
chapter list, so **every download failed**, and it reported network failures as
"no results", which made search look broken too.

Verified against the live site on 2026-09-27.

---

## Root cause

### 1. Chapter list — the fatal bug

weebcentral.com switched its markup from **absolute** to **relative** links:

```html
<!-- what 1.0.5 expected -->
<a href="https://weebcentral.com/chapters/01M3DVDYA933SQQ6703XQYMMGQ">

<!-- what the site actually serves now -->
<a href="/chapters/01M3DVDYA933SQQ6703XQYMMGQ">
```

The 1.0.5 regex in `scraper.py` hard-coded the absolute prefix:

```python
r'href="(https://weebcentral\.com/chapters/[^"]+)"[^>]*>.*?<span class="">\s*([^<]+?)\s*</span>'
```

So it matched **nothing**. `get_all_chapters()` returned `[]`, and the CLI looped
on `[!] Could not fetch chapter list. Try again.` — no download could ever start.
A live measurement confirmed it: One Piece parsed **0 chapters** before the fix,
**1194** after.

### 2. Errors were silently swallowed

Every scrape call was wrapped in `except Exception: return []`. A DNS failure,
a timeout and a genuine "no matches" were indistinguishable — so "search doesn't
work" and "chapter list is empty" both surfaced as a bare "no results".

### 3. Wrong default save path off Android

`DEFAULT_DOWNLOAD_DIR` was hard-coded to `/sdcard/Manga`, which cannot exist on
Linux/macOS/WSL.

---

## What changed

| File | Change |
|---|---|
| `manga_termux/scraper.py` | **Chapter-list regex accepts relative hrefs** (the fix); all parsed hrefs normalised via `_absolute()`; 3 retries with backoff; gzip/deflate decoding; browser-like headers; `ScraperError` raised instead of silent `[]`; search falls back from quick-search to `/search/data`; titles read from cover `alt` → `flex-1` div → URL slug; HTML entities unescaped. |
| `manga_termux/downloader.py` | `DEFAULT_DOWNLOAD_DIR` auto-detected (`/sdcard/Manga` on Termux, `~/Manga` elsewhere); per-page retries; aria2c gets `--max-tries`/`--retry-wait`; per-page failure URLs logged. |
| `manga_termux/cli.py` | Prints the real scrape error instead of a misleading retry loop; new non-interactive flags `--search TEXT`, `--chapters SERIES_ID`, `--version`. |
| `pyproject.toml` | Build metadata for 1.0.6. |

Everything else — chapter-range syntax, CBZ/PDF/images output, aria2c 16-connection
downloading, resume/skip, the prompt_toolkit live-search UI — is unchanged.

---

## Install

### Option A — patch the installed package (fastest, recommended)

```bash
cd manga-termux-fix
bash apply_fix.sh
```

It resolves the installed package through its metadata (safe to run from inside
this folder), backs up the originals as `*.bak-<timestamp>`, copies the fixed
files in, and clears stale `__pycache__`. If your interpreter is `python3`:

```bash
PYTHON=python3 bash apply_fix.sh
```

### Option B — install from this source tree

```bash
cd manga-termux-fix
pip install --force-reinstall .
```

### Option C — build a wheel, copy to the phone

```bash
cd manga-termux-fix
pip install build && python -m build --wheel
# then on Termux:
pip install --force-reinstall manga_termux-1.0.6-py3-none-any.whl
```

### Revert

The original files are kept next to the patched ones as `*.bak-<timestamp>`:

```bash
TARGET=$(python -c "from importlib.metadata import distribution as d; print(d('manga-termux').locate_file('manga_termux'))")
cd "$TARGET"
for bak in *.bak-*; do cp "$bak" "${bak%.bak-*}"; done
rm -rf __pycache__
```

---

## Verified after the fix

| Check | Result |
|---|---|
| `search_manga("one piece")` | 6 results |
| `search_manga("solo leveling")` | 9 results |
| `get_all_chapters(One Piece)` | **1194** chapters (was 0), Ch 1 → Ch 1194, none skipped |
| `get_all_chapters(Solo Leveling)` | 201 chapters, Ch 0 → Ch 200 |
| `filter_chapters(..., "1-3,200")` | 1, 2, 3, 200 |
| `get_chapter_images(...)` | 13–22 pages per chapter |
| Download → CBZ | 22 pages, 10.5 MB, zip integrity OK |
| Download → PDF | valid `%PDF-` header |
| Unreachable host | raises `ScraperError` with the real reason |
| `manga --version` | `manga-termux 1.0.6` |

---

## Known limits

- **It is a scraper, so it will break again** whenever weebcentral changes its
  markup. The parser now tolerates relative/absolute hrefs and several title
  layouts, but no regex scraper is future-proof.
- Some series' early chapters sit under a `0` / prologue number, so ranges are
  keyed to whatever the site labels them.
- Downloads depend on third-party image hosts (`temp.compsci88.com`,
  `hot.planeptune.us`). If one starts refusing requests, pages fail
  individually and the per-page URLs are now printed in the error log.
- You are responsible for what you download and for complying with copyright
  law and the site's terms in your jurisdiction.
