intellireading-cli 2.1.0__tar.gz → 2.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: intellireading-cli
3
- Version: 2.1.0
3
+ Version: 2.1.1
4
4
  Summary: Intellireading-cli is a Python library with a set of tools to improve your reading experience
5
5
  Project-URL: Documentation, https://go.hugobatista.com/gh/intellireading-cli#readme
6
6
  Project-URL: Issues, https://go.hugobatista.com/gh/intellireading-cli/issues
7
7
  Project-URL: Source, https://go.hugobatista.com/gh/intellireading-cli
8
- Author: Hugo Batista
8
+ Project-URL: Homepage, https://go.hugobatista.com/gh/intellireading-cli
9
+ Project-URL: Repository, https://go.hugobatista.com/gh/intellireading-cli.git
10
+ Author: Hugo Batista <intellireading at hugobatista.com>
9
11
  License-Expression: GPL-3.0
10
12
  License-File: LICENSE
11
13
  Keywords: adhd,calibre,dyslexia,ebook,epub,kepub,kindle,kobo,speed-reading
@@ -32,7 +34,7 @@ Requires-Dist: lxml>=4.9.2
32
34
  Requires-Dist: regex>=2024.11.6
33
35
  Description-Content-Type: text/markdown
34
36
 
35
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/intellireading.png)
37
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/intellireading.png)
36
38
  # Standalone tool and library
37
39
 
