openconvert 0.1.0__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.
- openconvert-0.1.0/PKG-INFO +232 -0
- openconvert-0.1.0/README.md +171 -0
- openconvert-0.1.0/setup.cfg +4 -0
- openconvert-0.1.0/setup.py +77 -0
- openconvert-0.1.0/src/openconvert/__init__.py +7 -0
- openconvert-0.1.0/src/openconvert/cli.py +145 -0
- openconvert-0.1.0/src/openconvert/converter.py +152 -0
- openconvert-0.1.0/src/openconvert/converters/__init__.py +3 -0
- openconvert-0.1.0/src/openconvert/converters/archive_converter.py +277 -0
- openconvert-0.1.0/src/openconvert/converters/audio_converter.py +223 -0
- openconvert-0.1.0/src/openconvert/converters/code_converter.py +412 -0
- openconvert-0.1.0/src/openconvert/converters/document_converter.py +596 -0
- openconvert-0.1.0/src/openconvert/converters/image_converter.py +214 -0
- openconvert-0.1.0/src/openconvert/converters/model_converter.py +208 -0
- openconvert-0.1.0/src/openconvert/converters/video_converter.py +259 -0
- openconvert-0.1.0/src/openconvert/launcher.py +0 -0
- openconvert-0.1.0/src/openconvert.egg-info/PKG-INFO +232 -0
- openconvert-0.1.0/src/openconvert.egg-info/SOURCES.txt +30 -0
- openconvert-0.1.0/src/openconvert.egg-info/dependency_links.txt +1 -0
- openconvert-0.1.0/src/openconvert.egg-info/entry_points.txt +2 -0
- openconvert-0.1.0/src/openconvert.egg-info/requires.txt +45 -0
- openconvert-0.1.0/src/openconvert.egg-info/top_level.txt +1 -0
- openconvert-0.1.0/tests/test_archive_converter.py +253 -0
- openconvert-0.1.0/tests/test_audio_converter.py +230 -0
- openconvert-0.1.0/tests/test_base.py +227 -0
- openconvert-0.1.0/tests/test_cli.py +216 -0
- openconvert-0.1.0/tests/test_code_converter.py +453 -0
- openconvert-0.1.0/tests/test_converter.py +142 -0
- openconvert-0.1.0/tests/test_document_converter.py +317 -0
- openconvert-0.1.0/tests/test_image_converter.py +240 -0
- openconvert-0.1.0/tests/test_model_converter.py +246 -0
- openconvert-0.1.0/tests/test_video_converter.py +227 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: openconvert
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: A versatile file and data conversion library
|
5
|
+
Home-page: https://github.com/openconvert/openconvert
|
6
|
+
Author: OpenConvert Team
|
7
|
+
Author-email: info@openconvert.org
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.7
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
Requires-Dist: pillow
|
14
|
+
Requires-Dist: reportlab
|
15
|
+
Requires-Dist: python-docx
|
16
|
+
Requires-Dist: PyPDF2
|
17
|
+
Requires-Dist: pandas
|
18
|
+
Requires-Dist: pyyaml
|
19
|
+
Requires-Dist: dicttoxml
|
20
|
+
Requires-Dist: xmltodict
|
21
|
+
Requires-Dist: markdown
|
22
|
+
Requires-Dist: beautifulsoup4
|
23
|
+
Requires-Dist: html2text
|
24
|
+
Provides-Extra: image
|
25
|
+
Requires-Dist: cairosvg; extra == "image"
|
26
|
+
Provides-Extra: audio
|
27
|
+
Requires-Dist: pydub; extra == "audio"
|
28
|
+
Requires-Dist: SpeechRecognition; extra == "audio"
|
29
|
+
Provides-Extra: video
|
30
|
+
Requires-Dist: moviepy; extra == "video"
|
31
|
+
Provides-Extra: document
|
32
|
+
Requires-Dist: pdf2image; extra == "document"
|
33
|
+
Provides-Extra: archive
|
34
|
+
Requires-Dist: py7zr; extra == "archive"
|
35
|
+
Requires-Dist: rarfile; extra == "archive"
|
36
|
+
Provides-Extra: model
|
37
|
+
Requires-Dist: trimesh; extra == "model"
|
38
|
+
Requires-Dist: numpy; extra == "model"
|
39
|
+
Requires-Dist: scipy; extra == "model"
|
40
|
+
Provides-Extra: all
|
41
|
+
Requires-Dist: cairosvg; extra == "all"
|
42
|
+
Requires-Dist: pydub; extra == "all"
|
43
|
+
Requires-Dist: SpeechRecognition; extra == "all"
|
44
|
+
Requires-Dist: moviepy; extra == "all"
|
45
|
+
Requires-Dist: pdf2image; extra == "all"
|
46
|
+
Requires-Dist: py7zr; extra == "all"
|
47
|
+
Requires-Dist: rarfile; extra == "all"
|
48
|
+
Requires-Dist: trimesh; extra == "all"
|
49
|
+
Requires-Dist: numpy; extra == "all"
|
50
|
+
Requires-Dist: scipy; extra == "all"
|
51
|
+
Dynamic: author
|
52
|
+
Dynamic: author-email
|
53
|
+
Dynamic: classifier
|
54
|
+
Dynamic: description
|
55
|
+
Dynamic: description-content-type
|
56
|
+
Dynamic: home-page
|
57
|
+
Dynamic: provides-extra
|
58
|
+
Dynamic: requires-dist
|
59
|
+
Dynamic: requires-python
|
60
|
+
Dynamic: summary
|
61
|
+
|
62
|
+
# AGConvert
|
63
|
+
|
64
|
+
AGConvert is a versatile file conversion library that supports a wide range of file formats across different categories including images, documents, audio, video, 3D models, code, and archives.
|
65
|
+
|
66
|
+
## Features
|
67
|
+
|
68
|
+
- **Image Conversion**: Convert between PNG, JPG, BMP, GIF, TIFF, WebP, SVG, and PDF
|
69
|
+
- **Document Conversion**: Convert between TXT, PDF, DOCX, HTML, MD, RTF, CSV, XLSX, JSON, XML, and YAML
|
70
|
+
- **Audio Conversion**: Convert between MP3, WAV, OGG, FLAC, AAC, and M4A
|
71
|
+
- **Video Conversion**: Convert between MP4, AVI, MKV, MOV, WMV, and WebM
|
72
|
+
- **3D Model Conversion**: Convert between OBJ, STL, PLY, and GLTF
|
73
|
+
- **Code Conversion**: Convert between JSON, XML, YAML, and CSV
|
74
|
+
- **Archive Conversion**: Convert between ZIP, TAR, GZ, BZ2, and 7Z
|
75
|
+
|
76
|
+
## Installation
|
77
|
+
|
78
|
+
### Quick Installation
|
79
|
+
|
80
|
+
To install all dependencies:
|
81
|
+
|
82
|
+
```bash
|
83
|
+
./scripts/install.sh
|
84
|
+
```
|
85
|
+
|
86
|
+
### Specific Installation
|
87
|
+
|
88
|
+
To install dependencies for specific conversion types:
|
89
|
+
|
90
|
+
```bash
|
91
|
+
./scripts/install_specific.sh --image --document
|
92
|
+
```
|
93
|
+
|
94
|
+
Available options:
|
95
|
+
- `--all`: Install all dependencies
|
96
|
+
- `--core`: Install core dependencies
|
97
|
+
- `--image`: Install image conversion dependencies
|
98
|
+
- `--document`: Install document conversion dependencies
|
99
|
+
- `--audio`: Install audio conversion dependencies
|
100
|
+
- `--video`: Install video conversion dependencies
|
101
|
+
- `--model`: Install 3D model conversion dependencies
|
102
|
+
- `--archive`: Install archive conversion dependencies
|
103
|
+
|
104
|
+
## Usage
|
105
|
+
|
106
|
+
### Python API
|
107
|
+
|
108
|
+
```python
|
109
|
+
from agconvert import open_convert
|
110
|
+
|
111
|
+
# Basic conversion
|
112
|
+
open_convert('input.png', 'output.jpg')
|
113
|
+
|
114
|
+
# Conversion with options
|
115
|
+
open_convert('input.png', 'output.jpg', quality=85, resize=(800, 600))
|
116
|
+
```
|
117
|
+
|
118
|
+
### Command Line Interface
|
119
|
+
|
120
|
+
```bash
|
121
|
+
# Basic conversion
|
122
|
+
agconvert input.png output.jpg
|
123
|
+
|
124
|
+
# Conversion with options
|
125
|
+
agconvert input.png output.jpg --quality 85 --resize 800x600
|
126
|
+
```
|
127
|
+
|
128
|
+
## Supported Conversion Options
|
129
|
+
|
130
|
+
### Image Options
|
131
|
+
- `quality`: Set the quality for lossy formats (1-100)
|
132
|
+
- `resize`: Resize the image (width, height)
|
133
|
+
- `grayscale`: Convert to grayscale
|
134
|
+
- `rotate`: Rotate the image by degrees
|
135
|
+
|
136
|
+
### Document Options
|
137
|
+
- `template`: Specify a template for document conversion
|
138
|
+
- `metadata`: Add metadata to the document
|
139
|
+
- `toc`: Include table of contents
|
140
|
+
|
141
|
+
### Audio Options
|
142
|
+
- `bitrate`: Set the bitrate for audio conversion
|
143
|
+
- `sample_rate`: Set the sample rate
|
144
|
+
- `channels`: Set the number of channels
|
145
|
+
|
146
|
+
### Video Options
|
147
|
+
- `resolution`: Set the video resolution
|
148
|
+
- `fps`: Set the frames per second
|
149
|
+
- `codec`: Specify the codec to use
|
150
|
+
|
151
|
+
## Examples
|
152
|
+
|
153
|
+
### Converting an Image
|
154
|
+
|
155
|
+
```python
|
156
|
+
from agconvert import open_convert
|
157
|
+
|
158
|
+
# Convert PNG to JPG
|
159
|
+
open_convert('image.png', 'image.jpg')
|
160
|
+
|
161
|
+
# Convert PNG to JPG with options
|
162
|
+
open_convert('image.png', 'image.jpg', quality=85, resize=(800, 600))
|
163
|
+
```
|
164
|
+
|
165
|
+
### Converting a Document
|
166
|
+
|
167
|
+
```python
|
168
|
+
from agconvert import open_convert
|
169
|
+
|
170
|
+
# Convert Markdown to HTML
|
171
|
+
open_convert('document.md', 'document.html')
|
172
|
+
|
173
|
+
# Convert CSV to Excel
|
174
|
+
open_convert('data.csv', 'data.xlsx')
|
175
|
+
```
|
176
|
+
|
177
|
+
### Converting Audio
|
178
|
+
|
179
|
+
```python
|
180
|
+
from agconvert import open_convert
|
181
|
+
|
182
|
+
# Convert WAV to MP3
|
183
|
+
open_convert('audio.wav', 'audio.mp3')
|
184
|
+
|
185
|
+
# Convert WAV to MP3 with options
|
186
|
+
open_convert('audio.wav', 'audio.mp3', bitrate='320k')
|
187
|
+
```
|
188
|
+
|
189
|
+
## Running Tests
|
190
|
+
|
191
|
+
To run all tests:
|
192
|
+
|
193
|
+
```bash
|
194
|
+
python run_tests.py
|
195
|
+
```
|
196
|
+
|
197
|
+
To run specific test categories:
|
198
|
+
|
199
|
+
```bash
|
200
|
+
python run_tests.py -k image
|
201
|
+
python run_tests.py -k document
|
202
|
+
```
|
203
|
+
|
204
|
+
## Dependencies
|
205
|
+
|
206
|
+
AGConvert relies on several libraries for different conversion types:
|
207
|
+
|
208
|
+
- **Image**: Pillow, CairoSVG
|
209
|
+
- **Document**: Pandas, OpenPyXL, python-docx, pdfkit, markdown
|
210
|
+
- **Audio**: PyDub, SpeechRecognition
|
211
|
+
- **Video**: MoviePy
|
212
|
+
- **3D Model**: Trimesh, NumPy
|
213
|
+
- **Archive**: py7zr, patool
|
214
|
+
|
215
|
+
System dependencies:
|
216
|
+
- FFmpeg (for audio and video)
|
217
|
+
- Pandoc (for document conversion)
|
218
|
+
- Cairo (for SVG conversion)
|
219
|
+
|
220
|
+
## License
|
221
|
+
|
222
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
223
|
+
|
224
|
+
## Contributing
|
225
|
+
|
226
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
227
|
+
|
228
|
+
1. Fork the repository
|
229
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
230
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
231
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
232
|
+
5. Open a Pull Request
|
@@ -0,0 +1,171 @@
|
|
1
|
+
# AGConvert
|
2
|
+
|
3
|
+
AGConvert is a versatile file conversion library that supports a wide range of file formats across different categories including images, documents, audio, video, 3D models, code, and archives.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **Image Conversion**: Convert between PNG, JPG, BMP, GIF, TIFF, WebP, SVG, and PDF
|
8
|
+
- **Document Conversion**: Convert between TXT, PDF, DOCX, HTML, MD, RTF, CSV, XLSX, JSON, XML, and YAML
|
9
|
+
- **Audio Conversion**: Convert between MP3, WAV, OGG, FLAC, AAC, and M4A
|
10
|
+
- **Video Conversion**: Convert between MP4, AVI, MKV, MOV, WMV, and WebM
|
11
|
+
- **3D Model Conversion**: Convert between OBJ, STL, PLY, and GLTF
|
12
|
+
- **Code Conversion**: Convert between JSON, XML, YAML, and CSV
|
13
|
+
- **Archive Conversion**: Convert between ZIP, TAR, GZ, BZ2, and 7Z
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
### Quick Installation
|
18
|
+
|
19
|
+
To install all dependencies:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
./scripts/install.sh
|
23
|
+
```
|
24
|
+
|
25
|
+
### Specific Installation
|
26
|
+
|
27
|
+
To install dependencies for specific conversion types:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
./scripts/install_specific.sh --image --document
|
31
|
+
```
|
32
|
+
|
33
|
+
Available options:
|
34
|
+
- `--all`: Install all dependencies
|
35
|
+
- `--core`: Install core dependencies
|
36
|
+
- `--image`: Install image conversion dependencies
|
37
|
+
- `--document`: Install document conversion dependencies
|
38
|
+
- `--audio`: Install audio conversion dependencies
|
39
|
+
- `--video`: Install video conversion dependencies
|
40
|
+
- `--model`: Install 3D model conversion dependencies
|
41
|
+
- `--archive`: Install archive conversion dependencies
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
### Python API
|
46
|
+
|
47
|
+
```python
|
48
|
+
from agconvert import open_convert
|
49
|
+
|
50
|
+
# Basic conversion
|
51
|
+
open_convert('input.png', 'output.jpg')
|
52
|
+
|
53
|
+
# Conversion with options
|
54
|
+
open_convert('input.png', 'output.jpg', quality=85, resize=(800, 600))
|
55
|
+
```
|
56
|
+
|
57
|
+
### Command Line Interface
|
58
|
+
|
59
|
+
```bash
|
60
|
+
# Basic conversion
|
61
|
+
agconvert input.png output.jpg
|
62
|
+
|
63
|
+
# Conversion with options
|
64
|
+
agconvert input.png output.jpg --quality 85 --resize 800x600
|
65
|
+
```
|
66
|
+
|
67
|
+
## Supported Conversion Options
|
68
|
+
|
69
|
+
### Image Options
|
70
|
+
- `quality`: Set the quality for lossy formats (1-100)
|
71
|
+
- `resize`: Resize the image (width, height)
|
72
|
+
- `grayscale`: Convert to grayscale
|
73
|
+
- `rotate`: Rotate the image by degrees
|
74
|
+
|
75
|
+
### Document Options
|
76
|
+
- `template`: Specify a template for document conversion
|
77
|
+
- `metadata`: Add metadata to the document
|
78
|
+
- `toc`: Include table of contents
|
79
|
+
|
80
|
+
### Audio Options
|
81
|
+
- `bitrate`: Set the bitrate for audio conversion
|
82
|
+
- `sample_rate`: Set the sample rate
|
83
|
+
- `channels`: Set the number of channels
|
84
|
+
|
85
|
+
### Video Options
|
86
|
+
- `resolution`: Set the video resolution
|
87
|
+
- `fps`: Set the frames per second
|
88
|
+
- `codec`: Specify the codec to use
|
89
|
+
|
90
|
+
## Examples
|
91
|
+
|
92
|
+
### Converting an Image
|
93
|
+
|
94
|
+
```python
|
95
|
+
from agconvert import open_convert
|
96
|
+
|
97
|
+
# Convert PNG to JPG
|
98
|
+
open_convert('image.png', 'image.jpg')
|
99
|
+
|
100
|
+
# Convert PNG to JPG with options
|
101
|
+
open_convert('image.png', 'image.jpg', quality=85, resize=(800, 600))
|
102
|
+
```
|
103
|
+
|
104
|
+
### Converting a Document
|
105
|
+
|
106
|
+
```python
|
107
|
+
from agconvert import open_convert
|
108
|
+
|
109
|
+
# Convert Markdown to HTML
|
110
|
+
open_convert('document.md', 'document.html')
|
111
|
+
|
112
|
+
# Convert CSV to Excel
|
113
|
+
open_convert('data.csv', 'data.xlsx')
|
114
|
+
```
|
115
|
+
|
116
|
+
### Converting Audio
|
117
|
+
|
118
|
+
```python
|
119
|
+
from agconvert import open_convert
|
120
|
+
|
121
|
+
# Convert WAV to MP3
|
122
|
+
open_convert('audio.wav', 'audio.mp3')
|
123
|
+
|
124
|
+
# Convert WAV to MP3 with options
|
125
|
+
open_convert('audio.wav', 'audio.mp3', bitrate='320k')
|
126
|
+
```
|
127
|
+
|
128
|
+
## Running Tests
|
129
|
+
|
130
|
+
To run all tests:
|
131
|
+
|
132
|
+
```bash
|
133
|
+
python run_tests.py
|
134
|
+
```
|
135
|
+
|
136
|
+
To run specific test categories:
|
137
|
+
|
138
|
+
```bash
|
139
|
+
python run_tests.py -k image
|
140
|
+
python run_tests.py -k document
|
141
|
+
```
|
142
|
+
|
143
|
+
## Dependencies
|
144
|
+
|
145
|
+
AGConvert relies on several libraries for different conversion types:
|
146
|
+
|
147
|
+
- **Image**: Pillow, CairoSVG
|
148
|
+
- **Document**: Pandas, OpenPyXL, python-docx, pdfkit, markdown
|
149
|
+
- **Audio**: PyDub, SpeechRecognition
|
150
|
+
- **Video**: MoviePy
|
151
|
+
- **3D Model**: Trimesh, NumPy
|
152
|
+
- **Archive**: py7zr, patool
|
153
|
+
|
154
|
+
System dependencies:
|
155
|
+
- FFmpeg (for audio and video)
|
156
|
+
- Pandoc (for document conversion)
|
157
|
+
- Cairo (for SVG conversion)
|
158
|
+
|
159
|
+
## License
|
160
|
+
|
161
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
162
|
+
|
163
|
+
## Contributing
|
164
|
+
|
165
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
166
|
+
|
167
|
+
1. Fork the repository
|
168
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
169
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
170
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
171
|
+
5. Open a Pull Request
|
@@ -0,0 +1,77 @@
|
|
1
|
+
from setuptools import setup, find_packages
|
2
|
+
|
3
|
+
with open("README.md", "r", encoding="utf-8") as fh:
|
4
|
+
long_description = fh.read()
|
5
|
+
|
6
|
+
setup(
|
7
|
+
name="openconvert",
|
8
|
+
version="0.1.0",
|
9
|
+
author="OpenConvert Team",
|
10
|
+
author_email="info@openconvert.org",
|
11
|
+
description="A versatile file and data conversion library",
|
12
|
+
long_description=long_description,
|
13
|
+
long_description_content_type="text/markdown",
|
14
|
+
url="https://github.com/openconvert/openconvert",
|
15
|
+
package_dir={"": "src"},
|
16
|
+
packages=find_packages(where="src"),
|
17
|
+
classifiers=[
|
18
|
+
"Programming Language :: Python :: 3",
|
19
|
+
"License :: OSI Approved :: MIT License",
|
20
|
+
"Operating System :: OS Independent",
|
21
|
+
],
|
22
|
+
python_requires=">=3.7",
|
23
|
+
install_requires=[
|
24
|
+
"pillow", # For image conversions
|
25
|
+
"reportlab", # For PDF creation
|
26
|
+
"python-docx", # For DOCX handling
|
27
|
+
"PyPDF2", # For PDF handling
|
28
|
+
"pandas", # For data conversions
|
29
|
+
"pyyaml", # For YAML handling
|
30
|
+
"dicttoxml", # For XML conversions
|
31
|
+
"xmltodict", # For XML parsing
|
32
|
+
"markdown", # For Markdown handling
|
33
|
+
"beautifulsoup4", # For HTML parsing
|
34
|
+
"html2text", # For HTML to Markdown conversion
|
35
|
+
],
|
36
|
+
extras_require={
|
37
|
+
"image": [
|
38
|
+
"cairosvg", # For SVG conversions
|
39
|
+
],
|
40
|
+
"audio": [
|
41
|
+
"pydub", # For audio conversions
|
42
|
+
"SpeechRecognition", # For speech-to-text
|
43
|
+
],
|
44
|
+
"video": [
|
45
|
+
"moviepy", # For video processing
|
46
|
+
],
|
47
|
+
"document": [
|
48
|
+
"pdf2image", # For PDF to image conversion
|
49
|
+
],
|
50
|
+
"archive": [
|
51
|
+
"py7zr", # For 7z handling
|
52
|
+
"rarfile", # For RAR handling
|
53
|
+
],
|
54
|
+
"model": [
|
55
|
+
"trimesh", # For 3D model handling
|
56
|
+
"numpy", # Required by trimesh
|
57
|
+
"scipy", # Required for 3D transformations
|
58
|
+
],
|
59
|
+
"all": [
|
60
|
+
"cairosvg",
|
61
|
+
"pydub",
|
62
|
+
"SpeechRecognition",
|
63
|
+
"moviepy",
|
64
|
+
"pdf2image",
|
65
|
+
"py7zr",
|
66
|
+
"rarfile",
|
67
|
+
"trimesh",
|
68
|
+
"numpy",
|
69
|
+
"scipy",
|
70
|
+
],
|
71
|
+
},
|
72
|
+
entry_points={
|
73
|
+
"console_scripts": [
|
74
|
+
"openconvert=openconvert.cli:main",
|
75
|
+
],
|
76
|
+
},
|
77
|
+
)
|
@@ -0,0 +1,145 @@
|
|
1
|
+
"""
|
2
|
+
Command-line interface for AGConvert.
|
3
|
+
"""
|
4
|
+
|
5
|
+
import argparse
|
6
|
+
import json
|
7
|
+
import logging
|
8
|
+
import os
|
9
|
+
import sys
|
10
|
+
from pathlib import Path
|
11
|
+
from typing import Dict, Any, Optional
|
12
|
+
|
13
|
+
from . import __version__
|
14
|
+
from .converter import open_convert
|
15
|
+
|
16
|
+
# Configure logging
|
17
|
+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
18
|
+
logger = logging.getLogger(__name__)
|
19
|
+
|
20
|
+
def parse_args() -> argparse.Namespace:
|
21
|
+
"""Parse command-line arguments."""
|
22
|
+
parser = argparse.ArgumentParser(
|
23
|
+
description="AGConvert - A versatile file and data conversion tool",
|
24
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
25
|
+
epilog="""
|
26
|
+
Examples:
|
27
|
+
agconvert image.png image.jpg # Convert PNG to JPG
|
28
|
+
agconvert document.docx document.pdf # Convert DOCX to PDF
|
29
|
+
agconvert audio.mp3 audio.wav # Convert MP3 to WAV
|
30
|
+
agconvert video.mp4 video.gif # Convert MP4 to GIF
|
31
|
+
agconvert data.json data.yaml # Convert JSON to YAML
|
32
|
+
agconvert --options '{"quality": 90}' image.png image.jpg # With options
|
33
|
+
"""
|
34
|
+
)
|
35
|
+
|
36
|
+
parser.add_argument(
|
37
|
+
"input_file",
|
38
|
+
help="Path to the input file"
|
39
|
+
)
|
40
|
+
|
41
|
+
parser.add_argument(
|
42
|
+
"output_file",
|
43
|
+
help="Path to the output file"
|
44
|
+
)
|
45
|
+
|
46
|
+
parser.add_argument(
|
47
|
+
"--source-format",
|
48
|
+
help="Source file format (if not specified, will be inferred from input file extension)"
|
49
|
+
)
|
50
|
+
|
51
|
+
parser.add_argument(
|
52
|
+
"--target-format",
|
53
|
+
help="Target file format (if not specified, will be inferred from output file extension)"
|
54
|
+
)
|
55
|
+
|
56
|
+
parser.add_argument(
|
57
|
+
"--options",
|
58
|
+
help="Additional conversion options as JSON string",
|
59
|
+
default="{}"
|
60
|
+
)
|
61
|
+
|
62
|
+
parser.add_argument(
|
63
|
+
"--verbose", "-v",
|
64
|
+
action="store_true",
|
65
|
+
help="Enable verbose output"
|
66
|
+
)
|
67
|
+
|
68
|
+
parser.add_argument(
|
69
|
+
"--version",
|
70
|
+
action="version",
|
71
|
+
version=f"AGConvert {__version__}"
|
72
|
+
)
|
73
|
+
|
74
|
+
return parser.parse_args()
|
75
|
+
|
76
|
+
def parse_options(options_str: str) -> Dict[str, Any]:
|
77
|
+
"""Parse options from JSON string."""
|
78
|
+
try:
|
79
|
+
return json.loads(options_str)
|
80
|
+
except json.JSONDecodeError as e:
|
81
|
+
logger.error(f"Error parsing options: {str(e)}")
|
82
|
+
logger.error("Options must be a valid JSON string")
|
83
|
+
sys.exit(1)
|
84
|
+
|
85
|
+
def infer_format(filepath: str) -> str:
|
86
|
+
"""Infer file format from file extension."""
|
87
|
+
ext = os.path.splitext(filepath)[1].lower().lstrip('.')
|
88
|
+
|
89
|
+
# Handle special cases
|
90
|
+
if ext == 'jpeg':
|
91
|
+
return 'jpg'
|
92
|
+
elif ext == 'tif':
|
93
|
+
return 'tiff'
|
94
|
+
elif ext == 'yml':
|
95
|
+
return 'yaml'
|
96
|
+
elif ext == 'htm':
|
97
|
+
return 'html'
|
98
|
+
elif ext == 'markdown':
|
99
|
+
return 'md'
|
100
|
+
elif ext == 'tex':
|
101
|
+
return 'latex'
|
102
|
+
|
103
|
+
return ext
|
104
|
+
|
105
|
+
def main() -> None:
|
106
|
+
"""Main entry point for the CLI."""
|
107
|
+
args = parse_args()
|
108
|
+
|
109
|
+
# Set logging level
|
110
|
+
if args.verbose:
|
111
|
+
logging.getLogger().setLevel(logging.DEBUG)
|
112
|
+
|
113
|
+
# Parse options
|
114
|
+
options = parse_options(args.options)
|
115
|
+
|
116
|
+
# Infer formats if not specified
|
117
|
+
source_format = args.source_format or infer_format(args.input_file)
|
118
|
+
target_format = args.target_format or infer_format(args.output_file)
|
119
|
+
|
120
|
+
if not source_format:
|
121
|
+
logger.error("Could not determine source format. Please specify --source-format")
|
122
|
+
sys.exit(1)
|
123
|
+
|
124
|
+
if not target_format:
|
125
|
+
logger.error("Could not determine target format. Please specify --target-format")
|
126
|
+
sys.exit(1)
|
127
|
+
|
128
|
+
try:
|
129
|
+
# Perform the conversion
|
130
|
+
output_path = open_convert(
|
131
|
+
filepath=args.input_file,
|
132
|
+
source_format=source_format,
|
133
|
+
target_format=target_format,
|
134
|
+
output_path=args.output_file,
|
135
|
+
options=options
|
136
|
+
)
|
137
|
+
|
138
|
+
logger.info(f"Conversion successful: {args.input_file} → {output_path}")
|
139
|
+
|
140
|
+
except Exception as e:
|
141
|
+
logger.error(f"Conversion failed: {str(e)}")
|
142
|
+
sys.exit(1)
|
143
|
+
|
144
|
+
if __name__ == "__main__":
|
145
|
+
main()
|