@mdgate/video 0.5.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 ADDED
@@ -0,0 +1,17 @@
1
+ # @mdgate/video
2
+
3
+ Convert MP4, MOV, WebM, Matroska, and AVI video to Markdown. Outputs GitHub-Flavored Markdown. Works
4
+ in Node, Edge, and browsers. No native addons, no external dependencies.
5
+
6
+ Needs an `(input) => markdown` function — `@mdgate/ai` or your own. The whole file is handed to that
7
+ function. `all()` does not register `video()`.
8
+
9
+ ```ts
10
+ import { create } from '@mdgate/core';
11
+ import { video } from '@mdgate/video';
12
+ import { ai } from '@mdgate/ai';
13
+
14
+ const convert = create([
15
+ video(ai({ baseURL, apiKey, model }).convertVideo),
16
+ ]);
17
+ ```
@@ -0,0 +1,3 @@
1
+ export { toMarkdown } from './to-markdown.js';
2
+ export type { ConvertVideo, VideoInput, VideoMime } from './types.js';
3
+ export { video } from './video.js';
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import{create as B}from"@mdgate/core";import{ConvertError as x}from"@mdgate/core";import{ConvertError as t}from"@mdgate/core";var c={mp4:"video/mp4",m4v:"video/mp4",mov:"video/quicktime",qt:"video/quicktime",webm:"video/webm",mkv:"video/x-matroska",mk3d:"video/x-matroska",avi:"video/x-msvideo"},l=new Set(["isom","iso2","iso3","iso4","iso5","iso6","mp41","mp42","mp71","avc1","av01","dash","mmp4","ndas","M4V ","M4VH","M4VP"]),h=new Set(["M4A ","M4B ","M4P "]),s=[208,207,17,224,161,177,26,225];function d(n){if(M(n))return"video/x-msvideo";let r=v(n);if(r!==void 0)return r;return A(n)}function u(n){let r=n.split(/[/\\]/).pop()??"",e=r.lastIndexOf(".");if(e<=0||e===r.length-1)return;return c[r.slice(e+1).toLowerCase()]}function a(n,r){return d(n)??(r?.path!==void 0?u(r.path):void 0)}function p(n){if(C(n))throw t.unsupported("pdf");if(U(n,s))throw t.unsupported("ole");if(n.length>=4&&n[0]===80&&n[1]===75&&n[2]===3&&n[3]===4)throw t.unsupported("zip")}function v(n){if(n.length<12)return;if(n[4]!==102||n[5]!==116||n[6]!==121||n[7]!==112)return;let r=g(n);if(r.some((e)=>h.has(e)))return;if(r.some((e)=>e==="qt "))return"video/quicktime";if(r.some((e)=>l.has(e)))return"video/mp4";return}function g(n){let r=(n[0]<<24|n[1]<<16|n[2]<<8|n[3])>>>0,e=Math.min(n.length,r>=16?r:n.length,256),i=[];if(n.length>=12)i.push(m(n,8));for(let o=16;o+4<=e;o+=4)i.push(m(n,o));return i}function m(n,r){return String.fromCharCode(n[r],n[r+1],n[r+2],n[r+3])}function A(n){if(n.length<4)return;if(n[0]!==26||n[1]!==69||n[2]!==223||n[3]!==163)return;let r=n.subarray(0,Math.min(n.length,256));if(k(r,"matroska"))return"video/x-matroska";return"video/webm"}function M(n){return n.length>=12&&n[0]===82&&n[1]===73&&n[2]===70&&n[3]===70&&n[8]===65&&n[9]===86&&n[10]===73&&n[11]===32}function C(n){let r=w(n);return V(n,"%PDF-",r)}function w(n){let r=0;if(n.length>=3&&n[0]===239&&n[1]===187&&n[2]===191)r=3;while(r<n.length){let e=n[r];if(e!==9&&e!==10&&e!==13&&e!==32)break;r+=1}return r}function U(n,r){if(n.length<r.length)return!1;for(let e=0;e<r.length;e+=1)if(n[e]!==r[e])return!1;return!0}function V(n,r,e){if(e+r.length>n.length)return!1;for(let i=0;i<r.length;i+=1)if(n[e+i]!==r.charCodeAt(i))return!1;return!0}function k(n,r){let e=r.length;if(e===0||n.length<e)return!1;n:for(let i=0;i+e<=n.length;i+=1){for(let o=0;o<e;o+=1)if(n[i+o]!==r.charCodeAt(o))continue n;return!0}return!1}function f(n){return{id:"video",sniff(r,e){if(d(r)!==void 0)return 2;if(e?.path!==void 0&&u(e.path)!==void 0)return 1;return 0},async convert(r,e){p(r);let i=a(r,e);if(i===void 0)throw x.unsupported(e?.path===void 0?"unrecognized file content: name the format explicitly":`unrecognized file content and extension: ${e.path}`);if(n===void 0)throw x.unsupported("video conversion");let o=await n({bytes:r,mime:i});return{markdown:o.endsWith(`
2
+ `)?o:`${o}
3
+ `}}}}var F=B([f()]);function S(n,r){return F(n,r)}export{f as video,S as toMarkdown};
@@ -0,0 +1,6 @@
1
+ import { type ConvertHint } from '@mdgate/core';
2
+ /**
3
+ * Convert a single file's bytes to Markdown with the video converter.
4
+ * `hint.path` is only a sniff hint; it is never read from disk.
5
+ */
6
+ export declare function toMarkdown(bytes: Uint8Array, hint?: ConvertHint): Promise<string>;
@@ -0,0 +1,6 @@
1
+ export type VideoMime = 'video/mp4' | 'video/quicktime' | 'video/webm' | 'video/x-matroska' | 'video/x-msvideo';
2
+ export type VideoInput = {
3
+ bytes: Uint8Array;
4
+ mime: VideoMime;
5
+ };
6
+ export type ConvertVideo = (input: VideoInput) => Promise<string>;
@@ -0,0 +1,3 @@
1
+ import type { Converter } from '@mdgate/core';
2
+ import type { ConvertVideo } from './types.js';
3
+ export declare function video(convertVideo?: ConvertVideo): Converter;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@mdgate/video",
3
+ "version": "0.5.0",
4
+ "description": "mdgate video converter",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "main": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*.js",
18
+ "dist/**/*.d.ts"
19
+ ],
20
+ "scripts": {
21
+ "build": "bun ../../scripts/build-package.ts",
22
+ "prepublishOnly": "bun run build"
23
+ },
24
+ "dependencies": {
25
+ "@mdgate/core": "0.5.0"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ },
33
+ "keywords": [
34
+ "mdgate",
35
+ "markdown",
36
+ "video"
37
+ ]
38
+ }