@langchain/community
Version:
Third-party integrations for LangChain.js
1 lines • 2.21 kB
Source Map (JSON)
{"version":3,"file":"srt.cjs","names":["TextLoader","filePathOrBlob: string | Blob","raw: string","srtParser2"],"sources":["../../../src/document_loaders/fs/srt.ts"],"sourcesContent":["import srtParser2 from \"srt-parser-2\";\nimport { TextLoader } from \"@langchain/classic/document_loaders/fs/text\";\n\n/**\n * A class that extends the `TextLoader` class. It represents a document\n * loader that loads documents from SRT (SubRip) subtitle files. It has a\n * constructor that takes a `filePathOrBlob` parameter representing the\n * path to the SRT file or a `Blob` object. The `parse()` method is\n * implemented to parse the SRT file and extract the text content of each\n * subtitle.\n * @example\n * ```typescript\n * const loader = new SRTLoader(\"path/to/file.srt\");\n * const docs = await loader.load();\n * console.log({ docs });\n * ```\n */\nexport class SRTLoader extends TextLoader {\n constructor(filePathOrBlob: string | Blob) {\n super(filePathOrBlob);\n }\n\n /**\n * A protected method that takes a `raw` string as a parameter and returns\n * a promise that resolves to an array of strings. It parses the raw SRT\n * string using the `SRTParser2` class from the `srt-parser-2` module. It\n * retrieves the subtitle objects from the parsed SRT data and extracts\n * the text content from each subtitle object. It filters out any empty\n * text content and joins the non-empty text content with a space\n * separator.\n * @param raw The raw SRT string to be parsed.\n * @returns A promise that resolves to an array of strings representing the text content of each subtitle.\n */\n protected async parse(raw: string): Promise<string[]> {\n // eslint-disable-next-line new-cap\n const parser = new srtParser2();\n const srts = parser.fromSrt(raw);\n return [\n srts\n .map((srt) => srt.text)\n .filter(Boolean)\n .join(\" \"),\n ];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiBA,IAAa,YAAb,cAA+BA,wDAAW;CACxC,YAAYC,gBAA+B;EACzC,MAAM,eAAe;CACtB;;;;;;;;;;;;CAaD,MAAgB,MAAMC,KAAgC;EAEpD,MAAM,SAAS,IAAIC;EACnB,MAAM,OAAO,OAAO,QAAQ,IAAI;AAChC,SAAO,CACL,KACG,IAAI,CAAC,QAAQ,IAAI,KAAK,CACtB,OAAO,QAAQ,CACf,KAAK,IAAI,AACb;CACF;AACF"}