Spaces:
Sleeping
Sleeping
| import { FPS } from "./enums"; | |
| import { TimeCode, createTimeCode } from "./timecode"; | |
| import { RichText, createRichText } from "./text"; | |
| import { Subtitle, createSubtitle } from "./subtitle"; | |
| import { SubtitleTrack, createSubtitleTrack, LanguageData, createLanguageData } from "./track"; | |
| export interface DocumentInfo { | |
| originalTitle: string; | |
| originalEpisodeTitle: string; | |
| translatedTitle: string; | |
| translatedEpisodeTitle: string; | |
| referenceNumber: string; | |
| productionNumber: string; | |
| revisionNumber: string; | |
| productionYear: string; | |
| sourceLanguage: LanguageData; | |
| targetLanguage: LanguageData; | |
| fps: FPS; | |
| fpsString: string; | |
| venue: string; | |
| format: number; | |
| comments: RichText; | |
| timecodeStart: TimeCode; | |
| timecodeEnd: TimeCode; | |
| fileStatus: string; | |
| volumeNo: string; | |
| seasonNo: string; | |
| discNo: string; | |
| episodeNo: string; | |
| translator: string; | |
| client: string; | |
| profileName: string; | |
| } | |
| export function createDocumentInfo(partial?: Partial<DocumentInfo>): DocumentInfo { | |
| return { | |
| originalTitle: "", | |
| originalEpisodeTitle: "", | |
| translatedTitle: "", | |
| translatedEpisodeTitle: "", | |
| referenceNumber: "", | |
| productionNumber: "", | |
| revisionNumber: "", | |
| productionYear: "", | |
| sourceLanguage: createLanguageData(), | |
| targetLanguage: createLanguageData(), | |
| fps: FPS.PAL, | |
| fpsString: "25", | |
| venue: "", | |
| format: 0, | |
| comments: createRichText(), | |
| timecodeStart: createTimeCode(), | |
| timecodeEnd: createTimeCode(), | |
| fileStatus: "", | |
| volumeNo: "", | |
| seasonNo: "", | |
| discNo: "", | |
| episodeNo: "", | |
| translator: "", | |
| client: "", | |
| profileName: "", | |
| ...partial, | |
| }; | |
| } | |
| export interface BreakPoint { | |
| timecode: TimeCode; | |
| type: number; | |
| } | |
| export interface LinkedVideoFile { | |
| fileName: string; | |
| firstTC: TimeCode; | |
| duration: TimeCode; | |
| } | |
| export interface GTSDocument { | |
| info: DocumentInfo; | |
| tracks: SubtitleTrack[]; | |
| breaks: BreakPoint[]; | |
| videoFiles: LinkedVideoFile[]; | |
| zeroTitle: Subtitle; | |
| fileVersion: number; | |
| sourceFormat: string; | |
| } | |
| export function createGTSDocument(partial?: Partial<GTSDocument>): GTSDocument { | |
| return { | |
| info: createDocumentInfo(), | |
| tracks: [createSubtitleTrack()], | |
| breaks: [], | |
| videoFiles: [], | |
| zeroTitle: createSubtitle(), | |
| fileVersion: 0, | |
| sourceFormat: "", | |
| ...partial, | |
| }; | |
| } | |
| /** Get the primary (first) track's subtitles */ | |
| export function getSubtitles(doc: GTSDocument): Subtitle[] { | |
| return doc.tracks[0]?.subtitles ?? []; | |
| } | |
| /** Total subtitle count across all tracks */ | |
| export function totalSubtitleCount(doc: GTSDocument): number { | |
| return doc.tracks.reduce((sum, t) => sum + t.subtitles.length, 0); | |
| } | |