file-converter-tool 1.0.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.
- file_converter_tool-1.0.0/LICENSE +21 -0
- file_converter_tool-1.0.0/MANIFEST.in +3 -0
- file_converter_tool-1.0.0/PKG-INFO +203 -0
- file_converter_tool-1.0.0/README.md +158 -0
- file_converter_tool-1.0.0/requirements.txt +12 -0
- file_converter_tool-1.0.0/setup.cfg +4 -0
- file_converter_tool-1.0.0/setup.py +43 -0
- file_converter_tool-1.0.0/src/file_converter/__init__.py +169 -0
- file_converter_tool-1.0.0/src/file_converter/cli.py +165 -0
- file_converter_tool-1.0.0/src/file_converter/converters/__init__.py +1 -0
- file_converter_tool-1.0.0/src/file_converter/converters/data.py +496 -0
- file_converter_tool-1.0.0/src/file_converter/converters/document.py +146 -0
- file_converter_tool-1.0.0/src/file_converter/converters/image.py +143 -0
- file_converter_tool-1.0.0/src/file_converter/converters/text.py +250 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/PKG-INFO +203 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/SOURCES.txt +20 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/dependency_links.txt +1 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/entry_points.txt +2 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/not-zip-safe +1 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/requires.txt +12 -0
- file_converter_tool-1.0.0/src/file_converter_tool.egg-info/top_level.txt +1 -0
- file_converter_tool-1.0.0/tests/test_converter.py +183 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ab0jwad
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: file-converter-tool
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A powerful, open-source file converter supporting 15+ formats
|
|
5
|
+
Home-page: https://github.com/ab0jwad/file-converter
|
|
6
|
+
Author: Ab0jwad
|
|
7
|
+
Author-email: ab0jwad@dev.com
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Utilities
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: pandas>=2.0.0
|
|
24
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
25
|
+
Requires-Dist: PyPDF2>=3.0.0
|
|
26
|
+
Requires-Dist: python-docx>=0.8.11
|
|
27
|
+
Requires-Dist: PyYAML>=6.0
|
|
28
|
+
Requires-Dist: Pillow>=10.0.0
|
|
29
|
+
Requires-Dist: flask>=2.3.0
|
|
30
|
+
Requires-Dist: click>=8.1.0
|
|
31
|
+
Requires-Dist: markdown>=3.5.0
|
|
32
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
33
|
+
Requires-Dist: pytest>=7.4.0
|
|
34
|
+
Requires-Dist: pytest-cov>=4.1.0
|
|
35
|
+
Dynamic: author
|
|
36
|
+
Dynamic: author-email
|
|
37
|
+
Dynamic: classifier
|
|
38
|
+
Dynamic: description
|
|
39
|
+
Dynamic: description-content-type
|
|
40
|
+
Dynamic: home-page
|
|
41
|
+
Dynamic: license-file
|
|
42
|
+
Dynamic: requires-dist
|
|
43
|
+
Dynamic: requires-python
|
|
44
|
+
Dynamic: summary
|
|
45
|
+
|
|
46
|
+
# 🔄 Multi-Format File Converter
|
|
47
|
+
|
|
48
|
+
<div align="center">
|
|
49
|
+
|
|
50
|
+

|
|
51
|
+

