Metadata-Version: 2.4
Name: wattpdl
Version: 1.2.0
Summary: Script Python + Rich CLI untuk mengunduh cerita Wattpad ke .txt/.docx offline
Author: nekonaru
License: MIT
Project-URL: Homepage, https://github.com/nekonaru/wattpdl
Project-URL: Repository, https://github.com/nekonaru/wattpdl
Project-URL: Issues, https://github.com/nekonaru/wattpdl/issues
Keywords: wattpad,downloader,cli,scraper,offline-reading
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Environment :: Console
Classifier: Topic :: Internet
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.31
Requires-Dist: rich>=13.7
Requires-Dist: python-docx>=1.1
Requires-Dist: EbookLib>=0.18
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.16; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Dynamic: license-file

<div align="center">

```
                         ██╗    ██╗ █████╗ ████████╗████████╗██████╗ ██████╗ ██╗     
                         ██║    ██║██╔══██╗╚══██╔══╝╚══██╔══╝██╔══██╗██╔══██╗██║     
                         ██║ █╗ ██║███████║   ██║      ██║   ██████╔╝██║  ██║██║     
                         ██║███╗██║██╔══██║   ██║      ██║   ██╔═══╝ ██║  ██║██║     
                         ╚███╔███╔╝██║  ██║   ██║      ██║   ██║     ██████╔╝███████╗
                         ╚══╝╚══╝ ╚═╝  ╚═╝   ╚═╝      ╚═╝   ╚═╝     ╚═════╝ ╚══════╝
```

### 📖 Wattpad Story Downloader
**Simpan cerita favoritmu jadi file `.txt`, `.docx`, atau `.epub`, lengkap atau per chapter, secara offline.**

<br>

