File size: 9,255 Bytes
976c248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7600c8b
 
0e7dc9f
976c248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47e088b
 
 
 
 
 
 
 
 
 
 
976c248
 
 
 
 
5df8575
 
aa49f24
9b1b573
aa49f24
 
5df8575
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
976c248
 
 
 
5df8575
 
 
 
 
976c248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47e088b
 
 
 
 
9b1b573
 
aa49f24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
---

title: Torrent Web Downloader
emoji: 🧲
colorFrom: blue
colorTo: green
sdk: docker
app_port: 5000
---


# Torrent Web Downloader

Aplikasi web torrent berbasis Python + Flask yang mengontrol `qbittorrent-nox` dari dalam satu container Docker.

Fitur utama:

- upload file `.torrent`
- tambah magnet link
- status torrent realtime
- pause, resume, delete
- auto cancel untuk torrent stuck
- upload file atau folder hasil torrent ke GoFile atau PixelDrain
  mode folder: archive `.zip` atau raw files melalui modal pilihan
- panel ringkasan server dan speedtest

## Jalankan Dengan Docker

Build image:

```bash

docker build . -t torrent-app

```

Run container:

```bash

docker run -d \

  --name torrent-app \

  -p 5000:5000 \

  -p 6881:6881 \

  -p 6881:6881/udp \

  -e FLASK_SECRET_KEY=change-me \

  -e PORT=5000 \

  -e QBITTORRENT_USERNAME=admin \

  -e QBITTORRENT_PASSWORD=adminadmin \

  -e QBT_PROFILE=/config \

  -e QBITTORRENT_SAVE_PATH=/downloads \

  -v torrent-config:/config \

  -v torrent-downloads:/downloads \

  torrent-app

```

Web app tersedia di:

- `http://localhost:5000`

## Docker Compose

Proyek sekarang memakai satu `Dockerfile` default. File [docker-compose.yml](./docker-compose.yml) masih disediakan hanya sebagai opsi lokal, tetapi deployment utama sudah didesain untuk:

- `docker build . -t torrent-app`
- `docker run ...`

## Environment Variables

- `PORT`: port web Flask yang diexpose ke luar. Default `5000`
- `GUNICORN_WORKERS`: jumlah worker Gunicorn. Default `2`
- `GUNICORN_THREADS`: jumlah thread per worker. Default `4`
- `GUNICORN_TIMEOUT`: timeout request Gunicorn. Default `120`
- `KEEPALIVE_ENABLED`: aktifkan scheduler ping ringan untuk mencegah idle sleep saat container masih berjalan. Default `true`
- `KEEPALIVE_URL`: URL yang diping oleh keepalive. Default memakai `https://$SPACE_HOST/healthz` di Hugging Face Spaces, atau `http://127.0.0.1:$PORT/healthz` di luar Spaces
- `KEEPALIVE_INTERVAL_SECONDS`: interval ping keepalive. Default `900`
- `KEEPALIVE_INITIAL_DELAY_SECONDS`: jeda awal sebelum ping pertama. Default `60`
- `KEEPALIVE_TIMEOUT_SECONDS`: timeout request keepalive. Default `20`
- `FLASK_SECRET_KEY`: secret key Flask
- `QBITTORRENT_USERNAME`: login qBittorrent Web API. Default `admin`
- `QBITTORRENT_PASSWORD`: password qBittorrent Web API. Default `adminadmin`
- `QBT_PROFILE`: direktori config qBittorrent. Default `/config`, atau `/data/qbittorrent` bila `/data` tersedia
- `QBITTORRENT_SAVE_PATH`: direktori hasil download. Default `/downloads`, atau `/data/downloads` bila `/data` tersedia
- `GOFILE_API_TOKEN`: token opsional untuk GoFile
  diperlukan untuk mode raw folder GoFile