|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
**A powerful, open-source file converter supporting 15+ formats**
|
|
55
|
+
|
|
56
|
+
[Features](#-features) • [Installation](#-installation) • [Usage](#-usage) • [Supported Formats](#-supported-formats) • [Contributing](#-contributing)
|
|
57
|
+
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🌟 Features
|
|
63
|
+
|
|
64
|
+
- **Multi-Format Support**: Convert between 15+ file formats
|
|
65
|
+
- **Batch Processing**: Convert multiple files at once
|
|
66
|
+
- **Preserve Quality**: Maintain original formatting and quality
|
|
67
|
+
- **CLI & GUI**: Command-line and web interface options
|
|
68
|
+
- **Cross-Platform**: Works on Windows, macOS, and Linux
|
|
69
|
+
- **Open Source**: Free and extensible
|
|
70
|
+
|
|
71
|
+
## 📦 Installation
|
|
72
|
+
|
|
73
|
+
### Using pip
|
|
74
|
+
```bash
|
|
75
|
+
pip install file-converter
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### From source
|
|
79
|
+
```bash
|
|
80
|
+
git clone https://github.com/ab0jwad/file-converter.git
|
|
81
|
+
cd file-converter
|
|
82
|
+
pip install -e .
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 🚀 Usage
|
|
86
|
+
|
|
87
|
+
### Command Line Interface
|
|
88
|
+
```bash
|
|
89
|
+
# Convert PDF to Word
|
|
90
|
+
file-converter convert document.pdf --format docx --output converted.docx
|
|
91
|
+
|
|
92
|
+
# Convert CSV to JSON
|
|
93
|
+
file-converter convert data.csv --format json --output data.json
|
|
94
|
+
|
|
95
|
+
# Batch convert all files in a directory
|
|
96
|
+
file-converter batch ./input --output ./output --format json
|
|
97
|
+
|
|
98
|
+
# List supported formats
|
|
99
|
+
file-converter formats
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Python API
|
|
103
|
+
```python
|
|
104
|
+
from file_converter import FileConverter
|
|
105
|
+
|
|
106
|
+
# Simple conversion
|
|
107
|
+
converter = FileConverter()
|
|
108
|
+
converter.convert('document.pdf', 'document.docx')
|
|
109
|
+
|
|
110
|
+
# Batch conversion
|
|
111
|
+
converter.convert_batch(['file1.csv', 'file2.csv'], format='json')
|
|
112
|
+
|
|
113
|
+
# Get supported formats
|
|
114
|
+
formats = converter.get_supported_formats()
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 📋 Supported Formats
|
|
118
|
+
|
|
119
|
+
### 📄 Documents
|
|
120
|
+
| From | To |
|
|
121
|
+
|------|----|
|
|
122
|
+
| PDF | Text (TXT) |
|
|
123
|
+
| Word (DOCX) | Text (TXT) |
|
|
124
|
+
| Text (TXT) | Word (DOCX), Markdown |
|
|
125
|
+
|
|
126
|
+
### 📊 Data
|
|
127
|
+
| From | To |
|
|
128
|
+
|------|----|
|
|
129
|
+
| CSV | JSON, XML, Excel (XLSX), YAML |
|
|
130
|
+
| JSON | CSV, XML, YAML, HTML |
|
|
131
|
+
| XML | JSON, CSV, YAML |
|
|
132
|
+
| Excel (XLSX) | CSV, JSON, XML |
|
|
133
|
+
| YAML | JSON, CSV, XML |
|
|
134
|
+
|
|
135
|
+
### 🖼️ Images
|
|
136
|
+
| From | To |
|
|
137
|
+
|------|----|
|
|
138
|
+
| PNG | JPG, WEBP |
|
|
139
|
+
| JPG | PNG, WEBP |
|
|
140
|
+
| WEBP | PNG, JPG |
|
|
141
|
+
|
|
142
|
+
### 📝 Text & Code
|
|
143
|
+
|
|
144
|
+
| From | To |
|
|
145
|
+
|------|----|
|
|
146
|
+
| Markdown | HTML, Text |
|
|
147
|
+
| HTML | Markdown, Text |
|
|
148
|
+
| Text (TXT) | Markdown, HTML |
|
|
149
|
+
## 🔧 Requirements
|
|
150
|
+
|
|
151
|
+
- Python 3.8 or higher
|
|
152
|
+
- Dependencies listed in `requirements.txt`
|
|
153
|
+
|
|
154
|
+
## 🧪 Testing
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
# Run all tests
|
|
158
|
+
pytest
|
|
159
|
+
|
|
160
|
+
# Run specific test
|
|
161
|
+
pytest tests/test_converter.py -v
|
|
162
|
+
|
|
163
|
+
# Test coverage
|
|
164
|
+
pytest --cov=src tests/
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## 🤝 Contributing
|
|
168
|
+
|
|
169
|
+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
170
|
+
|
|
171
|
+
1. Fork the repository
|
|
172
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
173
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
174
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
175
|
+
5. Open a Pull Request
|
|
176
|
+
|
|
177
|
+
## 📝 License
|
|
178
|
+
|
|
179
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
180
|
+
|
|
181
|
+
## 🙏 Acknowledgments
|
|
182
|
+
|
|
183
|
+
- Open source community
|
|
184
|
+
- Contributors and users
|
|
185
|
+
- File format libraries and tools
|
|
186
|
+
|
|
187
|
+
## 📞 Support
|
|
188
|
+
|
|
189
|
+
- **Issues**: [GitHub Issues](https://github.com/ab0jwad/file-converter/issues)
|
|
190
|
+
- **Discussions**: [GitHub Discussions](https://github.com/ab0jwad/file-converter/discussions)
|
|
191
|
+
- **Email**: support@fileconverter.dev
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
<div align="center">
|
|
196
|
+
|
|
197
|
+
**⭐ Star this project on GitHub to support development!**
|
|
198
|
+
|
|
199
|
+
[](https://github.com/ab0jwad/file-converter)
|
|
200
|
+
|
|
201
|
+
Made with ❤️ by the File Converter Team
|
|
202
|
+
|
|
203
|
+
</div>
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# 🔄 Multi-Format File Converter
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
**A powerful, open-source file converter supporting 15+ formats**
|
|
10
|
+
|
|
11
|
+
[Features](#-features) • [Installation](#-installation) • [Usage](#-usage) • [Supported Formats](#-supported-formats) • [Contributing](#-contributing)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🌟 Features
|
|
18
|
+
|
|
19
|
+
- **Multi-Format Support**: Convert between 15+ file formats
|
|
20
|
+
- **Batch Processing**: Convert multiple files at once
|
|
21
|
+
- **Preserve Quality**: Maintain original formatting and quality
|
|
22
|
+
- **CLI & GUI**: Command-line and web interface options
|
|
23
|
+
- **Cross-Platform**: Works on Windows, macOS, and Linux
|
|
24
|
+
- **Open Source**: Free and extensible
|
|
25
|
+
|
|
26
|
+
## 📦 Installation
|
|
27
|
+
|
|
28
|
+
### Using pip
|
|
29
|
+
```bash
|
|
30
|
+
pip install file-converter
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### From source
|
|
34
|
+
```bash
|
|
35
|
+
git clone https://github.com/ab0jwad/file-converter.git
|
|
36
|
+
cd file-converter
|
|
37
|
+
pip install -e .
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 🚀 Usage
|
|
41
|
+
|
|
42
|
+
### Command Line Interface
|
|
43
|
+
```bash
|
|
44
|
+
# Convert PDF to Word
|
|
45
|
+
file-converter convert document.pdf --format docx --output converted.docx
|
|
46
|
+
|
|
47
|
+
# Convert CSV to JSON
|
|
48
|
+
file-converter convert data.csv --format json --output data.json
|
|
49
|
+
|
|
50
|
+
# Batch convert all files in a directory
|
|
51
|
+
file-converter batch ./input --output ./output --format json
|
|
52
|
+
|
|
53
|
+
# List supported formats
|
|
54
|
+
file-converter formats
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Python API
|
|
58
|
+
```python
|
|
59
|
+
from file_converter import FileConverter
|
|
60
|
+
|
|
61
|
+
# Simple conversion
|
|
62
|
+
converter = FileConverter()
|
|
63
|
+
converter.convert('document.pdf', 'document.docx')
|
|
64
|
+
|
|
65
|
+
# Batch conversion
|
|
66
|
+
converter.convert_batch(['file1.csv', 'file2.csv'], format='json')
|
|
67
|
+
|
|
68
|
+
# Get supported formats
|
|
69
|
+
formats = converter.get_supported_formats()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 📋 Supported Formats
|
|
73
|
+
|
|
74
|
+
### 📄 Documents
|
|
75
|
+
| From | To |
|
|
76
|
+
|------|----|
|
|
77
|
+
| PDF | Text (TXT) |
|
|
78
|
+
| Word (DOCX) | Text (TXT) |
|
|
79
|
+
| Text (TXT) | Word (DOCX), Markdown |
|
|
80
|
+
|
|
81
|
+
### 📊 Data
|
|
82
|
+
| From | To |
|
|
83
|
+
|------|----|
|
|
84
|
+
| CSV | JSON, XML, Excel (XLSX), YAML |
|
|
85
|
+
| JSON | CSV, XML, YAML, HTML |
|
|
86
|
+
| XML | JSON, CSV, YAML |
|
|
87
|
+
| Excel (XLSX) | CSV, JSON, XML |
|
|
88
|
+
| YAML | JSON, CSV, XML |
|
|
89
|
+
|
|
90
|
+
### 🖼️ Images
|
|
91
|
+
| From | To |
|
|
92
|
+
|------|----|
|
|
93
|
+
| PNG | JPG, WEBP |
|
|
94
|
+
| JPG | PNG, WEBP |
|
|
95
|
+
| WEBP | PNG, JPG |
|
|
96
|
+
|
|
97
|
+
### 📝 Text & Code
|
|
98
|
+
|
|
99
|
+
| From | To |
|
|
100
|
+
|------|----|
|
|
101
|
+
| Markdown | HTML, Text |
|
|
102
|
+
| HTML | Markdown, Text |
|
|
103
|
+
| Text (TXT) | Markdown, HTML |
|
|
104
|
+
## 🔧 Requirements
|
|
105
|
+
|
|
106
|
+
- Python 3.8 or higher
|
|
107
|
+
- Dependencies listed in `requirements.txt`
|
|
108
|
+
|
|
109
|
+
## 🧪 Testing
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Run all tests
|
|
113
|
+
pytest
|
|
114
|
+
|
|
115
|
+
# Run specific test
|
|
116
|
+
pytest tests/test_converter.py -v
|
|
117
|
+
|
|
118
|
+
# Test coverage
|
|
119
|
+
pytest --cov=src tests/
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## 🤝 Contributing
|
|
123
|
+
|
|
124
|
+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
125
|
+
|
|
126
|
+
1. Fork the repository
|
|
127
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
128
|
+
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
129
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
130
|
+
5. Open a Pull Request
|
|
131
|
+
|
|
132
|
+
## 📝 License
|
|
133
|
+
|
|
134
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
135
|
+
|
|
136
|
+
## 🙏 Acknowledgments
|
|
137
|
+
|
|
138
|
+
- Open source community
|
|
139
|
+
- Contributors and users
|
|
140
|
+
- File format libraries and tools
|
|
141
|
+
|
|
142
|
+
## 📞 Support
|
|
143
|
+
|
|
144
|
+
- **Issues**: [GitHub Issues](https://github.com/ab0jwad/file-converter/issues)
|
|
145
|
+
- **Discussions**: [GitHub Discussions](https://github.com/ab0jwad/file-converter/discussions)
|
|
146
|
+
- **Email**: support@fileconverter.dev
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
<div align="center">
|
|
151
|
+
|
|
152
|
+
**⭐ Star this project on GitHub to support development!**
|
|
153
|
+
|
|
154
|
+
[](https://github.com/ab0jwad/file-converter)
|
|
155
|
+
|
|
156
|
+
Made with ❤️ by the File Converter Team
|
|
157
|
+
|
|
158
|
+
</div>
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
with open("requirements.txt", "r", encoding="utf-8") as fh:
|
|
7
|
+
requirements = [line.strip() for line in fh if line.strip() and not line.startswith("#")]
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name="file-converter-tool",
|
|
11
|
+
version="1.0.0",
|
|
12
|
+
author="Ab0jwad",
|
|
13
|
+
author_email="ab0jwad@dev.com",
|
|
14
|
+
description="A powerful, open-source file converter supporting 15+ formats",
|
|
15
|
+
long_description=long_description,
|
|
16
|
+
long_description_content_type="text/markdown",
|
|
17
|
+
url="https://github.com/ab0jwad/file-converter",
|
|
18
|
+
packages=find_packages(where="src"),
|
|
19
|
+
package_dir={"": "src"},
|
|
20
|
+
classifiers=[
|
|
21
|
+
"Development Status :: 4 - Beta",
|
|
22
|
+
"Intended Audience :: Developers",
|
|
23
|
+
"Intended Audience :: End Users/Desktop",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.8",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
32
|
+
"Topic :: Utilities",
|
|
33
|
+
],
|
|
34
|
+
python_requires=">=3.8",
|
|
35
|
+
install_requires=requirements,
|
|
36
|
+
entry_points={
|
|
37
|
+
"console_scripts": [
|
|
38
|
+
"file-converter=file_converter.cli:main",
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
include_package_data=True,
|
|
42
|
+
zip_safe=False,
|
|
43
|
+
)
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""
|
|
2
|
+
File Converter - Main Module
|
|
3
|
+
Supports conversion between 15+ file formats
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Dict, List, Optional, Union
|
|
9
|
+
|
|
10
|
+
from .converters.document import DocumentConverter
|
|
11
|
+
from .converters.data import DataConverter
|
|
12
|
+
from .converters.image import ImageConverter
|
|
13
|
+
from .converters.text import TextConverter
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class FileConverter:
|
|
17
|
+
"""Main file converter class supporting multiple formats"""
|
|
18
|
+
|
|
19
|
+
def __init__(self):
|
|
20
|
+
"""Initialize all converters"""
|
|
21
|
+
self.document_converter = DocumentConverter()
|
|
22
|
+
self.data_converter = DataConverter()
|
|
23
|
+
self.image_converter = ImageConverter()
|
|
24
|
+
self.text_converter = TextConverter()
|
|
25
|
+
|
|
26
|
+
# Format mapping to appropriate converter
|
|
27
|
+
self.format_map = {
|
|
28
|
+
# Documents
|
|
29
|
+
'pdf': 'document',
|
|
30
|
+
'docx': 'document',
|
|
31
|
+
'doc': 'document',
|
|
32
|
+
'pptx': 'document',
|
|
33
|
+
'txt': 'text',
|
|
34
|
+
|
|
35
|
+
# Data
|
|
36
|
+
'csv': 'data',
|
|
37
|
+
'json': 'data',
|
|
38
|
+
'xml': 'data',
|
|
39
|
+
'yaml': 'data',
|
|
40
|
+
'yml': 'data',
|
|
41
|
+
'xlsx': 'data',
|
|
42
|
+
'xls': 'data',
|
|
43
|
+
|
|
44
|
+
# Images
|
|
45
|
+
'png': 'image',
|
|
46
|
+
'jpg': 'image',
|
|
47
|
+
'jpeg': 'image',
|
|
48
|
+
'webp': 'image',
|
|
49
|
+
'svg': 'image',
|
|
50
|
+
|
|
51
|
+
# Text & Code
|
|
52
|
+
'md': 'text',
|
|
53
|
+
'html': 'text',
|
|
54
|
+
'rtf': 'text',
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
def convert(self, input_file: Union[str, Path],
|
|
58
|
+
output_file: Union[str, Path],
|
|
59
|
+
preserve_quality: bool = True) -> bool:
|
|
60
|
+
"""
|
|
61
|
+
Convert a single file from one format to another
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
input_file: Path to input file
|
|
65
|
+
output_file: Path to output file
|
|
66
|
+
preserve_quality: Whether to preserve quality (for images)
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
bool: True if conversion successful, False otherwise
|
|
70
|
+
"""
|
|
71
|
+
input_path = Path(input_file)
|
|
72
|
+
output_path = Path(output_file)
|
|
73
|
+
|
|
74
|
+
# Validate input file
|
|
75
|
+
if not input_path.exists():
|
|
76
|
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
|
77
|
+
|
|
78
|
+
# Get input and output formats
|
|
79
|
+
input_format = input_path.suffix.lower().lstrip('.')
|
|
80
|
+
output_format = output_path.suffix.lower().lstrip('.')
|
|
81
|
+
|
|
82
|
+
# Check if formats are supported
|
|
83
|
+
if input_format not in self.format_map:
|
|
84
|
+
raise ValueError(f"Unsupported input format: {input_format}")
|
|
85
|
+
|
|
86
|
+
if output_format not in self.format_map:
|
|
87
|
+
raise ValueError(f"Unsupported output format: {output_format}")
|
|
88
|
+
|
|
89
|
+
# Get appropriate converter
|
|
90
|
+
converter_type = self.format_map[input_format]
|
|
91
|
+
converter = getattr(self, f'{converter_type}_converter')
|
|
92
|
+
|
|
93
|
+
# Perform conversion
|
|
94
|
+
try:
|
|
95
|
+
converter.convert(str(input_path), str(output_path))
|
|
96
|
+
return True
|
|
97
|
+
except Exception as e:
|
|
98
|
+
print(f"Conversion failed: {e}")
|
|
99
|
+
return False
|
|
100
|
+
|
|
101
|
+
def convert_batch(self, input_files: List[Union[str, Path]],
|
|
102
|
+
output_dir: Union[str, Path],
|
|
103
|
+
output_format: str,
|
|
104
|
+
preserve_quality: bool = True) -> Dict[str, bool]:
|
|
105
|
+
"""
|
|
106
|
+
Convert multiple files in batch
|
|
107
|
+
|
|
108
|
+
Args:
|
|
109
|
+
input_files: List of input file paths
|
|
110
|
+
output_dir: Directory for output files
|
|
111
|
+
output_format: Target format
|
|
112
|
+
preserve_quality: Whether to preserve quality
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
dict: Mapping of input files to conversion success status
|
|
116
|
+
"""
|
|
117
|
+
output_path = Path(output_dir)
|
|
118
|
+
output_path.mkdir(parents=True, exist_ok=True)
|
|
119
|
+
|
|
120
|
+
results = {}
|
|
121
|
+
for input_file in input_files:
|
|
122
|
+
input_path = Path(input_file)
|
|
123
|
+
output_file = output_path / f"{input_path.stem}.{output_format}"
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
success = self.convert(input_path, output_file, preserve_quality)
|
|
127
|
+
results[str(input_file)] = success
|
|
128
|
+
except Exception as e:
|
|
129
|
+
print(f"Failed to convert {input_file}: {e}")
|
|
130
|
+
results[str(input_file)] = False
|
|
131
|
+
|
|
132
|
+
return results
|
|
133
|
+
|
|
134
|
+
def get_supported_formats(self) -> Dict[str, List[str]]:
|
|
135
|
+
"""
|
|
136
|
+
Get all supported formats organized by category
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
dict: Categories and their supported formats
|
|
140
|
+
"""
|
|
141
|
+
return {
|
|
142
|
+
'documents': ['pdf', 'docx', 'doc', 'pptx', 'txt'],
|
|
143
|
+
'data': ['csv', 'json', 'xml', 'yaml', 'xlsx', 'xls'],
|
|
144
|
+
'images': ['png', 'jpg', 'jpeg', 'webp', 'svg'],
|
|
145
|
+
'text_code': ['md', 'html', 'rtf'],
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
def get_conversion_matrix(self) -> Dict[str, List[str]]:
|
|
149
|
+
"""
|
|
150
|
+
Get conversion matrix (what can convert to what)
|
|
151
|
+
|
|
152
|
+
Returns:
|
|
153
|
+
dict: Source formats and possible target formats
|
|
154
|
+
"""
|
|
155
|
+
return {
|
|
156
|
+
'pdf': ['txt'],
|
|
157
|
+
'docx': ['txt'],
|
|
158
|
+
'txt': ['docx', 'md', 'html'],
|
|
159
|
+
'csv': ['json', 'xml', 'xlsx', 'yaml'],
|
|
160
|
+
'json': ['csv', 'xml', 'yaml', 'html'],
|
|
161
|
+
'xml': ['json', 'csv', 'yaml'],
|
|
162
|
+
'xlsx': ['csv', 'json', 'xml'],
|
|
163
|
+
'yaml': ['json', 'csv', 'xml'],
|
|
164
|
+
'png': ['jpg', 'webp'],
|
|
165
|
+
'jpg': ['png', 'webp'],
|
|
166
|
+
'webp': ['png', 'jpg'],
|
|
167
|
+
'md': ['html', 'txt'],
|
|
168
|
+
'html': ['md', 'txt'],
|
|
169
|
+
}
|