@convertrilo/sdk 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This file was auto-generated by openapi-typescript.
3
+ * Do not make direct changes to the file.
4
+ */
5
+ export {};
@@ -0,0 +1,51 @@
1
+ import { ConvertriloClient } from "@convertrilo/sdk";
2
+
3
+ const apiKey = process.env.CONVERTRILO_API_KEY;
4
+ if (!apiKey) throw new Error("Set CONVERTRILO_API_KEY");
5
+
6
+ const client = new ConvertriloClient({
7
+ baseUrl: process.env.CONVERTRILO_API_URL || "https://api.convertrilo.com",
8
+ apiKey,
9
+ });
10
+
11
+ async function main() {
12
+ const batch = await client.onDemandIngestFolder({
13
+ sourceS3: {
14
+ bucket: requireEnv("CUSTOMER_SOURCE_S3_BUCKET"),
15
+ prefix: process.env.CUSTOMER_SOURCE_S3_PREFIX || "incoming/",
16
+ region: process.env.CUSTOMER_S3_REGION || "us-east-1",
17
+ endpoint: process.env.CUSTOMER_S3_ENDPOINT,
18
+ accessKeyId: requireEnv("CUSTOMER_S3_ACCESS_KEY_ID"),
19
+ secretAccessKey: requireEnv("CUSTOMER_S3_SECRET_ACCESS_KEY"),
20
+ forcePathStyle: process.env.CUSTOMER_S3_FORCE_PATH_STYLE === "true",
21
+ },
22
+ outputDestination: "s3",
23
+ outputS3: {
24
+ bucket: requireEnv("CUSTOMER_OUTPUT_S3_BUCKET"),
25
+ prefix: process.env.CUSTOMER_OUTPUT_S3_PREFIX || "encoded/",
26
+ region: process.env.CUSTOMER_S3_REGION || "us-east-1",
27
+ endpoint: process.env.CUSTOMER_S3_ENDPOINT,
28
+ accessKeyId: requireEnv("CUSTOMER_S3_ACCESS_KEY_ID"),
29
+ secretAccessKey: requireEnv("CUSTOMER_S3_SECRET_ACCESS_KEY"),
30
+ forcePathStyle: process.env.CUSTOMER_S3_FORCE_PATH_STYLE === "true",
31
+ },
32
+ codec: "h264",
33
+ resolution: "1080p",
34
+ });
35
+
36
+ console.log(batch.message);
37
+ for (const job of batch.jobs || []) {
38
+ console.log(`${job.jobId} ${job.fileName ?? ""}`);
39
+ }
40
+ }
41
+
42
+ function requireEnv(name: string) {
43
+ const value = process.env[name];
44
+ if (!value) throw new Error(`Set ${name}`);
45
+ return value;
46
+ }
47
+
48
+ main().catch((error) => {
49
+ console.error(error);
50
+ process.exit(1);
51
+ });
@@ -0,0 +1,37 @@
1
+ import { ConvertriloClient } from "@convertrilo/sdk";
2
+
3
+ const apiKey = process.env.CONVERTRILO_API_KEY;
4
+ if (!apiKey) throw new Error("Set CONVERTRILO_API_KEY");
5
+
6
+ const client = new ConvertriloClient({
7
+ baseUrl: process.env.CONVERTRILO_API_URL || "https://api.convertrilo.com",
8
+ apiKey,
9
+ });
10
+
11
+ async function main() {
12
+ const job = await client.onDemandEncode({
13
+ sourceUrl: "https://example.com/input.mp4",
14
+ codec: "h264",
15
+ resolution: "1080p",
16
+ outputGoogleDrive: {
17
+ folderId: requireEnv("GOOGLE_DRIVE_OUTPUT_FOLDER_ID"),
18
+ fileName: "input-1080p.mp4",
19
+ accessToken: requireEnv("CUSTOMER_GOOGLE_ACCESS_TOKEN"),
20
+ refreshToken: process.env.CUSTOMER_GOOGLE_REFRESH_TOKEN,
21
+ },
22
+ });
23
+
24
+ console.log(`Queued job ${job.jobId}`);
25
+ console.log("The customer authorizes Google in your app; your backend passes the token here.");
26
+ }
27
+
28
+ function requireEnv(name: string) {
29
+ const value = process.env[name];
30
+ if (!value) throw new Error(`Set ${name}`);
31
+ return value;
32
+ }
33
+
34
+ main().catch((error) => {
35
+ console.error(error);
36
+ process.exit(1);
37
+ });
@@ -0,0 +1,41 @@
1
+ import { ConvertriloClient } from "@convertrilo/sdk";
2
+
3
+ const apiKey = process.env.CONVERTRILO_API_KEY;
4
+ if (!apiKey) throw new Error("Set CONVERTRILO_API_KEY");
5
+
6
+ const client = new ConvertriloClient({
7
+ baseUrl: process.env.CONVERTRILO_API_URL || "https://api.convertrilo.com",
8
+ apiKey,
9
+ });
10
+
11
+ async function main() {
12
+ const job = await client.onDemandEncode({
13
+ sourceUrl: "https://example.com/input.mp4",
14
+ codec: "h264",
15
+ resolution: "1080p",
16
+ quality: "better",
17
+ });
18
+
19
+ console.log(`Queued job ${job.jobId}`);
20
+
21
+ while (true) {
22
+ const status = await client.onDemandStatus(job.jobId);
23
+ console.log(`status=${status.status} progress=${status.progress ?? 0}`);
24
+
25
+ if (status.status === "success") {
26
+ console.log(`downloadUrl=${status.downloadUrl}`);
27
+ return;
28
+ }
29
+
30
+ if (status.status === "failed" || status.status === "canceled") {
31
+ throw new Error(status.failureMessage || `Job ended with ${status.status}`);
32
+ }
33
+
34
+ await new Promise((resolve) => setTimeout(resolve, 5000));
35
+ }
36
+ }
37
+
38
+ main().catch((error) => {
39
+ console.error(error);
40
+ process.exit(1);
41
+ });
@@ -0,0 +1,40 @@
1
+ import { ConvertriloClient } from "@convertrilo/sdk";
2
+
3
+ const apiKey = process.env.CONVERTRILO_API_KEY;
4
+ if (!apiKey) throw new Error("Set CONVERTRILO_API_KEY");
5
+
6
+ const client = new ConvertriloClient({
7
+ baseUrl: process.env.CONVERTRILO_API_URL || "https://api.convertrilo.com",
8
+ apiKey,
9
+ });
10
+
11
+ async function main() {
12
+ const job = await client.onDemandEncode({
13
+ sourceUrl: "https://example.com/input.mp4",
14
+ codec: "h264",
15
+ resolution: "1080p",
16
+ outputS3: {
17
+ bucket: requireEnv("CUSTOMER_S3_BUCKET"),
18
+ key: "encoded/input-1080p.mp4",
19
+ region: process.env.CUSTOMER_S3_REGION || "us-east-1",
20
+ endpoint: process.env.CUSTOMER_S3_ENDPOINT,
21
+ accessKeyId: requireEnv("CUSTOMER_S3_ACCESS_KEY_ID"),
22
+ secretAccessKey: requireEnv("CUSTOMER_S3_SECRET_ACCESS_KEY"),
23
+ forcePathStyle: process.env.CUSTOMER_S3_FORCE_PATH_STYLE === "true",
24
+ },
25
+ });
26
+
27
+ console.log(`Queued job ${job.jobId}`);
28
+ console.log("Poll with client.onDemandStatus(jobId) until status is success.");
29
+ }
30
+
31
+ function requireEnv(name: string) {
32
+ const value = process.env[name];
33
+ if (!value) throw new Error(`Set ${name}`);
34
+ return value;
35
+ }
36
+
37
+ main().catch((error) => {
38
+ console.error(error);
39
+ process.exit(1);
40
+ });