From bba9a3cb8648ca865ca0c32565e66b48b9ab6f5a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Wed, 21 Jul 2021 20:13:59 +0200 Subject: project file beginnings --- project.ts | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 project.ts (limited to 'project.ts') diff --git a/project.ts b/project.ts new file mode 100644 index 0000000..ff5f941 --- /dev/null +++ b/project.ts @@ -0,0 +1,93 @@ +import { MediaInfo as Mediainfo, ResultObject } from 'mediainfo.js/dist/types'; +import JSZip from 'jszip'; +import { TimedVideoPlayer } from './pages/present'; + +// garbage garbage garbage +declare var MediaInfo: () => Promise; + +const filext = '.prspr'; + +export class LocalVideo { + source: ArrayBuffer; + fileext: string; + mimetype: `video/${string}`; + type: string; + + framerate: number; + framecount: number; + + constructor() { + this.type = 'local'; + } + + async load(data: ArrayBuffer) { + this.source = data; + var mediainfo = await MediaInfo(); + var result = await mediainfo.analyzeData( + () => this.source.byteLength, + (size, offset) => new Uint8Array(this.source.slice(offset, offset + size)), + ) as ResultObject; + + var meta = result.media.track[0] as unknown as { + FrameCount: string; + FrameRate: string; + }; + + this.framecount = Number(meta.FrameCount); + this.framerate = Number(meta.FrameRate); + } + + save(dir: JSZip) { + dir.file('video.' + this.fileext, this.source); + } +} + +export type VideoSources = [LocalVideo]; + +export default class { + version: string; + zip: JSZip; + project: TimedVideoPlayer['timeline']; + video: VideoSources[number]; + + constructor() { + this.version = '0.1.0'; + this.zip = new JSZip(); + } + + loadProjectFile(data: Blob) { + this.zip = new JSZip(data); + } + + async downloadProjectFile() { + var zip = await this.zip.generateAsync({ type: 'blob' }); + var blob = new Blob([zip], { type: 'application/octet-stream' }); + var a = document.createElement('a'); + a.href = URL.createObjectURL(blob); + a.download = this.project.name + .toLowerCase() + .replace(/\s/g, '-') + filext; + a.click(); + } + + loadProject(project: TimedVideoPlayer['timeline']) { + this.project = project; + } + + saveProject() { + var meta = this.zip.folder('meta'); + meta.file('version', this.version); + meta.file('name', this.project.name); + + var settings = this.zip.folder('settings'); + settings.file('controlType', this.project.settings.controlType); + + var source = this.zip.folder('source'); + this.video.save(source); + + this.zip.file('slides', JSON.stringify(this.project.slides, null, 4)); + } + + openProject() { + } +} -- cgit v1.2.3