- `GOFILE_UPLOAD_URLS`: daftar endpoint upload GoFile dipisahkan koma. Default mencoba beberapa server resmi GoFile dan otomatis mengurutkannya berdasarkan latency terdekat
- `PIXELDRAIN_API_KEY`: API key PixelDrain untuk upload via API
- `PIXELDRAIN_API_URL`: base API PixelDrain. Default `https://pixeldrain.com/api`
- `RCLONE_CONFIG_URL`: raw URL untuk mengambil `rclone.conf`, misalnya raw GitHub atau Gist. Jika kosong, app membaca file lokal
- `RCLONE_CONFIG_PATH`: path file `rclone.conf` lokal. Default `/app/rclone.conf`. App juga mencoba `/config/rclone.conf` dan `/data/rclone.conf`
- `RCLONE_REMOTE`: nama remote rclone yang dipakai. Jika kosong, app memakai remote pertama dari `rclone.conf`
- `RCLONE_DESTINATION_PATH`: folder tujuan di remote rclone. Default `torrent-web`
- `IP_LOCATION_API_URL`: endpoint lookup lokasi. Default `https://ipapi.co/json/`
- `TORRENT_STUCK_TIMEOUT_MINUTES`: timeout torrent stuck. Default `5`
- `TELEGRAM_BOT_ENABLED`: set `true` untuk menjalankan bot Telegram di container yang sama. Default `false`
- `TELEGRAM_API_ID`: API ID Telegram untuk Kurigram
- `TELEGRAM_API_HASH`: API hash Telegram untuk Kurigram
- `TELEGRAM_BOT_TOKEN`: token bot dari BotFather
- `TELEGRAM_OWNER_IDS`: daftar user ID Telegram yang boleh memakai bot, dipisah koma. Kosong berarti semua user diizinkan
- `TELEGRAM_PROGRESS_INTERVAL_SECONDS`: interval edit pesan progress bot. Default `3`
- `TELEGRAM_PROGRESS_TIMEOUT_SECONDS`: batas waktu monitor progress per pesan. Default `86400`

## Telegram Bot

Bot Telegram bersifat opsional dan memakai `kurigram`. Struktur bot ada di `bot/bot.py`, terpisah dari Flask, tetapi memakai state/download path yang sama sehingga task dari bot tetap muncul di dashboard web.

Command awal:

- `/qm <magnet>` atau `/qbdown <magnet>` untuk tambah magnet ke qBittorrent
- `/aria2 <url>` untuk direct download via Aria2
- `/tasks` untuk melihat task terbaru
- `/status <task_id>` untuk memantau task tertentu

Saat task selesai, pesan progress bot menampilkan inline button untuk upload ke GoFile atau PixelDrain, refresh, delete, dan delete files.

## Struktur

- `Dockerfile` image tunggal untuk web app + qBittorrent
- `entrypoint.sh` startup script untuk menjalankan `qbittorrent-nox` dan `gunicorn`
- `app.py` aplikasi Flask
- `bot/bot.py` bot Telegram berbasis Kurigram
- `templates/index.html` UI Tailwind
- `qbittorrent/config/qBittorrent.conf` konfigurasi default qBittorrent

## ClawCloud Run

Sesuai dokumentasi resmi ClawCloud Run, deployment Docker dilakukan dari App Launchpad dengan memilih image, exposed port, environment variables, dan local storage volume jika dibutuhkan.

Referensi resmi:

- ClawCloud Run docs: `https://docs.run.claw.cloud/`
- Deploy from Docker: `https://docs.run.claw.cloud/app-platform/getting-started/deploy-from-docker`
- App Launchpad guide: `https://docs.run.claw.cloud/clawcloud-run/guide/app-launchpad`

Konfigurasi yang disarankan untuk ClawCloud Run:

