This package has been deprecated

Author message:

See subtitle-convert for a maintained alternative.

samits
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

SamiTS

SamiTS converts Microsoft SAMI-formatted subtitle files to more popular WebVTT and SubRip ones, thus allows browsers and players to read the most popular subtitle format in South Korea.

SamiTS also supports styles by collecting SAMI styling tags to make a standard CSS stylesheet.

Get a sneak peak with a sample here.

Install with bower: bower install samits

Example

Simple use

var player = document.getElementById("player");
var input = document.getElementById("loadVideo");
 
var track = document.createElement("track");
SamiTS.createWebVTT(input.files[0], { createStyleElement: true })
  .then(function (result) {
    track.src = URL.createObjectURL(new Blob([result.subtitle], { type: "text/vtt" }));
    document.head.appendChild(result.stylesheet);
  });

More advanced

SamiTS.createSamiDocument(input.files[0])
  .then(function (sami) {
    sami.delay(300);
    return SamiTS.createWebVTT(sami, { createStyleElement: true })
  })
  .then(function (result) {
    track.src = URL.createObjectURL(new Blob([result.subtitle], { type: "text/vtt" }));
    document.head.appendChild(result.stylesheet);
  });;

API

declare module SamiTS {
  interface WebVTTWriterOptions {
    createStyleElement?: boolean;
    disableDefaultStyle?: boolean;
    /** The default value is "video". */
    selector?: string;
  }
  interface SubRipWriterOptions {
    useTextStyles?: boolean
  }
  interface SamiTSResult {
    subtitle: string;
    stylesheet?: HTMLStyleElement;
  }
  
  function createWebVTT(input: string, options?: WebVTTWriterOptions): Promise<SamiTSResult>;
  function createWebVTT(input: Blob, options?: WebVTTWriterOptions): Promise<SamiTSResult>;
  function createWebVTT(input: SAMIDocument, options?: WebVTTWriterOptions): Promise<SamiTSResult>;
  
  function createSubRip(input: string, options?: SubRipWriterOptions): Promise<SamiTSResult>;
  function createSubRip(input: Blob, options?: SubRipWriterOptions): Promise<SamiTSResult>;
  function createSubRip(input: SAMIDocument, options?: SubRipWriterOptions): Promise<SamiTSResult>;
  
  function createSAMIDocument(input: string): Promise<SAMIDocument>;
  function createSAMIDocument(input: Blob): Promise<SAMIDocument>;
}
 
// More advanced SAMI manipulation before any conversion
declare module SamiTS {
    interface SAMILanguage {
        cssClass: string;
        displayName: string;
        code: string;
    }
    interface SAMIDocumentDictionary {
        [key: string]: SAMIDocument;
    }
    
    class SAMIDocument {
        public languages: SAMILanguage[];
        public splitByLanguage(): SAMIDocumentDictionary;
        public delay(increment: number): void;
    }
}

Development?

The following Node.js packages are used to test SamiTS:

Package Sidebar

Install

npm i samits

Weekly Downloads

0

Version

1.2.0

License

ISC

Unpacked Size

95.2 kB

Total Files

6

Last publish

Collaborators

  • saschanaz