magic-hour 0.36.0 → 0.37.0
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.
- package/README.md +202 -10
- package/dist/helpers/download.d.ts +5 -0
- package/dist/helpers/download.js +88 -0
- package/dist/helpers/generate-type.d.ts +51 -0
- package/dist/helpers/generate-type.js +2 -0
- package/dist/helpers/sleep.d.ts +4 -0
- package/dist/helpers/sleep.js +9 -0
- package/dist/logger.d.ts +48 -0
- package/dist/logger.js +97 -0
- package/dist/resources/v1/ai-clothes-changer/resource-client.d.ts +50 -0
- package/dist/resources/v1/ai-clothes-changer/resource-client.js +75 -0
- package/dist/resources/v1/ai-face-editor/resource-client.d.ts +55 -0
- package/dist/resources/v1/ai-face-editor/resource-client.js +85 -0
- package/dist/resources/v1/ai-gif-generator/resource-client.d.ts +29 -0
- package/dist/resources/v1/ai-gif-generator/resource-client.js +60 -0
- package/dist/resources/v1/ai-headshot-generator/resource-client.d.ts +38 -0
- package/dist/resources/v1/ai-headshot-generator/resource-client.js +68 -0
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +39 -0
- package/dist/resources/v1/ai-image-editor/resource-client.js +69 -0
- package/dist/resources/v1/ai-image-generator/resource-client.d.ts +31 -0
- package/dist/resources/v1/ai-image-generator/resource-client.js +62 -0
- package/dist/resources/v1/ai-image-upscaler/resource-client.d.ts +40 -0
- package/dist/resources/v1/ai-image-upscaler/resource-client.js +70 -0
- package/dist/resources/v1/ai-meme-generator/resource-client.d.ts +33 -0
- package/dist/resources/v1/ai-meme-generator/resource-client.js +64 -0
- package/dist/resources/v1/ai-photo-editor/resource-client.d.ts +49 -0
- package/dist/resources/v1/ai-photo-editor/resource-client.js +79 -0
- package/dist/resources/v1/ai-qr-code-generator/resource-client.d.ts +30 -0
- package/dist/resources/v1/ai-qr-code-generator/resource-client.js +61 -0
- package/dist/resources/v1/ai-talking-photo/resource-client.d.ts +51 -0
- package/dist/resources/v1/ai-talking-photo/resource-client.js +76 -0
- package/dist/resources/v1/animation/resource-client.d.ts +61 -0
- package/dist/resources/v1/animation/resource-client.js +98 -0
- package/dist/resources/v1/auto-subtitle-generator/resource-client.d.ts +41 -0
- package/dist/resources/v1/auto-subtitle-generator/resource-client.js +71 -0
- package/dist/resources/v1/face-detection/resource-client.d.ts +30 -0
- package/dist/resources/v1/face-detection/resource-client.js +75 -0
- package/dist/resources/v1/face-swap/resource-client.d.ts +77 -0
- package/dist/resources/v1/face-swap/resource-client.js +125 -0
- package/dist/resources/v1/face-swap-photo/resource-client.d.ts +73 -0
- package/dist/resources/v1/face-swap-photo/resource-client.js +117 -0
- package/dist/resources/v1/files/resource-client.d.ts +40 -0
- package/dist/resources/v1/files/resource-client.js +236 -0
- package/dist/resources/v1/files/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/files/resource-client.test.js +422 -0
- package/dist/resources/v1/image-background-remover/resource-client.d.ts +49 -0
- package/dist/resources/v1/image-background-remover/resource-client.js +82 -0
- package/dist/resources/v1/image-projects/resource-client.d.ts +22 -0
- package/dist/resources/v1/image-projects/resource-client.js +68 -0
- package/dist/resources/v1/image-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/image-projects/resource-client.test.js +538 -0
- package/dist/resources/v1/image-to-video/resource-client.d.ts +40 -0
- package/dist/resources/v1/image-to-video/resource-client.js +70 -0
- package/dist/resources/v1/lip-sync/resource-client.d.ts +53 -0
- package/dist/resources/v1/lip-sync/resource-client.js +84 -0
- package/dist/resources/v1/photo-colorizer/resource-client.d.ts +38 -0
- package/dist/resources/v1/photo-colorizer/resource-client.js +68 -0
- package/dist/resources/v1/text-to-video/resource-client.d.ts +32 -0
- package/dist/resources/v1/text-to-video/resource-client.js +63 -0
- package/dist/resources/v1/video-projects/resource-client.d.ts +22 -0
- package/dist/resources/v1/video-projects/resource-client.js +68 -0
- package/dist/resources/v1/video-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/video-projects/resource-client.test.js +713 -0
- package/dist/resources/v1/video-to-video/resource-client.d.ts +48 -0
- package/dist/resources/v1/video-to-video/resource-client.js +84 -0
- package/package.json +15 -11
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
# Magic Hour
|
|
1
|
+
# Magic Hour Node SDK
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/magic-hour)
|
|
4
4
|
|
|
5
|
-
Magic Hour
|
|
5
|
+
The Magic Hour Node SDK provides convenient access to the Magic Hour API via server-side TypeScript or JavaScript.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
For full documentation of all APIs, please visit https://docs.magichour.ai
|
|
8
10
|
|
|
9
11
|
If you have any questions, please reach out to us via [discord](https://discord.gg/JX5rgsZaJp).
|
|
10
12
|
|
|
@@ -16,19 +18,184 @@ npm install magic-hour
|
|
|
16
18
|
|
|
17
19
|
## Usage
|
|
18
20
|
|
|
19
|
-
Initialize the client
|
|
20
|
-
|
|
21
21
|
```ts
|
|
22
22
|
import Client from "magic-hour";
|
|
23
|
-
|
|
24
23
|
// generate your API Key at https://magichour.ai/developer
|
|
25
|
-
const client = new Client({
|
|
26
|
-
|
|
24
|
+
const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
25
|
+
const res = await client.v1.faceSwapPhoto.generate(
|
|
26
|
+
{
|
|
27
|
+
assets: {
|
|
28
|
+
faceSwapMode: "all-faces",
|
|
29
|
+
sourceFilePath: "/path/to/source/image.png",
|
|
30
|
+
targetFilePath: "/path/to/target/image.png",
|
|
31
|
+
},
|
|
32
|
+
name: "Face Swap image",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
waitForCompletion: true,
|
|
36
|
+
downloadOutputs: true,
|
|
37
|
+
downloadDirectory: "outputs",
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
console.log(`Project ID: ${response.id}`)
|
|
42
|
+
console.log(`Status: ${response.status}`)
|
|
43
|
+
console.log(`Downloaded files: ${response.downloaded_paths}`)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Client Functions
|
|
47
|
+
|
|
48
|
+
Most resources that generate media content support two methods:
|
|
49
|
+
|
|
50
|
+
- **`generate()`** - A high-level convenience method that handles the entire workflow
|
|
51
|
+
- **`create()`** - A low-level method that only initiates the generation process
|
|
52
|
+
|
|
53
|
+
### Generate Function
|
|
54
|
+
|
|
55
|
+
The `generate()` function provides a complete end-to-end solution:
|
|
56
|
+
|
|
57
|
+
- Uploads local files to Magic Hour storage
|
|
58
|
+
- Calls the API to start generation
|
|
59
|
+
- Automatically polls for completion
|
|
60
|
+
- Downloads generated files to your local machine
|
|
61
|
+
- Returns both API response data and local file paths
|
|
62
|
+
|
|
63
|
+
**Additional Parameters:**
|
|
64
|
+
|
|
65
|
+
- `waitForCompletion` (boolean, default true): Whether to wait for the project to complete
|
|
66
|
+
- `downloadOutputs` (boolean, default true): Whether to download the generated files
|
|
67
|
+
- `downloadDirectory` (string, optional): Directory to save downloaded files (defaults to current directory)
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const response = await client.v1.faceSwapPhoto.generate(
|
|
71
|
+
{
|
|
72
|
+
assets: {
|
|
73
|
+
faceSwapMode: "all-faces",
|
|
74
|
+
sourceFilePath: "/path/to/source/image.png",
|
|
75
|
+
targetFilePath: "/path/to/target/image.png",
|
|
76
|
+
},
|
|
77
|
+
name: "Face Swap image",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
waitForCompletion: true, // Wait for status to be complete/error/canceled
|
|
81
|
+
downloadOutputs: true, // Download files automatically
|
|
82
|
+
downloadDirectory: "./outputs/" // Where to save files
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// You get both the API response AND downloaded file paths
|
|
87
|
+
console.log(`Project ID: ${response.id}`);
|
|
88
|
+
console.log(`Status: ${response.status}`);
|
|
89
|
+
console.log(`Downloaded files: ${response.downloadedPaths}`);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Create Function
|
|
93
|
+
|
|
94
|
+
The `create()` function provides granular control:
|
|
95
|
+
|
|
96
|
+
- Only calls the API to start the generation process
|
|
97
|
+
- Returns immediately with a project ID and amount of credits used
|
|
98
|
+
- Requires manual status checking and file downloading
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// upload the files to Magic Hour's storage or you can use direct URLs
|
|
102
|
+
const sourceFilePath = await client.v1.files.uploadFile("/path/to/source/image.png")
|
|
103
|
+
const targetFilePath = await client.v1.files.uploadFile("/path/to/target/image.png")
|
|
104
|
+
|
|
105
|
+
// Create function - only starts the process
|
|
106
|
+
const createResponse = await client.v1.faceSwapPhoto.create({
|
|
107
|
+
assets: {
|
|
108
|
+
faceSwapMode: "all-faces",
|
|
109
|
+
sourceFilePath: sourceFilePath,
|
|
110
|
+
targetFilePath: targetFilePath,
|
|
111
|
+
},
|
|
112
|
+
name: "Face Swap image"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// You get just the project ID and initial response
|
|
116
|
+
const projectId = createResponse.id;
|
|
117
|
+
console.log(`Started project: ${projectId}`);
|
|
118
|
+
|
|
119
|
+
// You must handle the rest:
|
|
120
|
+
// 1. Poll for completion using the image/video projects API
|
|
121
|
+
const result = await client.v1.imageProjects.checkResults(projectId, {
|
|
122
|
+
waitForCompletion: true,
|
|
123
|
+
downloadOutputs: false,
|
|
27
124
|
});
|
|
125
|
+
|
|
126
|
+
// 2. Download files using the download URLs
|
|
127
|
+
const downloadUrls = result.downloads;
|
|
128
|
+
// Download the files using your preferred method
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Choosing Between Which Function to Use
|
|
132
|
+
|
|
133
|
+
**Use `generate()` when:**
|
|
134
|
+
|
|
135
|
+
- You want a simple, one-call solution
|
|
136
|
+
- You're building a straightforward application
|
|
137
|
+
- You don't need custom polling or download logic
|
|
138
|
+
|
|
139
|
+
**Use `create()` when:**
|
|
140
|
+
|
|
141
|
+
- You need custom status checking logic
|
|
142
|
+
- You're integrating with existing job processing systems
|
|
143
|
+
- You want to separate generation initiation from completion handling
|
|
144
|
+
- You need fine-grained control over the entire workflow
|
|
145
|
+
|
|
146
|
+
## Error Handling
|
|
147
|
+
|
|
148
|
+
The Magic Hour SDK includes the `ApiError` class, which includes the request and response data.
|
|
149
|
+
|
|
150
|
+
### Basic Error Handling
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
try {
|
|
154
|
+
await client.v1.imageToVideo.generate(
|
|
155
|
+
{
|
|
156
|
+
assets: {
|
|
157
|
+
imageFilePath: "/Users/dhu/Desktop/test-files/suit.jpg",
|
|
158
|
+
},
|
|
159
|
+
endSeconds: 0,
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error instanceof ApiError) {
|
|
164
|
+
console.error(`API Error: ${error.message}`); // API Error: 400 was returned from post /v1/image-to-video
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const errorData = await error.response.json();
|
|
168
|
+
console.error(`Error Message: ${errorData.message}`); // Error Message: end_seconds must be at least 5
|
|
169
|
+
} catch (parseError) {
|
|
170
|
+
console.error("Could not parse error response");
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
console.error("Unexpected error:", error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Logging
|
|
179
|
+
|
|
180
|
+
### Logging Levels
|
|
181
|
+
|
|
182
|
+
- `none` - Disable all logging
|
|
183
|
+
- `error` - Only error messages
|
|
184
|
+
- `warn` - Warnings and errors
|
|
185
|
+
- `info` - Info, warnings, and errors
|
|
186
|
+
- `debug` - All messages including request/response details
|
|
187
|
+
|
|
188
|
+
### Environment Variable Configuration
|
|
189
|
+
|
|
190
|
+
You can also configure the logging level using the `MAGIC_HOUR_LOG_LEVEL` environment variable:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
export MAGIC_HOUR_LOG_LEVEL=debug # Enable debug logging
|
|
194
|
+
# or
|
|
195
|
+
export MAGIC_HOUR_LOG_LEVEL=error # Only show errors
|
|
28
196
|
```
|
|
29
197
|
|
|
30
|
-
|
|
31
|
-
> Any API call that renders a video will utilize frames in your account.
|
|
198
|
+
Valid values are: `none`, `error`, `warn`, `info`, `debug` (case insensitive). If not set, defaults to `info`.
|
|
32
199
|
|
|
33
200
|
## Module Documentation and Snippets
|
|
34
201
|
|
|
@@ -38,70 +205,87 @@ const client = new Client({
|
|
|
38
205
|
### [v1.aiClothesChanger](src/resources/v1/ai-clothes-changer/README.md)
|
|
39
206
|
|
|
40
207
|
* [create](src/resources/v1/ai-clothes-changer/README.md#create) - AI Clothes Changer
|
|
208
|
+
* [generate](src/resources/v1/ai-clothes-changer/README.md#generate) - AI Clothes Changer Generate Workflow
|
|
41
209
|
|
|
42
210
|
### [v1.aiFaceEditor](src/resources/v1/ai-face-editor/README.md)
|
|
43
211
|
|
|
44
212
|
* [create](src/resources/v1/ai-face-editor/README.md#create) - AI Face Editor
|
|
213
|
+
* [generate](src/resources/v1/ai-face-editor/README.md#generate) - AI Face Editor Generate Workflow
|
|
45
214
|
|
|
46
215
|
### [v1.aiGifGenerator](src/resources/v1/ai-gif-generator/README.md)
|
|
47
216
|
|
|
48
217
|
* [create](src/resources/v1/ai-gif-generator/README.md#create) - AI GIFs
|
|
218
|
+
* [generate](src/resources/v1/ai-gif-generator/README.md#generate) - AI Gif Generator Generate Workflow
|
|
49
219
|
|
|
50
220
|
### [v1.aiHeadshotGenerator](src/resources/v1/ai-headshot-generator/README.md)
|
|
51
221
|
|
|
52
222
|
* [create](src/resources/v1/ai-headshot-generator/README.md#create) - AI Headshots
|
|
223
|
+
* [generate](src/resources/v1/ai-headshot-generator/README.md#generate) - AI Headshot Generator Generate Workflow
|
|
53
224
|
|
|
54
225
|
### [v1.aiImageEditor](src/resources/v1/ai-image-editor/README.md)
|
|
55
226
|
|
|
56
227
|
* [create](src/resources/v1/ai-image-editor/README.md#create) - AI Image Editor
|
|
228
|
+
* [generate](src/resources/v1/ai-image-editor/README.md#generate) - AI Image Editor Generate Workflow
|
|
57
229
|
|
|
58
230
|
### [v1.aiImageGenerator](src/resources/v1/ai-image-generator/README.md)
|
|
59
231
|
|
|
60
232
|
* [create](src/resources/v1/ai-image-generator/README.md#create) - AI Images
|
|
233
|
+
* [generate](src/resources/v1/ai-image-generator/README.md#generate) - AI Image Generator Generate Workflow
|
|
61
234
|
|
|
62
235
|
### [v1.aiImageUpscaler](src/resources/v1/ai-image-upscaler/README.md)
|
|
63
236
|
|
|
64
237
|
* [create](src/resources/v1/ai-image-upscaler/README.md#create) - AI Image Upscaler
|
|
238
|
+
* [generate](src/resources/v1/ai-image-upscaler/README.md#generate) - AI Image Upscaler Generate Workflow
|
|
65
239
|
|
|
66
240
|
### [v1.aiMemeGenerator](src/resources/v1/ai-meme-generator/README.md)
|
|
67
241
|
|
|
68
242
|
* [create](src/resources/v1/ai-meme-generator/README.md#create) - AI Meme Generator
|
|
243
|
+
* [generate](src/resources/v1/ai-meme-generator/README.md#generate) - AI Meme Generator Generate Workflow
|
|
69
244
|
|
|
70
245
|
### [v1.aiPhotoEditor](src/resources/v1/ai-photo-editor/README.md)
|
|
71
246
|
|
|
72
247
|
* [create](src/resources/v1/ai-photo-editor/README.md#create) - AI Photo Editor
|
|
248
|
+
* [generate](src/resources/v1/ai-photo-editor/README.md#generate) - AI Photo Editor Generate Workflow
|
|
73
249
|
|
|
74
250
|
### [v1.aiQrCodeGenerator](src/resources/v1/ai-qr-code-generator/README.md)
|
|
75
251
|
|
|
76
252
|
* [create](src/resources/v1/ai-qr-code-generator/README.md#create) - AI QR Code
|
|
253
|
+
* [generate](src/resources/v1/ai-qr-code-generator/README.md#generate) - AI Qr Code Generator Generate Workflow
|
|
77
254
|
|
|
78
255
|
### [v1.aiTalkingPhoto](src/resources/v1/ai-talking-photo/README.md)
|
|
79
256
|
|
|
80
257
|
* [create](src/resources/v1/ai-talking-photo/README.md#create) - AI Talking Photo
|
|
258
|
+
* [generate](src/resources/v1/ai-talking-photo/README.md#generate) - AI Talking Photo Generate Workflow
|
|
81
259
|
|
|
82
260
|
### [v1.animation](src/resources/v1/animation/README.md)
|
|
83
261
|
|
|
84
262
|
* [create](src/resources/v1/animation/README.md#create) - Animation
|
|
263
|
+
* [generate](src/resources/v1/animation/README.md#generate) - Animation Generate Workflow
|
|
85
264
|
|
|
86
265
|
### [v1.autoSubtitleGenerator](src/resources/v1/auto-subtitle-generator/README.md)
|
|
87
266
|
|
|
88
267
|
* [create](src/resources/v1/auto-subtitle-generator/README.md#create) - Auto Subtitle Generator
|
|
268
|
+
* [generate](src/resources/v1/auto-subtitle-generator/README.md#generate) - Auto Subtitle Generator Generate Workflow
|
|
89
269
|
|
|
90
270
|
### [v1.faceDetection](src/resources/v1/face-detection/README.md)
|
|
91
271
|
|
|
92
272
|
* [create](src/resources/v1/face-detection/README.md#create) - Face Detection
|
|
273
|
+
* [generate](src/resources/v1/face-detection/README.md#generate) - Face Detection Generate Workflow
|
|
93
274
|
* [get](src/resources/v1/face-detection/README.md#get) - Get face detection details
|
|
94
275
|
|
|
95
276
|
### [v1.faceSwap](src/resources/v1/face-swap/README.md)
|
|
96
277
|
|
|
97
278
|
* [create](src/resources/v1/face-swap/README.md#create) - Face Swap video
|
|
279
|
+
* [generate](src/resources/v1/face-swap/README.md#generate) - Face Swap Generate Workflow
|
|
98
280
|
|
|
99
281
|
### [v1.faceSwapPhoto](src/resources/v1/face-swap-photo/README.md)
|
|
100
282
|
|
|
101
283
|
* [create](src/resources/v1/face-swap-photo/README.md#create) - Face Swap Photo
|
|
284
|
+
* [generate](src/resources/v1/face-swap-photo/README.md#generate) - Face Swap Photo Generate Workflow
|
|
102
285
|
|
|
103
286
|
### [v1.files](src/resources/v1/files/README.md)
|
|
104
287
|
|
|
288
|
+
* [upload-file](src/resources/v1/files/README.md#upload-file) - Upload File
|
|
105
289
|
|
|
106
290
|
### [v1.files.uploadUrls](src/resources/v1/files/upload-urls/README.md)
|
|
107
291
|
|
|
@@ -110,35 +294,43 @@ const client = new Client({
|
|
|
110
294
|
### [v1.imageBackgroundRemover](src/resources/v1/image-background-remover/README.md)
|
|
111
295
|
|
|
112
296
|
* [create](src/resources/v1/image-background-remover/README.md#create) - Image Background Remover
|
|
297
|
+
* [generate](src/resources/v1/image-background-remover/README.md#generate) - Image Background Remover Generate Workflow
|
|
113
298
|
|
|
114
299
|
### [v1.imageProjects](src/resources/v1/image-projects/README.md)
|
|
115
300
|
|
|
301
|
+
* [check-result](src/resources/v1/image-projects/README.md#check-result) - Check results
|
|
116
302
|
* [delete](src/resources/v1/image-projects/README.md#delete) - Delete image
|
|
117
303
|
* [get](src/resources/v1/image-projects/README.md#get) - Get image details
|
|
118
304
|
|
|
119
305
|
### [v1.imageToVideo](src/resources/v1/image-to-video/README.md)
|
|
120
306
|
|
|
121
307
|
* [create](src/resources/v1/image-to-video/README.md#create) - Image-to-Video
|
|
308
|
+
* [generate](src/resources/v1/image-to-video/README.md#generate) - Image To Video Generate Workflow
|
|
122
309
|
|
|
123
310
|
### [v1.lipSync](src/resources/v1/lip-sync/README.md)
|
|
124
311
|
|
|
125
312
|
* [create](src/resources/v1/lip-sync/README.md#create) - Lip Sync
|
|
313
|
+
* [generate](src/resources/v1/lip-sync/README.md#generate) - Lip Sync Generate Workflow
|
|
126
314
|
|
|
127
315
|
### [v1.photoColorizer](src/resources/v1/photo-colorizer/README.md)
|
|
128
316
|
|
|
129
317
|
* [create](src/resources/v1/photo-colorizer/README.md#create) - Photo Colorizer
|
|
318
|
+
* [generate](src/resources/v1/photo-colorizer/README.md#generate) - Photo Colorizer Generate Workflow
|
|
130
319
|
|
|
131
320
|
### [v1.textToVideo](src/resources/v1/text-to-video/README.md)
|
|
132
321
|
|
|
133
322
|
* [create](src/resources/v1/text-to-video/README.md#create) - Text-to-Video
|
|
323
|
+
* [generate](src/resources/v1/text-to-video/README.md#generate) - Text To Video Generate Workflow
|
|
134
324
|
|
|
135
325
|
### [v1.videoProjects](src/resources/v1/video-projects/README.md)
|
|
136
326
|
|
|
327
|
+
* [check-result](src/resources/v1/video-projects/README.md#check-result) - Check results
|
|
137
328
|
* [delete](src/resources/v1/video-projects/README.md#delete) - Delete video
|
|
138
329
|
* [get](src/resources/v1/video-projects/README.md#get) - Get video details
|
|
139
330
|
|
|
140
331
|
### [v1.videoToVideo](src/resources/v1/video-to-video/README.md)
|
|
141
332
|
|
|
142
333
|
* [create](src/resources/v1/video-to-video/README.md#create) - Video-to-Video
|
|
334
|
+
* [generate](src/resources/v1/video-to-video/README.md#generate) - Video To Video Generate Workflow
|
|
143
335
|
|
|
144
336
|
<!-- MODULE DOCS END -->
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { types } from "../index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Download files from the given download URLs
|
|
4
|
+
*/
|
|
5
|
+
export declare function downloadFiles(downloads: (types.V1ImageProjectsGetResponseDownloadsItem | types.V1VideoProjectsGetResponseDownloadsItem)[], downloadDirectory?: string): Promise<string[]>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.downloadFiles = downloadFiles;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
52
|
+
const logger_1 = require("../logger");
|
|
53
|
+
/**
|
|
54
|
+
* Download files from the given download URLs
|
|
55
|
+
*/
|
|
56
|
+
function downloadFiles(downloads, downloadDirectory) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const downloadedPaths = [];
|
|
59
|
+
// Use current working directory if no download directory specified
|
|
60
|
+
const baseDir = downloadDirectory || process.cwd();
|
|
61
|
+
// Ensure the download directory exists
|
|
62
|
+
if (!fs.existsSync(baseDir)) {
|
|
63
|
+
fs.mkdirSync(baseDir, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
(0, logger_1.getLogger)().debug(`Downloading outputs to ${baseDir}`);
|
|
66
|
+
for (const download of downloads) {
|
|
67
|
+
(0, logger_1.getLogger)().debug(`Downloading output from ${download.url}`);
|
|
68
|
+
try {
|
|
69
|
+
const response = yield (0, node_fetch_1.default)(download.url);
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new Error(`Failed to download from ${download.url}: ${response.statusText}`);
|
|
72
|
+
}
|
|
73
|
+
const buffer = yield response.arrayBuffer();
|
|
74
|
+
// Extract filename from URL or generate one
|
|
75
|
+
const urlPath = new URL(download.url).pathname;
|
|
76
|
+
const filename = path.basename(urlPath) || `download_${Date.now()}`;
|
|
77
|
+
const filePath = path.join(baseDir, filename);
|
|
78
|
+
fs.writeFileSync(filePath, Buffer.from(buffer));
|
|
79
|
+
(0, logger_1.getLogger)().debug(`Downloaded output to ${filePath}`);
|
|
80
|
+
downloadedPaths.push(filePath);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
(0, logger_1.getLogger)().error(`Error downloading file from ${download.url}: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return downloadedPaths;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RequestOptions } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the `generate` method.
|
|
4
|
+
*/
|
|
5
|
+
export type GenerateOptions = RequestOptions & {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to wait for the generation to complete before returning the result.
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
waitForCompletion?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to download the generated outputs to local disk.
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
downloadOutputs?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The directory to save the downloaded outputs.
|
|
20
|
+
*
|
|
21
|
+
* @default undefined
|
|
22
|
+
*/
|
|
23
|
+
downloadDirectory?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
type FilePathKeys<T> = Extract<keyof T, `${string}FilePath`>;
|
|
26
|
+
type FilePathProps<T> = Pick<T, FilePathKeys<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* A type that allows you to override the `${string}FilePath` fields of the assets object.
|
|
29
|
+
*
|
|
30
|
+
* This is necessary to override the jsdoc for the asset fields, which now support local paths.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* type GenerateRequest = GenerateRequestType<requests.CreateRequest, {
|
|
35
|
+
* // custom jsdoc for the asset field
|
|
36
|
+
* garmentFilePath: string;
|
|
37
|
+
* }>;
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type GenerateRequestType<CreateRequest, AssetOverrides extends CreateRequest extends {
|
|
41
|
+
assets: Record<string, any>;
|
|
42
|
+
} ? FilePathProps<CreateRequest["assets"]> & {
|
|
43
|
+
[K in Exclude<keyof AssetOverrides, FilePathKeys<CreateRequest["assets"]> | "faceMappings">]: {
|
|
44
|
+
ERROR: `AssetOverrides can only contain ${FilePathKeys<CreateRequest["assets"]>} or faceMappings`;
|
|
45
|
+
};
|
|
46
|
+
} : {}> = CreateRequest extends {
|
|
47
|
+
assets: Record<string, any>;
|
|
48
|
+
} ? Omit<CreateRequest, "assets"> & {
|
|
49
|
+
assets: Omit<CreateRequest["assets"], `${string}FilePath`> & AssetOverrides;
|
|
50
|
+
} : CreateRequest;
|
|
51
|
+
export {};
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging levels for the SDK
|
|
3
|
+
*/
|
|
4
|
+
export declare const LogLevel: {
|
|
5
|
+
readonly none: 0;
|
|
6
|
+
readonly error: 1;
|
|
7
|
+
readonly warn: 2;
|
|
8
|
+
readonly info: 3;
|
|
9
|
+
readonly debug: 4;
|
|
10
|
+
};
|
|
11
|
+
export type PossibleLogLevel = keyof typeof LogLevel;
|
|
12
|
+
/**
|
|
13
|
+
* Logger interface for the Magic Hour SDK
|
|
14
|
+
*/
|
|
15
|
+
export interface Logger {
|
|
16
|
+
/**
|
|
17
|
+
* Log an error message
|
|
18
|
+
*/
|
|
19
|
+
error(message: string, ...args: any[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* Log a warning message
|
|
22
|
+
*/
|
|
23
|
+
warn(message: string, ...args: any[]): void;
|
|
24
|
+
/**
|
|
25
|
+
* Log an info message
|
|
26
|
+
*/
|
|
27
|
+
info(message: string, ...args: any[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* Log a debug message
|
|
30
|
+
*/
|
|
31
|
+
debug(message: string, ...args: any[]): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Configuration options for the logger
|
|
35
|
+
*/
|
|
36
|
+
export interface LoggerConfig {
|
|
37
|
+
level: PossibleLogLevel;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Default logger configuration
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_LOGGER_CONFIG: LoggerConfig;
|
|
43
|
+
/**
|
|
44
|
+
* Create a logger instance based on configuration
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
export declare function setupLogger(config: LoggerConfig): Logger;
|
|
48
|
+
export declare function getLogger(): Logger;
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_LOGGER_CONFIG = exports.LogLevel = void 0;
|
|
4
|
+
exports.setupLogger = setupLogger;
|
|
5
|
+
exports.getLogger = getLogger;
|
|
6
|
+
/**
|
|
7
|
+
* Logging levels for the SDK
|
|
8
|
+
*/
|
|
9
|
+
exports.LogLevel = {
|
|
10
|
+
none: 0,
|
|
11
|
+
error: 1,
|
|
12
|
+
warn: 2,
|
|
13
|
+
info: 3,
|
|
14
|
+
debug: 4,
|
|
15
|
+
};
|
|
16
|
+
const logLevelOrder = ["none", "error", "warn", "info", "debug"];
|
|
17
|
+
/**
|
|
18
|
+
* Default logger implementation using console
|
|
19
|
+
*/
|
|
20
|
+
class ConsoleLogger {
|
|
21
|
+
constructor(config) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
}
|
|
24
|
+
shouldLog(level) {
|
|
25
|
+
return (logLevelOrder.indexOf(level) <= logLevelOrder.indexOf(this.config.level));
|
|
26
|
+
}
|
|
27
|
+
formatMessage(level, message) {
|
|
28
|
+
const timestamp = `[${new Date().toISOString()}]`;
|
|
29
|
+
const levelStr = `[${level.toUpperCase()}]`;
|
|
30
|
+
return [timestamp, levelStr, message].join(" ");
|
|
31
|
+
}
|
|
32
|
+
error(message, ...args) {
|
|
33
|
+
if (this.shouldLog("error")) {
|
|
34
|
+
console.error(this.formatMessage("error", message), ...args);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
warn(message, ...args) {
|
|
38
|
+
if (this.shouldLog("warn")) {
|
|
39
|
+
console.warn(this.formatMessage("warn", message), ...args);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
info(message, ...args) {
|
|
43
|
+
if (this.shouldLog("info")) {
|
|
44
|
+
console.info(this.formatMessage("info", message), ...args);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
debug(message, ...args) {
|
|
48
|
+
if (this.shouldLog("debug")) {
|
|
49
|
+
console.debug(this.formatMessage("debug", message), ...args);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* No-operation logger for when logging is disabled
|
|
55
|
+
*/
|
|
56
|
+
class NoOpLogger {
|
|
57
|
+
error() { }
|
|
58
|
+
warn() { }
|
|
59
|
+
info() { }
|
|
60
|
+
debug() { }
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get log level from environment variable or default
|
|
64
|
+
*/
|
|
65
|
+
function getLogLevelFromEnv() {
|
|
66
|
+
var _a;
|
|
67
|
+
const envLevel = (_a = process.env["MAGIC_HOUR_LOG_LEVEL"]) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
68
|
+
if (envLevel && envLevel in exports.LogLevel) {
|
|
69
|
+
return envLevel;
|
|
70
|
+
}
|
|
71
|
+
return "info";
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Default logger configuration
|
|
75
|
+
*/
|
|
76
|
+
exports.DEFAULT_LOGGER_CONFIG = {
|
|
77
|
+
level: "info",
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Create a logger instance based on configuration
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
function setupLogger(config) {
|
|
84
|
+
globalForLogger.logger =
|
|
85
|
+
config.level === "none" ? new NoOpLogger() : new ConsoleLogger(config);
|
|
86
|
+
return globalForLogger.logger;
|
|
87
|
+
}
|
|
88
|
+
const globalForLogger = globalThis;
|
|
89
|
+
function getLogger() {
|
|
90
|
+
if (!globalForLogger.logger) {
|
|
91
|
+
const config = {
|
|
92
|
+
level: getLogLevelFromEnv(),
|
|
93
|
+
};
|
|
94
|
+
globalForLogger.logger = setupLogger(config);
|
|
95
|
+
}
|
|
96
|
+
return globalForLogger.logger;
|
|
97
|
+
}
|