38
40
  [![PyPI - Version](https://img.shields.io/pypi/v/intellireading-cli.svg)](https://pypi.org/project/intellireading-cli)
@@ -40,15 +42,15 @@ Description-Content-Type: text/markdown
40
42
  [![Deploy to ghcr.io](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml)
41
43
  [![Lint](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml)
42
44
  [![Test](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml)
45
+ [![GitMCP](https://img.shields.io/endpoint?url=https://gitmcp.io/badge/hugobatista/intellireading-cli)](https://gitmcp.io/hugobatista/intellireading-cli)
43
46
 
44
-
45
- Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a python library.
47
+ Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a Python library.
46
48
  Currently, it supports metaguiding an EPUB, KEPUB, XHTML, or HTML file (more features coming):
47
49
  ```console
48
50
  > intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub
49
51
  ```
50
52
  Example of a text converted to a metaguided text:
51
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/sample.png)
53
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/sample.png)
52
54
 
53
55
 
54
56
  This repo is part of the [Intellireading](https://intellireading.com/) project, which aims to help people with dyslexia, ADHD, or anyone who wants to improve their reading focus and speed.
@@ -60,7 +62,7 @@ This repo is part of the [Intellireading](https://intellireading.com/) project,
60
62
  - [Calibre Plugins](https://go.hugobatista.com/gh/intellireading-calibre-plugins). A set of plugins that can be used to metaguide epub files using Calibre.
61
63
 
62
64
 
63
- ## What is Epub Metaguiding?
65
+ ## What is EPUB Metaguiding?
64
66
  **Metagu**iding **i**s **a** **techn**ique **th**at **ca**n **b**e **us**ed **t**o **impr**ove **yo**ur **read**ing **foc**us **an**d **spe**ed **(some**times **cal**led **Bio**nic **Readi**ng). **I**t **i**s **bas**ed **o**n **th**e **id**ea **th**at **yo**u **ca**n **us**e **a** **vis**ual **gui**de **t**o **he**lp **yo**ur **ey**es **foc**us **o**n **th**e **te**xt **yo**u **ar**e **read**ing. **I**n **th**is **cas**e, **th**e **vis**ual **gui**de **i**s **do**ne **b**y **bold**ing **a** **pa**rt **o**f **th**e **tex**t, **crea**ting **vis**ual **anch**ors **th**at **yo**ur **ey**es **ca**n **us**e **t**o **foc**us **o**n **th**e **tex**t. **Th**is **i**s **simi**lar **t**o **th**e **wa**y **a** **fin**ger **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **a** **li**ne **o**f **tex**t, **whi**ch **ha**s **be**en **sho**wn **t**o **impr**ove **read**ing **spe**ed **an**d **foc**us. ([**stu**dy: **"Do**es **finger-t**racking **poi**nt **t**o **chi**ld **read**ing **strate**gies"](https://ceur-ws.org/Vol-2769/paper_60.pdf))
65
67
 
66
68
  **Howe**ver, **unl**ike **a** **fing**er, **th**e **vis**ual **gui**de **i**s **no**t **distra**cting, **an**d **i**t **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **mult**iple **lin**es **o**f **te**xt **a**t **onc**e. **Th**is **all**ows **yo**u **t**o **re**ad **fast**er, **an**d **wi**th **le**ss **effo**rt.
@@ -74,8 +76,8 @@ Intellireading commands can be used to:
74
76
  - **Metaguide an XHTML file**: Metaguide an XHTML file, transforming it into a metaguided XHTML file.
75
77
  - **Metaguide a directory**: Metaguide all files in a directory, transforming all EPUB, XHTML, and HTML files into metaguided files.
76
78
 
77
-
78
79
  ## Installation
80
+
79
81
  Intellireading is a command line tool that can be used in Windows, Linux, and MacOS. It is written in Python and can be used as a module or as a standalone tool, as long as you have Python >3.7 installed (or Docker).
80
82
 
81
83
  ### pip
@@ -93,29 +95,28 @@ You can also install it from the source code:
93
95
  > pip install .
94
96
  > intellireading --help
95
97
  ```
98
+
96
99
  ### Docker
97
100
  Alternatively, you can use the Docker image:
98
101
 
99
102
  #### Help command
100
103
  ```console
101
- > docker pull ghcr.io/0x6f677548/intellireading-cli:latest
102
- > docker run -it --rm ghcr.io/0x6f677548/intellireading-cli --help
104
+ > docker pull ghcr.io/hugobatista/intellireading-cli:latest
105
+ > docker run -it --rm ghcr.io/hugobatista/intellireading-cli --help
103
106
  ```
104
107
 
105
108
  #### Metaguide an EPUB file
106
109
  ##### Linux/MacOS
107
110
  ```console
108
- ```linux
109
- > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
111
+ > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
110
112
  ```
111
113
  ##### Windows
112
114
  ```powershell
113
- > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
115
+ > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
114
116
  ```
115
117
 
118
+ ## CLI Usage
116
119
 
117
-
118
- ## Usage
119
120
  All available commands and options can be seen by using the `--help` option.
120
121
  ```console
121
122
  > intellireading --help
@@ -128,7 +129,7 @@ To get help on a specific command, use the `--help` option with the command name
128
129
 
129
130
  Intellireading is based on [Click](https://github.com/pallets/click/), taking advantage of its features, such as chaining commands and options.
130
131
 
131
- ### Usage Examples
132
+ ### CLI Examples
132
133
 
133
134
  #### Metaguide an EPUB file
134
135
  To metaguide an EPUB file, use the `metaguide-epub` command. The command requires the path to the EPUB file and the output file. The output file will be a metaguided epub file.
@@ -177,3 +178,210 @@ To remove metaguiding from all files in a directory, use the --remove_metaguidin
177
178
  ```console
178
179
  > intellireading metaguide-dir --remove_metaguiding --input_dir mydir_metaguided --output_dir mydir
179
180
  ```
181
+
182
+ ## Python Library API
183
+
184
+ The intellireading-cli package can be used as a Python library for programmatic access to metaguiding functionality. This is useful for integrating metaguiding into web applications, batch processing scripts, or other Python projects.
185
+
186
+ ### Quick Start
187
+
188
+ ```python
189
+ from intellireading.client import (
190
+ metaguide_epub_file,
191
+ metaguide_xhtml_file,
192
+ metaguide_epub_stream,
193
+ metaguide_xhtml_stream,
194
+ metaguide_dir,
195
+ is_file_metaguided
196
+ )
197
+
198
+ # Metaguide an EPUB file
199
+ metaguide_epub_file("input.epub", "output.epub")
200
+
201
+ # Metaguide an XHTML file
202
+ metaguide_xhtml_file("input.html", "output.html")
203
+ ```
204
+
205
+ ### Core Functions
206
+
207
+ #### EPUB Functions
208
+
209
+ **`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
210
+
211
+ Metaguides an EPUB file by applying visual anchoring to text content within all XHTML files in the EPUB.
212
+
213
+ ```python
214
+ from intellireading.client import metaguide_epub_file
215
+
216
+ # Basic metaguiding
217
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
218
+
219
+ # Remove metaguiding (experimental)
220
+ metaguide_epub_file(
221
+ "mybook_metaguided.epub",
222
+ "mybook_original.epub",
223
+ remove_metaguiding=True
224
+ )
225
+ ```
226
+
227
+ **`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
228
+
229
+ Metaguides an EPUB from a byte stream, useful for in-memory processing or web applications.
230
+
231
+ ```python
232
+ from io import BytesIO
233
+ from intellireading.client import metaguide_epub_stream
234
+
235
+ # Read EPUB into memory
236
+ with open("input.epub", "rb") as f:
237
+ input_stream = BytesIO(f.read())
238
+
239
+ # Metaguide the stream
240
+ output_stream = metaguide_epub_stream(input_stream)
241
+
242
+ # Write to file
243
+ with open("output.epub", "wb") as f:
244
+ f.write(output_stream.read())
245
+ ```
246
+
247
+ #### XHTML Functions
248
+
249
+ **`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
250
+
251
+ Metaguides an XHTML/HTML file by applying visual anchoring to text content. Supports `.xhtml`, `.html`, and `.htm` files.
252
+
253
+ ```python
254
+ from intellireading.client import metaguide_xhtml_file
255
+
256
+ # Metaguide an HTML file
257
+ metaguide_xhtml_file("article.html", "article_metaguided.html")
258
+
259
+ # Remove metaguiding
260
+ metaguide_xhtml_file(
261
+ "article_metaguided.html",
262
+ "article_restored.html",
263
+ remove_metaguiding=True
264
+ )
265
+ ```
266
+
267
+ **`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
268
+
269
+ Metaguides an XHTML/HTML file from a byte stream.
270
+
271
+ ```python
272
+ from io import BytesIO
273
+ from intellireading.client import metaguide_xhtml_stream
274
+
275
+ # Process HTML content from string
276
+ html_content = """
277
+ <!DOCTYPE html>
278
+ <html>
279
+ <body>
280
+ <p>This is a sample paragraph that will be metaguided.</p>
281
+ </body>
282
+ </html>
283
+ """
284
+
285
+ input_stream = BytesIO(html_content.encode('utf-8'))
286
+ output_stream = metaguide_xhtml_stream(input_stream)
287
+ metaguided_content = output_stream.read().decode('utf-8')
288
+ ```
289
+
290
+ #### Directory Functions
291
+
292
+ **`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False)`**
293
+
294
+ Metaguides all EPUB and XHTML/HTML files found in a directory recursively.
295
+
296
+ ```python
297
+ from intellireading.client import metaguide_dir
298
+
299
+ # Metaguide all books in the directory
300
+ metaguide_dir("books", "books_metaguided")
301
+
302
+ # Remove metaguiding from all files
303
+ metaguide_dir("books_metaguided", "books_restored", remove_metaguiding=True)
304
+ ```
305
+
306
+ #### Utility Functions
307
+
308
+ **`is_file_metaguided(filepath: str) -> bool`**
309
+
310
+ Checks if an EPUB file has already been metaguided.
311
+
312
+ ```python
313
+ from intellireading.client import is_file_metaguided, metaguide_epub_file
314
+
315
+ # Check if file is already metaguided
316
+ if not is_file_metaguided("mybook.epub"):
317
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
318
+ print("File metaguided successfully")
319
+ else:
320
+ print("File is already metaguided")
321
+ ```
322
+
323
+ ### Integration Examples
324
+
325
+ #### Web Application (Flask)
326
+
327
+ ```python
328
+ from flask import Flask, request, send_file
329
+ from io import BytesIO
330
+ from intellireading.client import metaguide_epub_stream
331
+
332
+ app = Flask(__name__)
333
+
334
+ @app.route('/metaguide', methods=['POST'])
335
+ def metaguide_upload():
336
+ file = request.files['epub']
337
+ if file and file.filename.endswith('.epub'):
338
+ input_stream = BytesIO(file.read())
339
+ output_stream = metaguide_epub_stream(input_stream)
340
+
341
+ return send_file(
342
+ output_stream,
343
+ as_attachment=True,
344
+ download_name=f"metaguided_{file.filename}",
345
+ mimetype='application/epub+zip'
346
+ )
347
+ return "Invalid file", 400
348
+ ```
349
+
350
+ #### Batch Processing
351
+
352
+ ```python
353
+ import os
354
+ from intellireading.client import metaguide_dir, is_file_metaguided
355
+
356
+ def batch_process_library(library_path):
357
+ """Process an entire library of EPUB files"""
358
+ processed_path = os.path.join(library_path, "metaguided")
359
+
360
+ # Process all files
361
+ metaguide_dir(library_path, processed_path)
362
+
363
+ # Verify results
364
+ for root, dirs, files in os.walk(processed_path):
365
+ for file in files:
366
+ if file.endswith('.epub'):
367
+ filepath = os.path.join(root, file)
368
+ if is_file_metaguided(filepath):
369
+ print(f"✓ Successfully metaguided: {file}")
370
+
371
+ batch_process_library("/path/to/my/books")
372
+ ```
373
+
374
+ ### Error Handling
375
+
376
+ ```python
377
+ from intellireading.client import metaguide_epub_file
378
+
379
+ try:
380
+ metaguide_epub_file("mybook.epub", "output.epub")
381
+ except ValueError as e:
382
+ print(f"Invalid file: {e}")
383
+ except FileNotFoundError as e:
384
+ print(f"File not found: {e}")
385
+ except Exception as e:
386
+ print(f"Unexpected error: {e}")
387
+ ```
@@ -1,4 +1,4 @@
1
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/intellireading.png)
1
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/intellireading.png)
2
2
  # Standalone tool and library
3
3
 
4
4
  [![PyPI - Version](https://img.shields.io/pypi/v/intellireading-cli.svg)](https://pypi.org/project/intellireading-cli)
@@ -6,15 +6,15 @@
6
6
  [![Deploy to ghcr.io](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/build-and-publish-to-ghcr.yml)
7
7
  [![Lint](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/lint.yml)
8
8
  [![Test](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml/badge.svg)](https://go.hugobatista.com/gh/intellireading-cli/actions/workflows/test.yml)
9
+ [![GitMCP](https://img.shields.io/endpoint?url=https://gitmcp.io/badge/hugobatista/intellireading-cli)](https://gitmcp.io/hugobatista/intellireading-cli)
9
10
 
10
-
11
- Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a python library.
11
+ Intellireading is a CLI tool with commands to accelerate your reading experience. It can also be used as a Python library.
12
12
  Currently, it supports metaguiding an EPUB, KEPUB, XHTML, or HTML file (more features coming):
13
13
  ```console
14
14
  > intellireading metaguide-epub --input_file mybook.epub --output_file mybook_metaguided.epub
15
15
  ```
16
16
  Example of a text converted to a metaguided text:
17
- ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/src/img/sample.png)
17
+ ![Intellireading.com](https://go.hugobatista.com/ghraw/intellireading-www/main/public/img/sample.png)
18
18
 
19
19
 
20
20
  This repo is part of the [Intellireading](https://intellireading.com/) project, which aims to help people with dyslexia, ADHD, or anyone who wants to improve their reading focus and speed.
@@ -26,7 +26,7 @@ This repo is part of the [Intellireading](https://intellireading.com/) project,
26
26
  - [Calibre Plugins](https://go.hugobatista.com/gh/intellireading-calibre-plugins). A set of plugins that can be used to metaguide epub files using Calibre.
27
27
 
28
28
 
29
- ## What is Epub Metaguiding?
29
+ ## What is EPUB Metaguiding?
30
30
  **Metagu**iding **i**s **a** **techn**ique **th**at **ca**n **b**e **us**ed **t**o **impr**ove **yo**ur **read**ing **foc**us **an**d **spe**ed **(some**times **cal**led **Bio**nic **Readi**ng). **I**t **i**s **bas**ed **o**n **th**e **id**ea **th**at **yo**u **ca**n **us**e **a** **vis**ual **gui**de **t**o **he**lp **yo**ur **ey**es **foc**us **o**n **th**e **te**xt **yo**u **ar**e **read**ing. **I**n **th**is **cas**e, **th**e **vis**ual **gui**de **i**s **do**ne **b**y **bold**ing **a** **pa**rt **o**f **th**e **tex**t, **crea**ting **vis**ual **anch**ors **th**at **yo**ur **ey**es **ca**n **us**e **t**o **foc**us **o**n **th**e **tex**t. **Th**is **i**s **simi**lar **t**o **th**e **wa**y **a** **fin**ger **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **a** **li**ne **o**f **tex**t, **whi**ch **ha**s **be**en **sho**wn **t**o **impr**ove **read**ing **spe**ed **an**d **foc**us. ([**stu**dy: **"Do**es **finger-t**racking **poi**nt **t**o **chi**ld **read**ing **strate**gies"](https://ceur-ws.org/Vol-2769/paper_60.pdf))
31
31
 
32
32
  **Howe**ver, **unl**ike **a** **fing**er, **th**e **vis**ual **gui**de **i**s **no**t **distra**cting, **an**d **i**t **ca**n **b**e **us**ed **t**o **gui**de **yo**ur **ey**es **alo**ng **mult**iple **lin**es **o**f **te**xt **a**t **onc**e. **Th**is **all**ows **yo**u **t**o **re**ad **fast**er, **an**d **wi**th **le**ss **effo**rt.
@@ -40,8 +40,8 @@ Intellireading commands can be used to:
40
40
  - **Metaguide an XHTML file**: Metaguide an XHTML file, transforming it into a metaguided XHTML file.
41
41
  - **Metaguide a directory**: Metaguide all files in a directory, transforming all EPUB, XHTML, and HTML files into metaguided files.
42
42
 
43
-
44
43
  ## Installation
44
+
45
45
  Intellireading is a command line tool that can be used in Windows, Linux, and MacOS. It is written in Python and can be used as a module or as a standalone tool, as long as you have Python >3.7 installed (or Docker).
46
46
 
47
47
  ### pip
@@ -59,29 +59,28 @@ You can also install it from the source code:
59
59
  > pip install .
60
60
  > intellireading --help
61
61
  ```
62
+
62
63
  ### Docker
63
64
  Alternatively, you can use the Docker image:
64
65
 
65
66
  #### Help command
66
67
  ```console
67
- > docker pull ghcr.io/0x6f677548/intellireading-cli:latest
68
- > docker run -it --rm ghcr.io/0x6f677548/intellireading-cli --help
68
+ > docker pull ghcr.io/hugobatista/intellireading-cli:latest
69
+ > docker run -it --rm ghcr.io/hugobatista/intellireading-cli --help
69
70
  ```
70
71
 
71
72
  #### Metaguide an EPUB file
72
73
  ##### Linux/MacOS
73
74
  ```console
74
- ```linux
75
- > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
75
+ > docker run -it --rm -v $(pwd)/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
76
76
  ```
77
77
  ##### Windows
78
78
  ```powershell
79
- > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/0x6f677548/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
79
+ > docker run -it --rm -v ${pwd}/tests:/tests ghcr.io/hugobatista/intellireading-cli metaguide-epub --input_file '/tests/test_files/input.epub' --output_file '/tests/test_files/output.epub'
80
80
  ```
81
81
 
82
+ ## CLI Usage
82
83
 
83
-
84
- ## Usage
85
84
  All available commands and options can be seen by using the `--help` option.
86
85
  ```console
87
86
  > intellireading --help
@@ -94,7 +93,7 @@ To get help on a specific command, use the `--help` option with the command name
94
93
 
95
94
  Intellireading is based on [Click](https://github.com/pallets/click/), taking advantage of its features, such as chaining commands and options.
96
95
 
97
- ### Usage Examples
96
+ ### CLI Examples
98
97
 
99
98
  #### Metaguide an EPUB file
100
99
  To metaguide an EPUB file, use the `metaguide-epub` command. The command requires the path to the EPUB file and the output file. The output file will be a metaguided epub file.
@@ -143,3 +142,210 @@ To remove metaguiding from all files in a directory, use the --remove_metaguidin
143
142
  ```console
144
143
  > intellireading metaguide-dir --remove_metaguiding --input_dir mydir_metaguided --output_dir mydir
145
144
  ```
145
+
146
+ ## Python Library API
147
+
148
+ The intellireading-cli package can be used as a Python library for programmatic access to metaguiding functionality. This is useful for integrating metaguiding into web applications, batch processing scripts, or other Python projects.
149
+
150
+ ### Quick Start
151
+
152
+ ```python
153
+ from intellireading.client import (
154
+ metaguide_epub_file,
155
+ metaguide_xhtml_file,
156
+ metaguide_epub_stream,
157
+ metaguide_xhtml_stream,
158
+ metaguide_dir,
159
+ is_file_metaguided
160
+ )
161
+
162
+ # Metaguide an EPUB file
163
+ metaguide_epub_file("input.epub", "output.epub")
164
+
165
+ # Metaguide an XHTML file
166
+ metaguide_xhtml_file("input.html", "output.html")
167
+ ```
168
+
169
+ ### Core Functions
170
+
171
+ #### EPUB Functions
172
+
173
+ **`metaguide_epub_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
174
+
175
+ Metaguides an EPUB file by applying visual anchoring to text content within all XHTML files in the EPUB.
176
+
177
+ ```python
178
+ from intellireading.client import metaguide_epub_file
179
+
180
+ # Basic metaguiding
181
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
182
+
183
+ # Remove metaguiding (experimental)
184
+ metaguide_epub_file(
185
+ "mybook_metaguided.epub",
186
+ "mybook_original.epub",
187
+ remove_metaguiding=True
188
+ )
189
+ ```
190
+
191
+ **`metaguide_epub_stream(input_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
192
+
193
+ Metaguides an EPUB from a byte stream, useful for in-memory processing or web applications.
194
+
195
+ ```python
196
+ from io import BytesIO
197
+ from intellireading.client import metaguide_epub_stream
198
+
199
+ # Read EPUB into memory
200
+ with open("input.epub", "rb") as f:
201
+ input_stream = BytesIO(f.read())
202
+
203
+ # Metaguide the stream
204
+ output_stream = metaguide_epub_stream(input_stream)
205
+
206
+ # Write to file
207
+ with open("output.epub", "wb") as f:
208
+ f.write(output_stream.read())
209
+ ```
210
+
211
+ #### XHTML Functions
212
+
213
+ **`metaguide_xhtml_file(input_file: str, output_file: str, *, remove_metaguiding: bool = False)`**
214
+
215
+ Metaguides an XHTML/HTML file by applying visual anchoring to text content. Supports `.xhtml`, `.html`, and `.htm` files.
216
+
217
+ ```python
218
+ from intellireading.client import metaguide_xhtml_file
219
+
220
+ # Metaguide an HTML file
221
+ metaguide_xhtml_file("article.html", "article_metaguided.html")
222
+
223
+ # Remove metaguiding
224
+ metaguide_xhtml_file(
225
+ "article_metaguided.html",
226
+ "article_restored.html",
227
+ remove_metaguiding=True
228
+ )
229
+ ```
230
+
231
+ **`metaguide_xhtml_stream(input_file_stream: BytesIO, *, remove_metaguiding: bool = False) -> BytesIO`**
232
+
233
+ Metaguides an XHTML/HTML file from a byte stream.
234
+
235
+ ```python
236
+ from io import BytesIO
237
+ from intellireading.client import metaguide_xhtml_stream
238
+
239
+ # Process HTML content from string
240
+ html_content = """
241
+ <!DOCTYPE html>
242
+ <html>
243
+ <body>
244
+ <p>This is a sample paragraph that will be metaguided.</p>
245
+ </body>
246
+ </html>
247
+ """
248
+
249
+ input_stream = BytesIO(html_content.encode('utf-8'))
250
+ output_stream = metaguide_xhtml_stream(input_stream)
251
+ metaguided_content = output_stream.read().decode('utf-8')
252
+ ```
253
+
254
+ #### Directory Functions
255
+
256
+ **`metaguide_dir(input_dir: str, output_dir: str, *, remove_metaguiding: bool = False)`**
257
+
258
+ Metaguides all EPUB and XHTML/HTML files found in a directory recursively.
259
+
260
+ ```python
261
+ from intellireading.client import metaguide_dir
262
+
263
+ # Metaguide all books in the directory
264
+ metaguide_dir("books", "books_metaguided")
265
+
266
+ # Remove metaguiding from all files
267
+ metaguide_dir("books_metaguided", "books_restored", remove_metaguiding=True)
268
+ ```
269
+
270
+ #### Utility Functions
271
+
272
+ **`is_file_metaguided(filepath: str) -> bool`**
273
+
274
+ Checks if an EPUB file has already been metaguided.
275
+
276
+ ```python
277
+ from intellireading.client import is_file_metaguided, metaguide_epub_file
278
+
279
+ # Check if file is already metaguided
280
+ if not is_file_metaguided("mybook.epub"):
281
+ metaguide_epub_file("mybook.epub", "mybook_metaguided.epub")
282
+ print("File metaguided successfully")
283
+ else:
284
+ print("File is already metaguided")
285
+ ```
286
+
287
+ ### Integration Examples
288
+
289
+ #### Web Application (Flask)
290
+
291
+ ```python
292
+ from flask import Flask, request, send_file
293
+ from io import BytesIO
294
+ from intellireading.client import metaguide_epub_stream
295
+
296
+ app = Flask(__name__)
297
+
298
+ @app.route('/metaguide', methods=['POST'])
299
+ def metaguide_upload():
300
+ file = request.files['epub']
301
+ if file and file.filename.endswith('.epub'):
302
+ input_stream = BytesIO(file.read())
303
+ output_stream = metaguide_epub_stream(input_stream)
304
+
305
+ return send_file(
306
+ output_stream,
307
+ as_attachment=True,
308
+ download_name=f"metaguided_{file.filename}",
309
+ mimetype='application/epub+zip'
310
+ )
311
+ return "Invalid file", 400
312
+ ```
313
+
314
+ #### Batch Processing
315
+
316
+ ```python
317
+ import os
318
+ from intellireading.client import metaguide_dir, is_file_metaguided
319
+
320
+ def batch_process_library(library_path):
321
+ """Process an entire library of EPUB files"""
322
+ processed_path = os.path.join(library_path, "metaguided")
323
+
324
+ # Process all files
325
+ metaguide_dir(library_path, processed_path)
326
+
327
+ # Verify results
328
+ for root, dirs, files in os.walk(processed_path):
329
+ for file in files:
330
+ if file.endswith('.epub'):
331
+ filepath = os.path.join(root, file)
332
+ if is_file_metaguided(filepath):
333
+ print(f"✓ Successfully metaguided: {file}")
334
+
335
+ batch_process_library("/path/to/my/books")
336
+ ```
337
+
338
+ ### Error Handling
339
+
340
+ ```python
341
+ from intellireading.client import metaguide_epub_file
342
+
343
+ try:
344
+ metaguide_epub_file("mybook.epub", "output.epub")
345
+ except ValueError as e:
346
+ print(f"Invalid file: {e}")
347
+ except FileNotFoundError as e:
348
+ print(f"File not found: {e}")
349
+ except Exception as e:
350
+ print(f"Unexpected error: {e}")
351
+ ```
@@ -0,0 +1 @@
1
+ __version__ = "2.1.1"
@@ -12,7 +12,6 @@ import regex as re
12
12
  # it still works
13
13
  from .__about_cli__ import __version__ as cli_version # noqa: TID252
14
14
 
15
-
16
15
  _logger = logging.getLogger(__name__)
17
16
  _METAGUIDED_FLAG_FILENAME = "intellireading.metaguide"
18
17
  _EPUB_EXTENSIONS = [".EPUB", ".KEPUB"]
@@ -143,10 +142,13 @@ class RegExBoldMetaguider:
143
142
  def _get_encoding_using_lxml(self, xhtml_document: bytes) -> str | None:
144
143
  from lxml import etree
145
144
 
146
- parser = etree.XMLParser(resolve_entities=False)
147
- doc = etree.fromstring(xhtml_document, parser=parser).getroottree()
148
- docinfo = doc.docinfo
149
- return docinfo.encoding
145
+ try:
146
+ parser = etree.XMLParser(resolve_entities=False)
147
+ doc = etree.fromstring(xhtml_document, parser=parser).getroottree()
148
+ docinfo = doc.docinfo
149
+ return docinfo.encoding
150
+ except etree.XMLSyntaxError:
151
+ return None
150
152
 
151
153
  def _get_encoding_using_bom(self, xhtml_document: bytes) -> str | None:
152
154
  if xhtml_document.startswith(b"\xef\xbb\xbf"):
@@ -11,7 +11,7 @@ requires-python = ">=3.13"
11
11
  license = "GPL-3.0"
12
12
  keywords = ["kepub","epub", "calibre", "ebook","kindle","kobo","speed-reading", "dyslexia", "adhd"]
13
13
  authors = [
14
- { name = "Hugo Batista"},
14
+ { name = "Hugo Batista <intellireading at hugobatista.com>"},
15
15
  ]
16
16
  classifiers = [
17
17
  "Operating System :: OS Independent",
@@ -45,6 +45,9 @@ intellireading = "intellireading.client:entrypoint"
45
45
  Documentation = "https://go.hugobatista.com/gh/intellireading-cli#readme"
46
46
  Issues = "https://go.hugobatista.com/gh/intellireading-cli/issues"
47
47
  Source = "https://go.hugobatista.com/gh/intellireading-cli"
48
+ Homepage = "https://go.hugobatista.com/gh/intellireading-cli"
49
+ Repository = "https://go.hugobatista.com/gh/intellireading-cli.git"
50
+
48
51
 
49
52
  [tool.hatch.version]
50
53
  path = "src/intellireading/client/__about_cli__.py"
@@ -1 +0,0 @@
1
- __version__ = "2.1.0"