summaryrefslogtreecommitdiff
path: root/python-kobodl.spec
blob: 24bd73e96a784fd175491575e25549c22b590aaf (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
%global _empty_manifest_terminate_build 0
Name:		python-kobodl
Version:	0.9.3
Release:	1
Summary:	Kobo Book Downloader
License:	Unlicense
URL:		https://github.com/subdavis/kobo-book-downloader.git
Source0:	https://mirrors.aliyun.com/pypi/web/packages/c3/79/230dc7a287e0f014efee03d1ddcba0a681ed4054e11b3b19a3f3108d3321/kobodl-0.9.3.tar.gz
BuildArch:	noarch

Requires:	python3-beautifulsoup4
Requires:	python3-click
Requires:	python3-dataclasses
Requires:	python3-dataclasses-json
Requires:	python3-flask
Requires:	python3-pycryptodome
Requires:	python3-pyperclip
Requires:	python3-requests
Requires:	python3-tabulate

%description
![kobodl logo](docs/kobodl.png)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/subdavis/kobo-book-downloader/Publish%20Docker%20Container?style=for-the-badge)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/subdavis/kobo-book-downloader?style=for-the-badge)
![PyPI - Downloads](https://img.shields.io/pypi/dm/kobodl?style=for-the-badge)
![PyPI - License](https://img.shields.io/pypi/l/kobodl?style=for-the-badge)
![PyPI](https://img.shields.io/pypi/v/kobodl?style=for-the-badge)
# kobodl
This is a hard fork of [kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader), a command line tool to download and remove Digital Rights Management (DRM) protection from media legally purchased from [Rakuten Kobo](https://www.kobo.com/). The resulting [EPUB](https://en.wikipedia.org/wiki/EPUB) files can be read with, amongst others, [KOReader](https://github.com/koreader/koreader).
> **NOTE:** You must have a kobo email login for this tool to work (you can't use an external provider like Google or Facebook). However, you can create a NEW kobo account and link it with your existing account on the user profile page. Go to `My Account -> Account Settings` to link your new kobo login.
## Features
kobodl preserves the features from [TnS-hun/kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader).
* stand-alone; no need to run other software or pre-download through an e-reader.
* downloads `.epub` formatted books
It adds several new features.
* **audiobook support**; command-line only for now.
  * Use `kobodl book get`. There will not be a download button in the webpage for audiobooks because they consist of many large files.
* **multi-user support**; fetch books for multiple accounts.
* **web interface**; adds new browser gui (with flask)
* **CalibreWeb Integration**; send books directly to CalibreWeb from the web interface.
* [docker image](https://github.com/subdavis/kobodl/pkgs/container/kobodl)
* [pypi package](https://pypi.org/project/kobodl/)
* [pyinstaller bundles](https://github.com/subdavis/kobo-book-downloader/releases/latest)
## Web UI
WebUI provides most of the same functions of the CLI. It was added to allow other members of a household to add their accounts to kobodl and access their books without having to set up python.
### User page
![Example of User page](docs/webss.png)
### Book list page
![Example of book list page](docs/books3.png)
## Installation
### pipx
``` bash
pipx install kobodl
```
### pip
``` bash
pip install kobodl
```
### Pre-built bundles
No python installation necessary.  Simply download the appropriate executable from [the latest release assets](https://github.com/subdavis/kobo-book-downloader/releases/latest) and run it from the command line.  Pre-built bundles are CLI-only (no web server) so use a different install option if you want that feature.
``` bash
# Linux
wget https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-ubuntu
chmod +x kobodl-ubuntu
./kobodl-ubuntu
```
``` bash
# MacOS (Catalina 10.15 or newer required.  For older versions, use the pip or docker install option)
wget https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-macos
chmod +x kobodl-macos
./kobodl-macos
```
``` powershell
# Windows Powershell example
wget "https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-windows.exe" -outfile "kobodl.exe"
./kobodl.exe
```
### docker
> *Note*: for rootless docker installations (uncommon), omit the `--user` argument.
``` bash
# list users
docker run --rm -it --user $(id -u):$(id -g) \
  -v ${HOME}/.config:/home/config \
  ghcr.io/subdavis/kobodl \
  --config /home/config/kobodl.json user list
# run http server
docker run --rm -it --user $(id -u):$(id -g) \
  -p 5000:5000 \
  -v ${HOME}/.config:/home/config \
  -v ${PWD}:/home/downloads \
  ghcr.io/subdavis/kobodl \
  --config /home/config/kobodl.json \
  serve \
  --host 0.0.0.0 \
  --output-dir /home/downloads/kobodl_downloads
```
[Also see the **docker-compose** example file.](./docker-compose.yml)
## Usage
General usage documentation.
> **Note**: These are commands you type into a shell prompt like Terminal (Ubuntu, MacOS) or Powershell or CMD (Windows).  You may need to replace `kobodl` with `./kobodl.exe`, `./kobodl-macos-latest`, or something else, depending on which installation method you chose.
``` bash
# Get started by adding one or more users
# See `Getting a reCAPTCHA code` below for more help
kobodl user add
# List users
kobodl user list
# Remove a user
kobodl user rm email@domain.com
# List books
kobodl book list
# List books for a single user
kobodl book list --user email@domain.com
# List all books, including those marked as read
kobodl book list --read
# Show book list help
kobodl book list --help
# Download a single book with default options when only 1 user exists
# default output directory is `./kobo_downloads` 
kobodl book get c1db3f5c-82da-4dda-9d81-fa718d5d1d16
# Download a single book with advanced options
kobodl book get \
  --user email@domain.com \
  --output-dir /path/to/download_directory \
  --format-str '{Title}' \
  c1db3f5c-82da-4dda-9d81-fa718d5d1d16
# Download ALL books with default options when only 1 user exists
kobodl book get --get-all
# Download ALL books with advanced options
kobodl book get \
  --user email@domain.com \
  --output-dir /path/to/download_directory \
  --format-str '{Title}' \
  --get-all
```
Running the web UI
``` bash
kobodl serve
 * Serving Flask app "kobodl.app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
```
Global options
``` bash
# argument format
kobodl [OPTIONS] COMMAND [ARGS]...
# set python tabulate formatting style.
kobodl --fmt "pretty" COMMAND [ARGS]...
# set config path if different than ~/.config/kobodl.json
kobodl --config /path/to/kobodl.json COMMAND [ARGS]...
# get version
kobodl --version
# enable debugging, prints to "debug.log"
kobodl --debug [OPTIONS] COMMAND [ARGS]...
```
## Getting a reCAPTCHA code
Adding a user requires a bit of hackery to get a reCAPTCHA code from Kobo's website. This GIF helps to explain how to do that.
![Gif explaining how to get reCAPTHCA](docs/captcha.gif)
## CalibreWeb Integration: **Experimental**
Kobodl's web interface can send books directly to your calibre web server.  Only supported from web client.
You must add your CalibreWeb server and user details directly in kobodl.json.  Make sure to include `/upload` in the url.  If you don't have CalibreWeb authentication on, leave these fields blank (`""`).
``` json
{
    "users": [ /* ... */ ],
    "calibre_web": {
        "enabled": true,
        "url": "https://calibre.domain.com/upload",
        "username": "CHANGEME",
        "password": "CHANGEME"
    }
}
```
> **NOTE**: you may need to add escape characters if your password contains a `\`, `"`, or others that require JSON escaping.
## Troubleshooting
> Some of my books are missing!
Try `kobodl book list --read` to show all "finished" and "archived" books.  You can manage your book status on [the library page](https://kobo.com/library).  Try changing the status using the "..." button.
> I see a mesage about "skipping _____" when I download all.
Try to download the book individually using `kobodl book get <revision-id>`, replacing `revision-id` with the UUID from the list table.
> I can't log in.  I get a message saying "The page format might have changed"
This happens from time to time, maybe once or twice a year.  Kobo changes their login page and makes it hard for the tool to parse out the necessary information.  Please open an issue.
> Something else is going wrong!
Try enabling debugging.  Run `kobodl --debug book get` (for example), which will dump a lot of data into a file called `debug.log`. Email me this file. Do not post it in public on an issue because it will contain information about your account.  My email address can be found on my [github profile page](https://github.com/subdavis).
## Development
This project uses [Python Poetry](https://python-poetry.org/).
```bash
pip install poetry
git clone https://github.com/subdavis/kobo-book-downloader
poetry install
# Run command line app
poetry run kobodl
# Run linting
poetry run tox -e lint
# Run standalone bundle generation
poetry run tox -e buildcli
# Run type checks
poetry run tox -e type
```
## Notes
kobo-book-downloader will prompt for your [Kobo](https://www.kobo.com/) e-mail address and password. Once it has successfully logged in, it won't ask for them again. Your password will not be stored on disk; Kobodl uses access tokens after the initial login.
Credit recursively to [kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader) and the projects that lead to it.
## FAQ
**How does this work?**
kobodl works by pretending to be an Android Kobo e-reader.  It initializes a device, fetches your library, and downloads books as a "fake" Android app.
**Why does this download KEPUB formatted books?**
Kobo has different formats that it serves to different platforms.  For example, Desktop users generally get `EPUB3` books with `AdobeDrm` DRM.  Android users typically get `KEPUB` books with `KDRM` DRM, which is fairly easy to remove, so that's what you get when you use this tool.
**Is this tool safe and okay to use?**
I'm not a lawyer, and the discussion below is strictly academic.
The author(s) of `kobodl` don't collect any information about you or your account aside from what is made available through metrics from GitHub, PyPi, Docker Hub, etc.  See `LICENSE.md` for further info.
Kobo would probably claim that this tool violates its [Terms of Use](https://authorize.kobo.com/terms/termsofuse) but I'm not able to conclusively determine that it does so.  Some relevant sections are reproduced here.
> The download of, and access to any Digital Content is available only to Customers and is intended only for such Customers’ personal and non-commercial use. Any other use of Digital Content downloaded or accessed from the Service is strictly prohibited
This tool should only be used to download books for personal use.
> You may not obscure or misrepresent your geographical location, forge headers, use proxies, use IP spoofing or otherwise manipulate identifiers in order to disguise the origin of any message or transmittal you send on or through the Service. You may not pretend that you are, or that you represent, someone else, or impersonate any other individual or entity.
This might be a violation.  This client announces itself to Kobo servers as an Android device, which can safely be construed as "manipulating identifiers", but whether or not the purpose is to "disguise the origin" is unclear.
> Kobo may also take steps to prevent fraud, such as restricting the number of titles that may be accessed at one time, and monitoring Customer accounts for any activity that may violate these Terms. If Kobo discovers any type of fraud, Kobo reserves the right to take enforcement action including the termination or suspension of a User’s account.
In other words, you could have your account suspended for using `kobodl`. **Please open an issue on the issue tracker if this happens to you.**

%package -n python3-kobodl
Summary:	Kobo Book Downloader
Provides:	python-kobodl
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-kobodl
![kobodl logo](docs/kobodl.png)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/subdavis/kobo-book-downloader/Publish%20Docker%20Container?style=for-the-badge)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/subdavis/kobo-book-downloader?style=for-the-badge)
![PyPI - Downloads](https://img.shields.io/pypi/dm/kobodl?style=for-the-badge)
![PyPI - License](https://img.shields.io/pypi/l/kobodl?style=for-the-badge)
![PyPI](https://img.shields.io/pypi/v/kobodl?style=for-the-badge)
# kobodl
This is a hard fork of [kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader), a command line tool to download and remove Digital Rights Management (DRM) protection from media legally purchased from [Rakuten Kobo](https://www.kobo.com/). The resulting [EPUB](https://en.wikipedia.org/wiki/EPUB) files can be read with, amongst others, [KOReader](https://github.com/koreader/koreader).
> **NOTE:** You must have a kobo email login for this tool to work (you can't use an external provider like Google or Facebook). However, you can create a NEW kobo account and link it with your existing account on the user profile page. Go to `My Account -> Account Settings` to link your new kobo login.
## Features
kobodl preserves the features from [TnS-hun/kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader).
* stand-alone; no need to run other software or pre-download through an e-reader.
* downloads `.epub` formatted books
It adds several new features.
* **audiobook support**; command-line only for now.
  * Use `kobodl book get`. There will not be a download button in the webpage for audiobooks because they consist of many large files.
* **multi-user support**; fetch books for multiple accounts.
* **web interface**; adds new browser gui (with flask)
* **CalibreWeb Integration**; send books directly to CalibreWeb from the web interface.
* [docker image](https://github.com/subdavis/kobodl/pkgs/container/kobodl)
* [pypi package](https://pypi.org/project/kobodl/)
* [pyinstaller bundles](https://github.com/subdavis/kobo-book-downloader/releases/latest)
## Web UI
WebUI provides most of the same functions of the CLI. It was added to allow other members of a household to add their accounts to kobodl and access their books without having to set up python.
### User page
![Example of User page](docs/webss.png)
### Book list page
![Example of book list page](docs/books3.png)
## Installation
### pipx
``` bash
pipx install kobodl
```
### pip
``` bash
pip install kobodl
```
### Pre-built bundles
No python installation necessary.  Simply download the appropriate executable from [the latest release assets](https://github.com/subdavis/kobo-book-downloader/releases/latest) and run it from the command line.  Pre-built bundles are CLI-only (no web server) so use a different install option if you want that feature.
``` bash
# Linux
wget https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-ubuntu
chmod +x kobodl-ubuntu
./kobodl-ubuntu
```
``` bash
# MacOS (Catalina 10.15 or newer required.  For older versions, use the pip or docker install option)
wget https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-macos
chmod +x kobodl-macos
./kobodl-macos
```
``` powershell
# Windows Powershell example
wget "https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-windows.exe" -outfile "kobodl.exe"
./kobodl.exe
```
### docker
> *Note*: for rootless docker installations (uncommon), omit the `--user` argument.
``` bash
# list users
docker run --rm -it --user $(id -u):$(id -g) \
  -v ${HOME}/.config:/home/config \
  ghcr.io/subdavis/kobodl \
  --config /home/config/kobodl.json user list
# run http server
docker run --rm -it --user $(id -u):$(id -g) \
  -p 5000:5000 \
  -v ${HOME}/.config:/home/config \
  -v ${PWD}:/home/downloads \
  ghcr.io/subdavis/kobodl \
  --config /home/config/kobodl.json \
  serve \
  --host 0.0.0.0 \
  --output-dir /home/downloads/kobodl_downloads
```
[Also see the **docker-compose** example file.](./docker-compose.yml)
## Usage
General usage documentation.
> **Note**: These are commands you type into a shell prompt like Terminal (Ubuntu, MacOS) or Powershell or CMD (Windows).  You may need to replace `kobodl` with `./kobodl.exe`, `./kobodl-macos-latest`, or something else, depending on which installation method you chose.
``` bash
# Get started by adding one or more users
# See `Getting a reCAPTCHA code` below for more help
kobodl user add
# List users
kobodl user list
# Remove a user
kobodl user rm email@domain.com
# List books
kobodl book list
# List books for a single user
kobodl book list --user email@domain.com
# List all books, including those marked as read
kobodl book list --read
# Show book list help
kobodl book list --help
# Download a single book with default options when only 1 user exists
# default output directory is `./kobo_downloads` 
kobodl book get c1db3f5c-82da-4dda-9d81-fa718d5d1d16
# Download a single book with advanced options
kobodl book get \
  --user email@domain.com \
  --output-dir /path/to/download_directory \
  --format-str '{Title}' \
  c1db3f5c-82da-4dda-9d81-fa718d5d1d16
# Download ALL books with default options when only 1 user exists
kobodl book get --get-all
# Download ALL books with advanced options
kobodl book get \
  --user email@domain.com \
  --output-dir /path/to/download_directory \
  --format-str '{Title}' \
  --get-all
```
Running the web UI
``` bash
kobodl serve
 * Serving Flask app "kobodl.app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
```
Global options
``` bash
# argument format
kobodl [OPTIONS] COMMAND [ARGS]...
# set python tabulate formatting style.
kobodl --fmt "pretty" COMMAND [ARGS]...
# set config path if different than ~/.config/kobodl.json
kobodl --config /path/to/kobodl.json COMMAND [ARGS]...
# get version
kobodl --version
# enable debugging, prints to "debug.log"
kobodl --debug [OPTIONS] COMMAND [ARGS]...
```
## Getting a reCAPTCHA code
Adding a user requires a bit of hackery to get a reCAPTCHA code from Kobo's website. This GIF helps to explain how to do that.
![Gif explaining how to get reCAPTHCA](docs/captcha.gif)
## CalibreWeb Integration: **Experimental**
Kobodl's web interface can send books directly to your calibre web server.  Only supported from web client.
You must add your CalibreWeb server and user details directly in kobodl.json.  Make sure to include `/upload` in the url.  If you don't have CalibreWeb authentication on, leave these fields blank (`""`).
``` json
{
    "users": [ /* ... */ ],
    "calibre_web": {
        "enabled": true,
        "url": "https://calibre.domain.com/upload",
        "username": "CHANGEME",
        "password": "CHANGEME"
    }
}
```
> **NOTE**: you may need to add escape characters if your password contains a `\`, `"`, or others that require JSON escaping.
## Troubleshooting
> Some of my books are missing!
Try `kobodl book list --read` to show all "finished" and "archived" books.  You can manage your book status on [the library page](https://kobo.com/library).  Try changing the status using the "..." button.
> I see a mesage about "skipping _____" when I download all.
Try to download the book individually using `kobodl book get <revision-id>`, replacing `revision-id` with the UUID from the list table.
> I can't log in.  I get a message saying "The page format might have changed"
This happens from time to time, maybe once or twice a year.  Kobo changes their login page and makes it hard for the tool to parse out the necessary information.  Please open an issue.
> Something else is going wrong!
Try enabling debugging.  Run `kobodl --debug book get` (for example), which will dump a lot of data into a file called `debug.log`. Email me this file. Do not post it in public on an issue because it will contain information about your account.  My email address can be found on my [github profile page](https://github.com/subdavis).
## Development
This project uses [Python Poetry](https://python-poetry.org/).
```bash
pip install poetry
git clone https://github.com/subdavis/kobo-book-downloader
poetry install
# Run command line app
poetry run kobodl
# Run linting
poetry run tox -e lint
# Run standalone bundle generation
poetry run tox -e buildcli
# Run type checks
poetry run tox -e type
```
## Notes
kobo-book-downloader will prompt for your [Kobo](https://www.kobo.com/) e-mail address and password. Once it has successfully logged in, it won't ask for them again. Your password will not be stored on disk; Kobodl uses access tokens after the initial login.
Credit recursively to [kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader) and the projects that lead to it.
## FAQ
**How does this work?**
kobodl works by pretending to be an Android Kobo e-reader.  It initializes a device, fetches your library, and downloads books as a "fake" Android app.
**Why does this download KEPUB formatted books?**
Kobo has different formats that it serves to different platforms.  For example, Desktop users generally get `EPUB3` books with `AdobeDrm` DRM.  Android users typically get `KEPUB` books with `KDRM` DRM, which is fairly easy to remove, so that's what you get when you use this tool.
**Is this tool safe and okay to use?**
I'm not a lawyer, and the discussion below is strictly academic.
The author(s) of `kobodl` don't collect any information about you or your account aside from what is made available through metrics from GitHub, PyPi, Docker Hub, etc.  See `LICENSE.md` for further info.
Kobo would probably claim that this tool violates its [Terms of Use](https://authorize.kobo.com/terms/termsofuse) but I'm not able to conclusively determine that it does so.  Some relevant sections are reproduced here.
> The download of, and access to any Digital Content is available only to Customers and is intended only for such Customers’ personal and non-commercial use. Any other use of Digital Content downloaded or accessed from the Service is strictly prohibited
This tool should only be used to download books for personal use.
> You may not obscure or misrepresent your geographical location, forge headers, use proxies, use IP spoofing or otherwise manipulate identifiers in order to disguise the origin of any message or transmittal you send on or through the Service. You may not pretend that you are, or that you represent, someone else, or impersonate any other individual or entity.
This might be a violation.  This client announces itself to Kobo servers as an Android device, which can safely be construed as "manipulating identifiers", but whether or not the purpose is to "disguise the origin" is unclear.
> Kobo may also take steps to prevent fraud, such as restricting the number of titles that may be accessed at one time, and monitoring Customer accounts for any activity that may violate these Terms. If Kobo discovers any type of fraud, Kobo reserves the right to take enforcement action including the termination or suspension of a User’s account.
In other words, you could have your account suspended for using `kobodl`. **Please open an issue on the issue tracker if this happens to you.**

%package help
Summary:	Development documents and examples for kobodl
Provides:	python3-kobodl-doc
%description help
![kobodl logo](docs/kobodl.png)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/subdavis/kobo-book-downloader/Publish%20Docker%20Container?style=for-the-badge)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/subdavis/kobo-book-downloader?style=for-the-badge)
![PyPI - Downloads](https://img.shields.io/pypi/dm/kobodl?style=for-the-badge)
![PyPI - License](https://img.shields.io/pypi/l/kobodl?style=for-the-badge)
![PyPI](https://img.shields.io/pypi/v/kobodl?style=for-the-badge)
# kobodl
This is a hard fork of [kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader), a command line tool to download and remove Digital Rights Management (DRM) protection from media legally purchased from [Rakuten Kobo](https://www.kobo.com/). The resulting [EPUB](https://en.wikipedia.org/wiki/EPUB) files can be read with, amongst others, [KOReader](https://github.com/koreader/koreader).
> **NOTE:** You must have a kobo email login for this tool to work (you can't use an external provider like Google or Facebook). However, you can create a NEW kobo account and link it with your existing account on the user profile page. Go to `My Account -> Account Settings` to link your new kobo login.
## Features
kobodl preserves the features from [TnS-hun/kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader).
* stand-alone; no need to run other software or pre-download through an e-reader.
* downloads `.epub` formatted books
It adds several new features.
* **audiobook support**; command-line only for now.
  * Use `kobodl book get`. There will not be a download button in the webpage for audiobooks because they consist of many large files.
* **multi-user support**; fetch books for multiple accounts.
* **web interface**; adds new browser gui (with flask)
* **CalibreWeb Integration**; send books directly to CalibreWeb from the web interface.
* [docker image](https://github.com/subdavis/kobodl/pkgs/container/kobodl)
* [pypi package](https://pypi.org/project/kobodl/)
* [pyinstaller bundles](https://github.com/subdavis/kobo-book-downloader/releases/latest)
## Web UI
WebUI provides most of the same functions of the CLI. It was added to allow other members of a household to add their accounts to kobodl and access their books without having to set up python.
### User page
![Example of User page](docs/webss.png)
### Book list page
![Example of book list page](docs/books3.png)
## Installation
### pipx
``` bash
pipx install kobodl
```
### pip
``` bash
pip install kobodl
```
### Pre-built bundles
No python installation necessary.  Simply download the appropriate executable from [the latest release assets](https://github.com/subdavis/kobo-book-downloader/releases/latest) and run it from the command line.  Pre-built bundles are CLI-only (no web server) so use a different install option if you want that feature.
``` bash
# Linux
wget https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-ubuntu
chmod +x kobodl-ubuntu
./kobodl-ubuntu
```
``` bash
# MacOS (Catalina 10.15 or newer required.  For older versions, use the pip or docker install option)
wget https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-macos
chmod +x kobodl-macos
./kobodl-macos
```
``` powershell
# Windows Powershell example
wget "https://github.com/subdavis/kobo-book-downloader/releases/latest/download/kobodl-windows.exe" -outfile "kobodl.exe"
./kobodl.exe
```
### docker
> *Note*: for rootless docker installations (uncommon), omit the `--user` argument.
``` bash
# list users
docker run --rm -it --user $(id -u):$(id -g) \
  -v ${HOME}/.config:/home/config \
  ghcr.io/subdavis/kobodl \
  --config /home/config/kobodl.json user list
# run http server
docker run --rm -it --user $(id -u):$(id -g) \
  -p 5000:5000 \
  -v ${HOME}/.config:/home/config \
  -v ${PWD}:/home/downloads \
  ghcr.io/subdavis/kobodl \
  --config /home/config/kobodl.json \
  serve \
  --host 0.0.0.0 \
  --output-dir /home/downloads/kobodl_downloads
```
[Also see the **docker-compose** example file.](./docker-compose.yml)
## Usage
General usage documentation.
> **Note**: These are commands you type into a shell prompt like Terminal (Ubuntu, MacOS) or Powershell or CMD (Windows).  You may need to replace `kobodl` with `./kobodl.exe`, `./kobodl-macos-latest`, or something else, depending on which installation method you chose.
``` bash
# Get started by adding one or more users
# See `Getting a reCAPTCHA code` below for more help
kobodl user add
# List users
kobodl user list
# Remove a user
kobodl user rm email@domain.com
# List books
kobodl book list
# List books for a single user
kobodl book list --user email@domain.com
# List all books, including those marked as read
kobodl book list --read
# Show book list help
kobodl book list --help
# Download a single book with default options when only 1 user exists
# default output directory is `./kobo_downloads` 
kobodl book get c1db3f5c-82da-4dda-9d81-fa718d5d1d16
# Download a single book with advanced options
kobodl book get \
  --user email@domain.com \
  --output-dir /path/to/download_directory \
  --format-str '{Title}' \
  c1db3f5c-82da-4dda-9d81-fa718d5d1d16
# Download ALL books with default options when only 1 user exists
kobodl book get --get-all
# Download ALL books with advanced options
kobodl book get \
  --user email@domain.com \
  --output-dir /path/to/download_directory \
  --format-str '{Title}' \
  --get-all
```
Running the web UI
``` bash
kobodl serve
 * Serving Flask app "kobodl.app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
```
Global options
``` bash
# argument format
kobodl [OPTIONS] COMMAND [ARGS]...
# set python tabulate formatting style.
kobodl --fmt "pretty" COMMAND [ARGS]...
# set config path if different than ~/.config/kobodl.json
kobodl --config /path/to/kobodl.json COMMAND [ARGS]...
# get version
kobodl --version
# enable debugging, prints to "debug.log"
kobodl --debug [OPTIONS] COMMAND [ARGS]...
```
## Getting a reCAPTCHA code
Adding a user requires a bit of hackery to get a reCAPTCHA code from Kobo's website. This GIF helps to explain how to do that.
![Gif explaining how to get reCAPTHCA](docs/captcha.gif)
## CalibreWeb Integration: **Experimental**
Kobodl's web interface can send books directly to your calibre web server.  Only supported from web client.
You must add your CalibreWeb server and user details directly in kobodl.json.  Make sure to include `/upload` in the url.  If you don't have CalibreWeb authentication on, leave these fields blank (`""`).
``` json
{
    "users": [ /* ... */ ],
    "calibre_web": {
        "enabled": true,
        "url": "https://calibre.domain.com/upload",
        "username": "CHANGEME",
        "password": "CHANGEME"
    }
}
```
> **NOTE**: you may need to add escape characters if your password contains a `\`, `"`, or others that require JSON escaping.
## Troubleshooting
> Some of my books are missing!
Try `kobodl book list --read` to show all "finished" and "archived" books.  You can manage your book status on [the library page](https://kobo.com/library).  Try changing the status using the "..." button.
> I see a mesage about "skipping _____" when I download all.
Try to download the book individually using `kobodl book get <revision-id>`, replacing `revision-id` with the UUID from the list table.
> I can't log in.  I get a message saying "The page format might have changed"
This happens from time to time, maybe once or twice a year.  Kobo changes their login page and makes it hard for the tool to parse out the necessary information.  Please open an issue.
> Something else is going wrong!
Try enabling debugging.  Run `kobodl --debug book get` (for example), which will dump a lot of data into a file called `debug.log`. Email me this file. Do not post it in public on an issue because it will contain information about your account.  My email address can be found on my [github profile page](https://github.com/subdavis).
## Development
This project uses [Python Poetry](https://python-poetry.org/).
```bash
pip install poetry
git clone https://github.com/subdavis/kobo-book-downloader
poetry install
# Run command line app
poetry run kobodl
# Run linting
poetry run tox -e lint
# Run standalone bundle generation
poetry run tox -e buildcli
# Run type checks
poetry run tox -e type
```
## Notes
kobo-book-downloader will prompt for your [Kobo](https://www.kobo.com/) e-mail address and password. Once it has successfully logged in, it won't ask for them again. Your password will not be stored on disk; Kobodl uses access tokens after the initial login.
Credit recursively to [kobo-book-downloader](https://github.com/TnS-hun/kobo-book-downloader) and the projects that lead to it.
## FAQ
**How does this work?**
kobodl works by pretending to be an Android Kobo e-reader.  It initializes a device, fetches your library, and downloads books as a "fake" Android app.
**Why does this download KEPUB formatted books?**
Kobo has different formats that it serves to different platforms.  For example, Desktop users generally get `EPUB3` books with `AdobeDrm` DRM.  Android users typically get `KEPUB` books with `KDRM` DRM, which is fairly easy to remove, so that's what you get when you use this tool.
**Is this tool safe and okay to use?**
I'm not a lawyer, and the discussion below is strictly academic.
The author(s) of `kobodl` don't collect any information about you or your account aside from what is made available through metrics from GitHub, PyPi, Docker Hub, etc.  See `LICENSE.md` for further info.
Kobo would probably claim that this tool violates its [Terms of Use](https://authorize.kobo.com/terms/termsofuse) but I'm not able to conclusively determine that it does so.  Some relevant sections are reproduced here.
> The download of, and access to any Digital Content is available only to Customers and is intended only for such Customers’ personal and non-commercial use. Any other use of Digital Content downloaded or accessed from the Service is strictly prohibited
This tool should only be used to download books for personal use.
> You may not obscure or misrepresent your geographical location, forge headers, use proxies, use IP spoofing or otherwise manipulate identifiers in order to disguise the origin of any message or transmittal you send on or through the Service. You may not pretend that you are, or that you represent, someone else, or impersonate any other individual or entity.
This might be a violation.  This client announces itself to Kobo servers as an Android device, which can safely be construed as "manipulating identifiers", but whether or not the purpose is to "disguise the origin" is unclear.
> Kobo may also take steps to prevent fraud, such as restricting the number of titles that may be accessed at one time, and monitoring Customer accounts for any activity that may violate these Terms. If Kobo discovers any type of fraud, Kobo reserves the right to take enforcement action including the termination or suspension of a User’s account.
In other words, you could have your account suspended for using `kobodl`. **Please open an issue on the issue tracker if this happens to you.**

%prep
%autosetup -n kobodl-0.9.3

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "\"/%h/%f\"\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "\"/%h/%f.gz\"\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-kobodl -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Tue Jun 20 2023 Python_Bot <Python_Bot@openeuler.org> - 0.9.3-1
- Package Spec generated