pdf2epub 0.1.2 → 0.1.3

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,118 +0,0 @@
1
- #!/usr/bin/env python3
2
- import argparse
3
- import sys
4
- from pathlib import Path
5
- import modules.pdf2md as pdf2md
6
- import modules.mark2epub as mark2epub
7
- import torch
8
-
9
-
10
-
11
- def main():
12
- if torch.cuda.is_available():
13
- print("CUDA is available. Using GPU for processing.")
14
- elif torch.backends.mps.is_available():
15
- print("MPS is available. Using Apple Silicon for processing.")
16
- else:
17
- print("CUDA is not available. Using CPU for processing.")
18
-
19
- parser = argparse.ArgumentParser(
20
- description='Convert PDF files to EPUB format via Markdown'
21
- )
22
- parser.add_argument(
23
- 'input_path',
24
- nargs='?',
25
- type=str,
26
- help='Path to input PDF file or directory (default: ./input/*.pdf)'
27
- )
28
- parser.add_argument(
29
- 'output_path',
30
- nargs='?',
31
- type=str,
32
- help='Path to output directory (default: directory named after PDF)'
33
- )
34
- parser.add_argument(
35
- '--max-pages',
36
- type=int,
37
- default=None,
38
- help='Maximum number of pages to process'
39
- )
40
- parser.add_argument(
41
- '--start-page',
42
- type=int,
43
- default=None,
44
- help='Page number to start from'
45
- )
46
- parser.add_argument(
47
- '--skip-epub',
48
- action='store_true',
49
- help='Skip EPUB generation, only create markdown'
50
- )
51
- parser.add_argument(
52
- '--skip-md',
53
- action='store_true',
54
- help='Skip markdown generation, use existing markdown files'
55
- )
56
-
57
- args = parser.parse_args()
58
-
59
- # Get input path
60
- input_path = Path(args.input_path) if args.input_path else pdf2md.get_default_input_dir()
61
-
62
- # Get queue of PDFs to process
63
- queue = pdf2md.add_pdfs_to_queue(input_path)
64
- print(f"Found {len(queue)} PDF files to process")
65
-
66
- # Process each PDF
67
- failed = []
68
- for pdf_path in queue:
69
- print(f"\nProcessing: {pdf_path.name}")
70
-
71
- # Get output directory for this PDF
72
- if args.output_path:
73
- output_path = Path(args.output_path)
74
- markdown_dir = output_path / pdf_path.stem
75
- else:
76
- markdown_dir = pdf2md.get_default_output_dir(pdf_path)
77
- output_path = markdown_dir.parent
78
-
79
- try:
80
- # Check if markdown directory exists when skipping MD generation
81
- if args.skip_md:
82
- if not markdown_dir.exists():
83
- print(f"Error: Markdown directory not found: {markdown_dir}", file=sys.stderr)
84
- failed.append(pdf_path.name)
85
- continue
86
- print(f"Using existing markdown files from: {markdown_dir}")
87
-
88
- # Convert PDF to Markdown unless skipped
89
- if not args.skip_md:
90
- print("Converting PDF to Markdown...")
91
- pdf2md.convert_pdf(
92
- str(pdf_path),
93
- markdown_dir,
94
- args.max_pages,
95
- args.start_page,
96
- )
97
-
98
- # Convert Markdown to EPUB unless skipped
99
- if not args.skip_epub:
100
- print("Converting Markdown to EPUB...")
101
- mark2epub.convert_to_epub(markdown_dir, output_path)
102
-
103
- except Exception as e:
104
- print(f"Error processing {pdf_path.name}: {str(e)}", file=sys.stderr)
105
- failed.append(pdf_path.name)
106
- continue
107
-
108
- if failed:
109
- print(
110
- f"\nFailed to process {len(failed)} of {len(queue)} PDF file(s):",
111
- file=sys.stderr,
112
- )
113
- for name in failed:
114
- print(f" - {name}", file=sys.stderr)
115
- sys.exit(1)
116
-
117
- if __name__ == '__main__':
118
- main()
File without changes