1. Build image ini lalu push ke registry publik atau private Anda.
2. Di App Launchpad, buat app baru dari Docker image tersebut.
3. Set exposed port ke `5000` atau samakan dengan env `PORT`.
4. Tambahkan environment variables:
   - `PORT=5000`
   - `FLASK_SECRET_KEY=...`
   - `QBITTORRENT_USERNAME=admin`
   - `QBITTORRENT_PASSWORD=adminadmin`
   - `QBT_PROFILE=/config`
   - `QBITTORRENT_SAVE_PATH=/downloads`
5. Tambahkan persistent storage:
   - mount `/config` untuk profile qBittorrent
   - mount `/downloads` untuk file hasil download
6. Jika platform Anda hanya mengekspos satu public port, cukup expose `5000`. qBittorrent WebUI internal tetap dipakai oleh Flask lewat `127.0.0.1:8080`.

Catatan:

- Dukungan PaaS terbaik di sini adalah model single-container, single-public-port.
- Peer BitTorrent inbound port `6881` bisa dipetakan di Docker biasa, tetapi pada PaaS support-nya bergantung kemampuan platform untuk membuka port tambahan.
- Jika ClawCloud Run hanya mengizinkan satu public port, aplikasi tetap bisa berjalan, tetapi performa peer discovery torrent bisa berbeda dibanding VPS atau Docker host biasa.

## Hugging Face Spaces

Repo ini sekarang bisa dipakai sebagai Docker Space karena `README.md` sudah memakai metadata `sdk: docker` dan `app_port: 5000`.

Langkah deploy:

1. Buat Space baru di Hugging Face dan pilih SDK `Docker`.
2. Push isi repo ini ke repository Space tersebut.
3. Di Settings, tambahkan runtime variables bila diperlukan:
   - `FLASK_SECRET_KEY=...`
   - `QBITTORRENT_USERNAME=admin`
   - `QBITTORRENT_PASSWORD=adminadmin`
4. Jika ingin data tetap tersimpan setelah restart, aktifkan persistent storage. Saat volume `/data` tersedia, aplikasi ini otomatis memakai:
   - `/data/qbittorrent` untuk profile qBittorrent
   - `/data/downloads` untuk hasil download
5. Akses aplikasi dari URL Space Anda. Port publik yang dipakai adalah `5000`.

Catatan:

- Hugging Face Spaces Docker hanya mengekspos satu public port. qBittorrent internal tetap berjalan di `127.0.0.1:8080` dan diakses oleh Flask dari dalam container.
- Tanpa persistent storage, file config dan hasil download akan hilang saat Space restart.
- Koneksi peer BitTorrent tambahan seperti port `6881` tidak bisa diasumsikan terbuka dari internet pada Spaces, jadi perilaku swarm bisa berbeda dibanding VPS atau Docker host biasa.
- Container menjalankan keepalive scheduler yang memanggil endpoint ringan `/healthz` secara periodik. Di Spaces, target defaultnya adalah `https://$SPACE_HOST/healthz`, sehingga request melewati URL publik Space.
- Keepalive ini hanya bekerja saat container masih berjalan. Jika Space sudah terlanjur stopped/sleep, proses di dalam container tidak bisa membangunkan dirinya sendiri; untuk uptime penuh gunakan hardware berbayar atau set sleep time resmi dari Settings Hugging Face.
- Provider rclone aktif jika `rclone.conf` valid ditemukan. Anda bisa set `RCLONE_CONFIG_URL`, mount file ke `/config/rclone.conf` atau `/data/rclone.conf`, atau isi raw URL langsung dari modal rclone di dashboard.
- Jika tidak ada config, aplikasi tetap berjalan. Saat tombol rclone diklik, dashboard akan membuka modal setup raw URL, misalnya `https://gist.githubusercontent.com/genstava789/e7fa4e34e126bfc257b21db4f8c0f3ba/raw/rclone.conf`.
- Upload rclone memakai `rclone copyto` untuk file atau archive `.zip`, dan `rclone copy` untuk folder raw. Setelah upload selesai, app mencoba `rclone link`; jika backend remote mendukung public/download link, link tersebut ditampilkan di dashboard.