![Python](https://img.shields.io/badge/Python-3.9%2B-3776AB?style=flat-square&logo=python&logoColor=white)
![PyPI](https://img.shields.io/pypi/v/wattpdl?style=flat-square&color=blue)
![License](https://img.shields.io/badge/License-MIT-green?style=flat-square)
![Platform](https://img.shields.io/badge/Platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey?style=flat-square)
![Status](https://img.shields.io/badge/Status-Active-brightgreen?style=flat-square)
![Tests](https://github.com/nekonaru/wattpdl/actions/workflows/tests.yml/badge.svg)

</div>

## ✨ Tentang Project

**WattPDL** adalah script Python ringan yang mengunduh chapter dari cerita Wattpad pilihanmu, lalu menyimpannya sebagai file `.txt` polos, dokumen Word `.docx`, atau ebook `.epub` yang bersih dan rapi. Kamu bisa unduh seluruh cerita jadi satu file, semua chapter terpisah dalam satu `.zip`, atau cukup chapter tertentu yang kamu pilih sendiri. Tidak perlu login, tidak perlu API key, cukup link atau ID ceritanya.

> _"Karena cerita yang bagus layak dibaca kapan saja, bahkan tanpa internet."_

## 🎯 Fitur

| Fitur | Keterangan |
|-------|------------|
| 🎨 **Tampilan CLI rapi** | Panel, tabel info cerita, dan warna berkat library `rich` |
| 🧩 **4 mode unduh** | Semua jadi 1 file, semua terpisah dalam `.zip`, pilih beberapa chapter, atau cukup 1 chapter |
| 📄 **3 pilihan format** | Simpan sebagai `.txt` polos, dokumen Word `.docx`, atau ebook `.epub` |
| 📁 **Pilih folder simpan** | Default ke folder `Downloads` sistem, bisa dikustomisasi |
| 🔄 **Auto-retry** | Chapter gagal dicoba ulang hingga 3× sebelum dilewati |
| 📊 **Progress bar animasi** | Spinner, persentase, jumlah chapter, dan estimasi waktu tersisa |
| 📋 **Ringkasan akhir** | Panel laporan chapter yang gagal (jika ada) setelah selesai |
| 🗂 **Nama file aman** | Karakter ilegal otomatis dihapus dari nama file |
| 🔗 **Link sumber tersimpan** | URL cerita dicantumkan di header file hasil |
| ⚡ **Tanpa login** | Pakai endpoint publik Wattpad, jadi tidak butuh akun |
| ↻ **Resume otomatis** | Kalau proses terhenti di tengah jalan, jalankan ulang cerita yang sama — chapter yang sudah berhasil tidak diunduh ulang |
| ⚙️ **Ingat preferensi** | Folder simpan & format file terakhir otomatis dipakai lagi di sesi berikutnya |
| 🤖 **Mode non-interaktif** | Bisa dijalankan lewat argumen command line untuk scripting/otomatisasi, tanpa perlu jawab prompt |

## 📦 Requirements

- **Python** 3.9 atau lebih baru
- **Koneksi internet**
- Library: `requests`, `rich`, `python-docx`, `EbookLib` — otomatis terinstall bareng `wattpdl`, tidak perlu diinstall manual

### Belum pernah pakai terminal? Ikuti ini dulu

<details>
<summary><b>🪟 Cara buka terminal di Windows</b></summary>

1. Tekan tombol **Windows**, ketik `PowerShell`, lalu tekan **Enter**
2. Jendela hitam/biru akan terbuka. Itu tempat kamu mengetik perintah
3. Semua perintah `python ...` atau `pip ...` di panduan ini diketik di jendela itu, lalu tekan **Enter**

</details>

<details>
<summary><b>🍎 Cara buka terminal di macOS</b></summary>

1. Tekan **Cmd + Spasi**, ketik `Terminal`, lalu tekan **Enter**
2. Ketik perintah-perintah di panduan ini di situ, lalu tekan **Enter**

</details>

<details>
<summary><b>🐧 Cara buka terminal di Linux</b></summary>

Tekan **Ctrl + Alt + T**, atau cari aplikasi "Terminal" di menu aplikasi.

</details>

### Belum punya Python?

1. Buka [python.org/downloads](https://www.python.org/downloads/) dan unduh versi terbaru
2. **Khusus Windows**: saat instalasi, centang dulu kotak **"Add Python to PATH"** di layar pertama sebelum klik Install. Kalau ini kelewat, perintah `python` nanti tidak akan dikenali
3. Setelah selesai install, buka terminal (lihat panduan di atas) lalu cek dengan:

```bash
python --version
# atau
python3 --version
```

Kalau muncul angka versi (misal `Python 3.12.1`), berarti sudah siap.

## 🚀 Instalasi

### Cara A: Install dari PyPI (paling gampang)

```bash
pip install wattpdl
```

> Kalau `pip` tidak dikenali, coba:
> ```bash
> python -m pip install wattpdl
> ```

> Kalau muncul error `externally-managed-environment` (biasanya di Linux):
> ```bash
> pip install wattpdl --break-system-packages
> ```

Setelah terinstall, command `wattpdl` langsung bisa dipakai dari terminal mana saja — lanjut ke bagian [Cara Pakai](#️-cara-pakai).

### Cara B: Install dari source (untuk development / mau lihat/ubah kode)

**1. Ambil kode project ini**

<details>
<summary><b>Punya Git terinstall</b></summary>

```bash
git clone https://github.com/nekonaru/wattpdl.git
cd wattpdl
```

</details>

<details>
<summary><b>Tidak punya Git</b></summary>

1. Buka halaman repository di GitHub
2. Klik tombol hijau **`Code`** → pilih **`Download ZIP`**
3. Ekstrak file ZIP yang terunduh ke folder pilihanmu
4. Di terminal, masuk ke folder hasil ekstrak, contoh:

```bash
cd Downloads/wattpdl-main
```

</details>

**2. Install dalam mode "editable"**
```bash
pip install -e .
```

> Sama seperti Cara A, tambahkan `--break-system-packages` di akhir kalau muncul error `externally-managed-environment`.

Ini juga mendaftarkan command `wattpdl`, tapi mengambil kodenya langsung dari folder ini — cocok kalau kamu mau modifikasi kode dan langsung lihat hasilnya tanpa install ulang.

## 🖥️ Cara Pakai

**Jalankan:**
```bash
wattpdl
```

> Kalau kamu install dari source tanpa `pip install -e .`, jalankan lewat `python -m wattpdl` dari dalam folder `src/` — tapi cara Editable Install di atas lebih direkomendasikan.

**Masukkan link atau ID cerita saat diminta:**
```
Link atau ID cerita Wattpad: https://www.wattpad.com/story/123456789-judul-cerita
```
atau cukup ID-nya:
```
Link atau ID cerita Wattpad: 123456789
```

**Pilih mode unduh:**
```
  1  Semua chapter → 1 file gabungan
  2  Semua chapter → file terpisah per chapter, dikemas .zip
  3  Pilih beberapa chapter → 1 file gabungan
  4  Pilih 1 chapter saja

Pilih mode [1/2/3/4] (1):
```

- **Mode 1**: cara paling umum, seluruh cerita jadi satu file rapi dari chapter pertama sampai terakhir
- **Mode 2**: cocok kalau mau baca per chapter terpisah, hasilnya satu `.zip` berisi file per chapter
- **Mode 3**: muncul daftar semua judul chapter bernomor, lalu ketik nomor yang mau diunduh, bisa gabung koma dan rentang, contoh: `1,3,5-8`
- **Mode 4**: muncul daftar semua judul chapter, ketik satu nomor untuk unduh chapter itu saja

**Pilih format file:**
```
  1  Teks polos (.txt)
  2  Dokumen Word (.docx)
  3  Ebook (.epub)

Pilih format file [1/2/3] (1):
```

**Pilih folder penyimpanan:**
```
Folder default: C:\Users\user\Downloads
Tekan Enter untuk pakai folder itu, atau ketik path lain:
```
Tekan **Enter** untuk simpan di `Downloads`, atau ketik path kustom seperti:
- Windows: `D:\Cerita\Wattpad`
- Linux/macOS: `/home/user/cerita`

**Tunggu proses selesai:**
```
⠋ Chapter 24...              ████████████████░░░░░░░░░░░░░░  53.3%  24/45  0:00:12  sisa 0:00:11
```

**Done! 🎉**
```
╔══════ 🎉 Berhasil!  Semua chapter tersimpan ══════╗
║ 📁 File tersimpan di   C:\Users\user\Downloads\Judul_Cerita.txt ║
║ ✅ Berhasil            45/45                                    ║
║ ⏱️  Waktu total         2m 18d                                   ║
╚═══════════════════════════════════════════════════╝
```

## ↻ Resume Otomatis

Kalau proses unduh terhenti di tengah jalan (koneksi putus, terminal ditutup, laptop mati), setiap chapter yang **sudah berhasil** diunduh tersimpan otomatis di `~/.wattpdl/progress/<id_cerita>.json`.

Jalankan lagi dengan cerita yang sama (ID/link sama), dan WattPDL akan:
- Melewati chapter yang sudah berhasil (dipakai dari cache, tidak fetch ulang)
- Hanya mengunduh chapter yang belum berhasil / gagal sebelumnya

File progress otomatis dihapus setelah semua chapter berhasil diunduh dalam satu sesi. Kalau mau paksa unduh ulang dari awal, hapus manual folder `~/.wattpdl/progress/`.

## ⚙️ Preferensi Tersimpan

Folder simpan dan format file terakhir yang kamu pilih otomatis tersimpan di `~/.wattpdl/config.json`, dan dipakai lagi sebagai default di sesi berikutnya — gak perlu isi ulang tiap kali jalanin script.

## 🤖 Mode Non-Interaktif (Scripting/Otomatisasi)

Selain mode tanya-jawab, WattPDL juga bisa dijalankan lewat argumen command line — cocok buat dijadwalkan (cron/Task Scheduler) atau dipanggil dari script lain.

```bash
wattpdl --id 398440633 --mode 1 --format docx
```

**Argumen yang tersedia:**

| Argumen | Keterangan |
|---|---|
| `--id` | ID atau link cerita Wattpad. Mengisi ini mengaktifkan mode non-interaktif. |
| `--mode {1,2,3,4}` | 1 = semua jadi 1 file, 2 = semua terpisah `.zip`, 3 = pilih beberapa chapter, 4 = pilih 1 chapter |
| `--format {txt,docx,epub}` | Format file output. Default: dari config tersimpan, atau `txt` |
| `--chapters` | Nomor chapter untuk `--mode 3`, contoh: `1,3,5-8` |
| `--chapter` | Nomor chapter untuk `--mode 4`, contoh: `5` |
| `--output-dir` | Folder penyimpanan custom. Default: dari config tersimpan, atau folder `Downloads` |

**Contoh lain:**

```bash
# Unduh semua chapter sebagai .zip terpisah
wattpdl --id 398440633 --mode 2 --format txt

# Unduh chapter 1, 3, dan 5-8 saja, jadi 1 file gabungan
wattpdl --id 398440633 --mode 3 --chapters 1,3,5-8 --format docx

# Unduh chapter 10 saja, simpan ke folder custom
wattpdl --id 398440633 --mode 4 --chapter 10 --output-dir "D:\Cerita Wattpad"

# Unduh semua chapter jadi 1 ebook .epub
wattpdl --id 398440633 --mode 1 --format epub

# Lihat semua opsi
wattpdl --help
```

## 📂 Struktur Output

Nama dan bentuk file yang dihasilkan tergantung mode & format yang kamu pilih:

| Mode | Format `.txt` | Format `.docx` | Format `.epub` |
|------|----------------|-----------------|------------------|
| 1 - Semua, gabungan | `Judul_Cerita.txt` | `Judul_Cerita.docx` | `Judul_Cerita.epub` |
| 2 - Semua, terpisah | `Judul_Cerita.zip` (isi: `.txt` per chapter) | `Judul_Cerita.zip` (isi: `.docx` per chapter) | `Judul_Cerita.zip` (isi: `.epub` per chapter) |
| 3 - Beberapa chapter | `Judul_Cerita_pilihan.txt` | `Judul_Cerita_pilihan.docx` | `Judul_Cerita_pilihan.epub` |
| 4 - Satu chapter | `Judul_Cerita_Ch003_Nama_Chapter.txt` | `Judul_Cerita_Ch003_Nama_Chapter.docx` | `Judul_Cerita_Ch003_Nama_Chapter.epub` |

**Isi file gabungan (mode 1 & 3):** judul cerita, penulis, dan sumber di bagian atas, lalu tiap chapter dipisah dengan penanda `#####`.

```
Judul Cerita
oleh Nama Penulis
Sumber : https://www.wattpad.com/story/123456789

==================================================

##### Judul Chapter 1 #####

Isi teks chapter 1...

##### Judul Chapter 2 #####

Isi teks chapter 2...
```

Di versi `.docx`, judul cerita jadi heading utama dan tiap chapter otomatis jadi Heading 1 dengan halaman baru, tinggal buka di Word atau Google Docs dan langsung enak dibaca.

Di versi `.epub`, cerita jadi ebook standar dengan daftar isi (table of contents) otomatis per chapter — tinggal buka di aplikasi pembaca ebook favoritmu (Google Play Books, Apple Books, Calibre, dll).

**Isi zip (mode 2):** satu file per chapter, bernomor urut sesuai posisi di cerita, plus `000_info.txt`/`000_info.docx`/`000_info.epub` berisi judul, penulis, dan sumber. Ekstensi file di dalam zip mengikuti format yang dipilih saat menjalankan script (`.txt`, `.docx`, atau `.epub`):

```
Judul_Cerita.zip
├── 000_info.txt
├── 001_Judul_Chapter_1.txt
├── 002_Judul_Chapter_2.txt
└── ...
```

## 🗺️ Default Folder per OS

| Sistem Operasi | Folder Default |
|----------------|----------------|
| 🪟 Windows | `C:\Users\<namauser>\Downloads` |
| 🍎 macOS | `/Users/<namauser>/Downloads` |
| 🐧 Linux | `/home/<namauser>/Downloads` |

## ⚠️ Troubleshooting

| Masalah | Solusi |
|---------|--------|
| `ModuleNotFoundError: No module named 'requests'` | Jalankan `pip install requests` |
| `ModuleNotFoundError: No module named 'rich'` | Jalankan `pip install rich` |
| `Library 'python-docx' belum terinstall` | Jalankan `pip install python-docx` (cuma dibutuhkan kalau memilih format `.docx`) |
| `Library 'EbookLib' belum terinstall` | Jalankan `pip install EbookLib` (cuma dibutuhkan kalau memilih format `.epub`) |
| Error `404` / "Tidak ada chapter ditemukan" | Pastikan ID/link benar & cerita tidak di-private |
| Folder tidak bisa dibuat | Cek path valid & kamu punya izin tulis di sana |
| Proses macet di satu chapter | Cek koneksi internet, jalankan ulang, progress akan lanjut |

## 📝 Catatan Penting

- ID cerita adalah angka di URL Wattpad, tepat setelah `/story/`
- Script memakai endpoint publik, tidak butuh login atau API key
- Jeda **0.5 detik** antar chapter sudah diatur untuk menghindari rate limit server, jangan dihapus
- Script ini hanya untuk membaca cerita milik sendiri atau cerita publik secara offline. Hormati hak cipta penulis

## 🛠️ Dibuat dengan

![Python](https://img.shields.io/badge/-Python-3776AB?style=flat-square&logo=python&logoColor=white)
![Requests](https://img.shields.io/badge/-Requests-FF6B6B?style=flat-square)
![Rich](https://img.shields.io/badge/-Rich-FAE742?style=flat-square)
![python--docx](https://img.shields.io/badge/-python--docx-2B579A?style=flat-square)
![Wattpad API](https://img.shields.io/badge/-Wattpad%20Public%20API-FF6122?style=flat-square)

## 🗂️ Struktur Project

```
wattpdl/
├── src/
│   └── wattpdl/
│       ├── __init__.py       # metadata package (__version__)
│       ├── __main__.py       # entry untuk `python -m wattpdl`
│       ├── app.py            # orkestrasi alur program (main())
│       ├── api.py            # komunikasi ke Wattpad public API
│       ├── writers.py        # konversi teks & penulisan file .txt/.docx/.zip
│       ├── cli.py            # tampilan terminal (rich), interaksi dengan user
│       ├── cli_args.py       # parsing argumen untuk mode non-interaktif
│       ├── config.py         # simpan preferensi user (folder simpan, format)
│       └── progress.py       # cache progress unduhan untuk fitur resume
├── requirements.txt          # daftar dependency (untuk referensi manual)
├── pyproject.toml            # metadata package + build config + ruff
├── tests/
│   ├── __init__.py
│   └── test_wattpdl.py       # unit test (pytest)
├── .github/
│   └── workflows/
│       ├── tests.yml         # CI: test, lint, & build check otomatis
│       └── publish.yml       # auto-publish ke PyPI saat rilis baru
├── CONTRIBUTING.md           # panduan kontribusi
├── LICENSE
└── README.md
```

**Prinsip pemisahan modul:**
- `api.py` — tidak tahu apa-apa soal tampilan (`rich`), murni fetch data
- `writers.py` — tidak melakukan request jaringan, murni konversi & tulis file
- `cli.py` — semua interaksi dengan user & tampilan progress bar
- `cli_args.py` — parsing & validasi argumen command line, tidak ada logika bisnis
- `config.py` / `progress.py` — baca-tulis file JSON di `~/.wattpdl/`, tidak tahu soal CLI atau jaringan
- `app.py` — menyatukan semuanya, tanpa logika bisnis sendiri (dipanggil lewat command `wattpdl` setelah install)

## 🧪 Testing

Ada unit test untuk fungsi-fungsi inti (parsing ID cerita, validasi nama file, parsing pilihan chapter, konversi HTML ke teks, config, progress/resume, parsing argumen CLI, dll).

```bash
pip install -e .[dev]
pytest tests/ -v
ruff check .
```

## 🤝 Kontribusi

Mau bantu kembangin WattPDL? Baca [`CONTRIBUTING.md`](CONTRIBUTING.md) untuk struktur project dan alur kontribusi.

## ❓ FAQ

<details>
<summary><b>Apakah ini legal / aman dipakai?</b></summary>

Script ini memakai endpoint publik Wattpad yang sama seperti saat kamu baca cerita lewat browser, jadi tidak meng-hack apa pun. Tapi gunakan secara bertanggung jawab: unduh untuk bacaan pribadi/offline, dan hormati hak cipta penulis. Jangan sebar ulang atau jual isi cerita orang lain.

</details>

<details>
<summary><b>Apakah butuh akun Wattpad?</b></summary>

Tidak. Tidak perlu login atau API key sama sekali.

</details>

<details>
<summary><b>Cerita private / dihapus, bisa diunduh?</b></summary>

Tidak. Script hanya bisa mengakses cerita yang memang publik.

</details>

<details>
<summary><b>Prosesnya lama, kenapa?</b></summary>

Ada jeda 0.5 detik antar chapter (sengaja, biar tidak membebani server Wattpad). Untuk cerita ratusan chapter, wajar kalau prosesnya makan waktu beberapa menit.

</details>

<details>
<summary><b>Mode dan format mana yang sebaiknya dipilih?</b></summary>

- Mau baca dari awal sampai akhir kayak buku → **Mode 1**, format `.epub` paling enak dibaca di aplikasi ebook
- Mau tiap chapter jadi file sendiri-sendiri → **Mode 2**
- Cuma butuh beberapa chapter tertentu (misal lagi ulang baca bagian tertentu) → **Mode 3**
- Cuma penasaran satu chapter → **Mode 4**
- Mau baca santai di HP/tablet pakai aplikasi ebook (Google Play Books, Apple Books, dll) → pilih format **`.epub`**
- Mau edit atau print rapi pakai Word → pilih format **`.docx`**
- Mau file kecil dan simpel, atau mau dibaca di aplikasi e-reader/notes → pilih format **`.txt`**

</details>

## 👤 Author

<div align="center">

| [![Nicolas Dwi Dharma](https://github.com/github.png?size=100)](https://github.com/nekonaru) |
|:---:|
| **Nicolas Dwi Dharma** |
| [github.com/nekonaru](https://github.com/nekonaru) |

</div>

## 📄 License

Distributed under the **MIT License**. See [`LICENSE`](LICENSE) for more information.

<div align="center">

Made with by **Nicolas Dwi Dharma**

*Star ⭐ repo ini kalau project ini membantumu!*

</div>
