@mtillmann/chapters 0.1.2 → 0.1.3

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/dist/index.d.ts CHANGED
@@ -294,4 +294,4 @@ declare namespace util {
294
294
  export { util_Float as Float, util_Floats as Floats, util_Int as Int, util_Ints as Ints, util_NPTToSeconds as NPTToSeconds, util_enforceMilliseconds as enforceMilliseconds, util_escapeRegExpCharacters as escapeRegExpCharacters, util_formatBytes as formatBytes, util_hash as hash, util_indenter as indenter, util_secondsToNPT as secondsToNPT, util_secondsToTimestamp as secondsToTimestamp, util_stringToLines as stringToLines, util_timestampToSeconds as timestampToSeconds, util_toSeconds as toSeconds, util_zeroPad as zeroPad };
295
295
  }
296
296
 
297
- export { AppleChapters, AppleHLS, AutoFormat, ChaptersJson, FFMetadata, FFMpegInfo, MKVMergeSimple, MKVMergeXML, MP4Chaps, MatroskaXML, PodloveJson, PodloveSimpleChapters, PySceneDetect, Scenecut, ShutterEDL, util as Util, VorbisComment, WebVTT, Youtube };
297
+ export { AppleChapters, AppleHLS, AutoFormat, type Chapter, ChaptersJson, FFMetadata, FFMpegInfo, MKVMergeSimple, MKVMergeXML, MP4Chaps, MatroskaXML, type MediaItem, type MediaItemMeta, PodloveJson, PodloveSimpleChapters, PySceneDetect, Scenecut, ShutterEDL, util as Util, VorbisComment, WebVTT, Youtube };
package/dist/index.js CHANGED
@@ -762,6 +762,7 @@ var MKVMergeXML = class extends MatroskaXML {
762
762
  mimeType = "text/xml";
763
763
  chapterStringNodeName = "ChapterString";
764
764
  inputTimeToSeconds(string) {
765
+ string = string.replace(/\.(\d{3}).*$/, ".$1");
765
766
  return timestampToSeconds(string);
766
767
  }
767
768
  secondsToOutputTime(seconds) {
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "@mtillmann/chapters",
3
- "version": "0.1.2",
4
- "description": "library that manages and converts chapters of multiple formats",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "type": "module",
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "test": "jest",
13
- "build": "rimraf dist && tsup",
14
- "lint": "eslint src --ext .ts",
15
- "publishify": "npm run build && npm publish --access public"
16
- },
17
- "homepage": "https://github.com/Mtillmann/chapters",
18
- "author": "Martin Tillmann<mtillmann@gmail.com>",
19
- "bugs": {
20
- "url": "https://github.com/Mtillmann/chapters/issues"
21
- },
22
- "keywords": [
23
- "podcast",
24
- "ffmpeg",
25
- "chapters",
26
- "youtube",
27
- "mkvmerge",
28
- "matroska",
29
- "webvtt",
30
- "pyscenedetect",
31
- "vorbis",
32
- "apple-chapters",
33
- "podlove",
34
- "podcast-chapters",
35
- "edl",
36
- "hls",
37
- "scenecut"],
38
- "license": "MIT",
39
- "devDependencies": {
40
- "@babel/core": "^7.24.0",
41
- "@babel/preset-env": "^7.24.0",
42
- "@types/jest": "^29.5.12",
43
- "@types/jsdom": "^21.1.6",
44
- "@typescript-eslint/eslint-plugin": "^6.21.0",
45
- "babel-jest": "^29.7.0",
46
- "eslint": "^8.57.0",
47
- "eslint-config-standard-with-typescript": "^43.0.1",
48
- "eslint-plugin-import": "^2.29.1",
49
- "eslint-plugin-n": "^16.6.2",
50
- "eslint-plugin-promise": "^6.1.1",
51
- "jest": "^29.7.0",
52
- "jest-environment-jsdom": "^29.7.0",
53
- "rimraf": "^5.0.5",
54
- "ts-jest": "^29.1.2",
55
- "tsup": "^8.0.2",
56
- "typescript": "^5.3.3"
57
- },
58
- "dependencies": {
59
- "filenamify": "^6.0.0",
60
- "jsdom": "^24.0.0"
61
- }
62
- }
1
+ {
2
+ "name": "@mtillmann/chapters",
3
+ "version": "0.1.3",
4
+ "description": "library that manages and converts chapters of multiple formats",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "test": "jest",
13
+ "build": "rimraf dist && tsup",
14
+ "lint": "eslint src --ext .ts",
15
+ "publishify": "npm run build && npm publish --access public"
16
+ },
17
+ "homepage": "https://github.com/Mtillmann/chapters",
18
+ "author": "Martin Tillmann<mtillmann@gmail.com>",
19
+ "bugs": {
20
+ "url": "https://github.com/Mtillmann/chapters/issues"
21
+ },
22
+ "keywords": [
23
+ "podcast",
24
+ "ffmpeg",
25
+ "chapters",
26
+ "youtube",
27
+ "mkvmerge",
28
+ "matroska",
29
+ "webvtt",
30
+ "pyscenedetect",
31
+ "vorbis",
32
+ "apple-chapters",
33
+ "podlove",
34
+ "podcast-chapters",
35
+ "edl",
36
+ "hls",
37
+ "scenecut"],
38
+ "license": "MIT",
39
+ "devDependencies": {
40
+ "@babel/core": "^7.24.0",
41
+ "@babel/preset-env": "^7.24.0",
42
+ "@types/jest": "^29.5.12",
43
+ "@types/jsdom": "^21.1.6",
44
+ "@typescript-eslint/eslint-plugin": "^6.21.0",
45
+ "babel-jest": "^29.7.0",
46
+ "eslint": "^8.57.0",
47
+ "eslint-config-standard-with-typescript": "^43.0.1",
48
+ "eslint-plugin-import": "^2.29.1",
49
+ "eslint-plugin-n": "^16.6.2",
50
+ "eslint-plugin-promise": "^6.1.1",
51
+ "jest": "^29.7.0",
52
+ "jest-environment-jsdom": "^29.7.0",
53
+ "rimraf": "^5.0.5",
54
+ "ts-jest": "^29.1.2",
55
+ "tsup": "^8.0.2",
56
+ "typescript": "^5.3.3"
57
+ },
58
+ "dependencies": {
59
+ "filenamify": "^6.0.0",
60
+ "jsdom": "^24.0.0"
61
+ }
62
+ }
package/readme.md CHANGED
@@ -1,196 +1,196 @@
1
- ![tests](https://github.com/Mtillmann/chapters/actions/workflows/tests.yaml/badge.svg?event=push)
2
-
3
- [![npm version](https://badge.fury.io/js/@mtillmann%2Fchapters.svg)](https://badge.fury.io/js/@mtillmann%2Fchapters)
4
-
5
- # chapters
6
-
7
- This is the core library of the [chaptertool](https://github.com/Mtillmann/chaptertool) project and provides the functionality to handle the formats below.
8
-
9
- [Click here to open the web GUI](https://mtillmann.github.io/chaptertool) or go install chaptertool locally for CLI use.
10
-
11
- ## Supported formats
12
-
13
- | class | description | key | ext | info |
14
- |-------------------------------------|------------------------------|----------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
15
- | ChaptersJson | Podcasting 2.0 Chapters | chaptersjson | `json` | [spec](https://github.com/Podcastindex-org/podcast-namespace/blob/main/chapters/jsonChapters.md) |
16
- | FFMetadata | FFMetadata | ffmpegdata | `txt` | [spec](https://ffmpeg.org/ffmpeg-formats.html#Metadata-1) |
17
- | MatroskaXML | Matroska XML chapters | matroskaxml | `xml` | [spec](https://www.matroska.org/technical/chapters.html) |
18
- | MKVMergeXML | MKVToolNix mkvmerge XML | mkvmergexml | `xml` | [spec](https://mkvtoolnix.download/doc/mkvmerge.html#mkvmerge.chapters) |
19
- | MKVMergeSimple | MKVToolNix mkvmerge _simple_ | mkvmergesimple | `txt` | [spec](https://mkvtoolnix.download/doc/mkvmerge.html#mkvmerge.chapters) |
20
- | WebVTT | WebVTT Chapters | webvtt | `vtt` | [spec](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) |
21
- | Youtube | Youtube Chapter Syntax | youtube | `txt` | |
22
- | FFMpegInfo | FFMpegInfo | ffmpeginfo | `txt` | read only, used internally |
23
- | PySceneDetect | PySceneDetect | pyscenedetect | `csv` | [project home](https://github.com/Breakthrough/PySceneDetect) |
24
- | VorbisComment | Vorbis Comment Format | vorbiscomment | `txt` | [spec](https://wiki.xiph.org/Chapter_Extension) |
25
- | AppleChapters | "Apple Chapters" | applechapters | `xml` | [source](https://github.com/rigaya/NVEnc/blob/master/NVEncC_Options.en.md#--chapter-string:~:text=CHAPTER03NAME%3Dchapter%2D3-,apple%20format,-(should%20be%20in)) |
26
- | ShutterEDL | Shutter EDL | edl | `edl` | [source](https://github.com/paulpacifico/shutter-encoder/blob/f3d6bb6dfcd629861a0b0a50113bf4b062e1ba17/src/application/SceneDetection.java) |
27
- | PodloveSimpleChapters | Podlove Simple Chapters | psc | `xml` | [spec](https://podlove.org/simple-chapters/) |
28
- | PodloveJson | Podlove Simple Chapters JSON | podlovejson | `json` | [source](https://github.com/podlove/chapters#:~:text=org/%3E-,Encode%20to%20JSON,-iex%3E%20Chapters) |
29
- | MP4Chaps | MP4Chaps | mp4chaps | `txt` | [source](https://github.com/podlove/chapters#:~:text=%3Achapters%3E-,Encode%20to%20mp4chaps,-iex%3E%20Chapters) |
30
- | AppleHLS | Apple HLS Chapters | applehls | `json` | [spec](https://developer.apple.com/documentation/http-live-streaming/providing-javascript-object-notation-json-chapters), partial support |
31
- | Scenecut | Scenecut format | scenecut | `json` | [source](https://github.com/slhck/scenecut-extractor#:~:text=cuts%20in%20JSON-,format,-%3A) |
32
-
33
- ## Installation
34
-
35
- `npm i @mtillmann/chapters`
36
-
37
- ## Usage
38
-
39
- ```javascript
40
- import { ChaptersJson } from '@mtillmann/chapters';
41
-
42
- const chapters = new ChaptersJson()
43
- chapters.add({ startTime: 0, title: 'Intro' })
44
- chapters.add({ startTime: 30, title: 'Some Topic' })
45
- const json = chapters.toString()
46
- ```
47
-
48
- ## Autoformat
49
-
50
- `Autoformat` is a helper that can be used to automatically detect the format of a given input and return the corresponding class,
51
- key or a new instance of the detected class. It also provides a method to convert the input to a specific format.
52
-
53
- ```javascript
54
- import { Autoformat } from '@mtillmann/chapters'
55
- import { WebVTT } from '@mtillmann/chapters'
56
-
57
- const content = '<podcasting 2.0 chapters.json>...'
58
- const instance = Autoformat.detect(content) // returns an instance of ChaptersJson
59
- const instance2 = Autoformat.from(content) // returns an instance of ChaptersJson
60
-
61
- const key = Autoformat.detect(content, 'key') // returns 'chaptersjson'
62
- const className = Autoformat.detect(content, 'class') // returns ChaptersJson
63
-
64
- const webVttString = 'WEBVTT...';
65
-
66
- const autodetectedWebVtt = Autoformat.detect(webVttString) // returns an instance of WebVTT
67
-
68
- const fail = Autoformat.as('chaptersjson', webVttString) // throws an error
69
-
70
- const vtt = Autoformat.as('webvtt', webVttString) // returns an instance of WebVTT
71
- const vtt2 = Autoformat.as(WebVTT, webVttString) // returns an instance of WebVTT
72
- ```
73
-
74
- ## API
75
-
76
- All formats support the following methods:
77
-
78
- ### `constructor (duration: number = 3600)`
79
-
80
- Creates a new instance of the class, optionally with a duration in seconds.
81
-
82
- ```javascript
83
- const chapters = (new ChaptersJson(3600)).from(input)
84
- ```
85
-
86
- > the constructor will not accept any input due to javascript's order of initialization which prevents the parse method
87
- > from having access to cerain locally defined properties and methods.
88
-
89
- ### `static create (input?: string | MediaItem): MediaItem`
90
-
91
- Creates a new media item. This is the suggested way to create a media item from a string:
92
-
93
- ```javascript
94
- const chapters = MatroskaXML.create(input)
95
- // chapters is now an instance of MatroskaXML
96
-
97
- const chapterString = WebVTT.create(chapters).toString()
98
- // chapterString is now a string representation of the chapters
99
- ```
100
-
101
- ### `from (input?: string | MediaItem): MediaItem`
102
-
103
- Populates the media item's chapters from the given input.
104
-
105
- ### `to (className: any): MediaItem`
106
-
107
- Converts the media item to another format.
108
-
109
- ### `add (chapter: Chapter): void`
110
-
111
- Adds a chapter.
112
-
113
- ### `addChapterAt (index: number, chapter: object = {}): number`
114
-
115
- Adds a chapter at the given index.
116
-
117
- ### `addChapterAtTime (time: number | string, chapter: object = {}): boolean`
118
-
119
- Adds a chapter at the given time.
120
-
121
- ### `remove (index: number): void`
122
-
123
- Removes the chapter at the given index.
124
-
125
- ### `bump (keepDuration: boolean = false): void`
126
-
127
- Updates the chapters and duration. Called automatically after adding or removing chapters.
128
-
129
- ### `endTime (index: number): number`
130
-
131
- Returns the end time for the chapter at the given index.
132
-
133
- ### `expandFirstToStart (): void`
134
-
135
- Expands the first chapter to start at 0.
136
-
137
- ### `applyChapterMinLength (seconds: number): object`
138
-
139
- Applies a minimum length to the chapters.
140
-
141
- ### `chapterExistsAtStartTime (time: number): boolean`
142
-
143
- Checks if a chapter exists at the given start time.
144
-
145
- ### `updateChapterStartTime (index: number, startTime: number | string): number | 'timeInUse'`
146
-
147
- Updates the start time for the chapter at the given index.
148
-
149
- ### `chapterIndexFromStartTime (startTime: number | string): number`
150
-
151
- Returns the index of the chapter with the given start time.
152
-
153
- ### `chapterIndexFromTime (time: number | string): null | number`
154
-
155
- Returns the index of the chapter at the given time.
156
-
157
- ### `toString([pretty: boolean][, options: object]): string`
158
-
159
- Convert the chapters to a string.
160
- If `pretty` is `true`, the output will be formatted for better readability. Only supported by `json` and `xml` formats.
161
- Some formats support additional options:
162
-
163
- #### ChapterJson toString() options
164
-
165
- | option | type | default | description |
166
- |---------------------|-----------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
167
- | `imagePrefix` | `string` | `''` | Prefix for image URLs |
168
- | `writeRedundantToc` | `boolean` | `false` | Write [redundant](https://github.com/Podcastindex-org/podcast-namespace/blob/main/chapters/jsonChapters.md#:~:text=or%20not%20present%20at%20all) TOC attributes |
169
- | `writeEndTimes` | `boolean` | `false` | Write end times |
170
-
171
- #### AppleChapters toString() options
172
-
173
- | option | type | default | description |
174
- |-----------------|-----------|---------|-----------------------------------------------------------|
175
- | `acUseTextAttr` | `boolean` | `false` | When set, the text-attribute will be used instead of node textContent |
176
-
177
- #### PySceneDetect toString() options
178
-
179
- | option | type | default | description |
180
- |--------------------|----------|----------|------------------------------------------|
181
- | `psdFramerate` | `number` | `23.976` | Framerate of the video file |
182
- | `psdOmitTimecodes` | `boolen` | `false` | When set, the first line will be omitted |
183
-
184
- #### Scenecut toString() options
185
-
186
- | option | type | default | description |
187
- |--------|----------|---------|-----------------------------|
188
- | `frameRate` | `number` | `30` | Framerate of the video file |
189
- | `ptsScale` | `number` | `1` | PTS scale (See below) |
190
- | `score` | `number` | `0.5` | Score threshold |
191
-
192
- When asked about the `ptsScale`-value, ChatGPT said:
193
- > The number "1001" in the context of video processing and multimedia, especially in relation to frame rates and timecodes, is often associated with the NTSC color system used in North America and Japan.
194
- > In this system, the frame rate is often described as "29.97 frames per second", but it's technically 30000/1001 frames per second, which is approximately 29.97 but not exactly. This is known as a "drop frame" rate, and the "1001" comes from this fractional frame rate.
195
-
196
- When you use `1` the output `pts` will be the same as the `frame` number. When you use `1001` the output `pts` will be the same as the `frame` number multiplied by `1001`.
1
+ ![tests](https://github.com/Mtillmann/chapters/actions/workflows/tests.yaml/badge.svg?event=push)
2
+
3
+ [![npm version](https://badge.fury.io/js/@mtillmann%2Fchapters.svg)](https://badge.fury.io/js/@mtillmann%2Fchapters)
4
+
5
+ # chapters
6
+
7
+ This is the core library of the [chaptertool](https://github.com/Mtillmann/chaptertool) project and provides the functionality to handle the formats below.
8
+
9
+ [Click here to open the web GUI](https://mtillmann.github.io/chaptertool) or go install chaptertool locally for CLI use.
10
+
11
+ ## Supported formats
12
+
13
+ | class | description | key | ext | info |
14
+ |-------------------------------------|------------------------------|----------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
15
+ | ChaptersJson | Podcasting 2.0 Chapters | chaptersjson | `json` | [spec](https://github.com/Podcastindex-org/podcast-namespace/blob/main/chapters/jsonChapters.md) |
16
+ | FFMetadata | FFMetadata | ffmpegdata | `txt` | [spec](https://ffmpeg.org/ffmpeg-formats.html#Metadata-1) |
17
+ | MatroskaXML | Matroska XML chapters | matroskaxml | `xml` | [spec](https://www.matroska.org/technical/chapters.html) |
18
+ | MKVMergeXML | MKVToolNix mkvmerge XML | mkvmergexml | `xml` | [spec](https://mkvtoolnix.download/doc/mkvmerge.html#mkvmerge.chapters) |
19
+ | MKVMergeSimple | MKVToolNix mkvmerge _simple_ | mkvmergesimple | `txt` | [spec](https://mkvtoolnix.download/doc/mkvmerge.html#mkvmerge.chapters) |
20
+ | WebVTT | WebVTT Chapters | webvtt | `vtt` | [spec](https://developer.mozilla.org/en-US/docs/Web/API/WebVTT_API) |
21
+ | Youtube | Youtube Chapter Syntax | youtube | `txt` | |
22
+ | FFMpegInfo | FFMpegInfo | ffmpeginfo | `txt` | read only, used internally |
23
+ | PySceneDetect | PySceneDetect | pyscenedetect | `csv` | [project home](https://github.com/Breakthrough/PySceneDetect) |
24
+ | VorbisComment | Vorbis Comment Format | vorbiscomment | `txt` | [spec](https://wiki.xiph.org/Chapter_Extension) |
25
+ | AppleChapters | "Apple Chapters" | applechapters | `xml` | [source](https://github.com/rigaya/NVEnc/blob/master/NVEncC_Options.en.md#--chapter-string:~:text=CHAPTER03NAME%3Dchapter%2D3-,apple%20format,-(should%20be%20in)) |
26
+ | ShutterEDL | Shutter EDL | edl | `edl` | [source](https://github.com/paulpacifico/shutter-encoder/blob/f3d6bb6dfcd629861a0b0a50113bf4b062e1ba17/src/application/SceneDetection.java) |
27
+ | PodloveSimpleChapters | Podlove Simple Chapters | psc | `xml` | [spec](https://podlove.org/simple-chapters/) |
28
+ | PodloveJson | Podlove Simple Chapters JSON | podlovejson | `json` | [source](https://github.com/podlove/chapters#:~:text=org/%3E-,Encode%20to%20JSON,-iex%3E%20Chapters) |
29
+ | MP4Chaps | MP4Chaps | mp4chaps | `txt` | [source](https://github.com/podlove/chapters#:~:text=%3Achapters%3E-,Encode%20to%20mp4chaps,-iex%3E%20Chapters) |
30
+ | AppleHLS | Apple HLS Chapters | applehls | `json` | [spec](https://developer.apple.com/documentation/http-live-streaming/providing-javascript-object-notation-json-chapters), partial support |
31
+ | Scenecut | Scenecut format | scenecut | `json` | [source](https://github.com/slhck/scenecut-extractor#:~:text=cuts%20in%20JSON-,format,-%3A) |
32
+
33
+ ## Installation
34
+
35
+ `npm i @mtillmann/chapters`
36
+
37
+ ## Usage
38
+
39
+ ```javascript
40
+ import { ChaptersJson } from '@mtillmann/chapters';
41
+
42
+ const chapters = new ChaptersJson()
43
+ chapters.add({ startTime: 0, title: 'Intro' })
44
+ chapters.add({ startTime: 30, title: 'Some Topic' })
45
+ const json = chapters.toString()
46
+ ```
47
+
48
+ ## Autoformat
49
+
50
+ `Autoformat` is a helper that can be used to automatically detect the format of a given input and return the corresponding class,
51
+ key or a new instance of the detected class. It also provides a method to convert the input to a specific format.
52
+
53
+ ```javascript
54
+ import { Autoformat } from '@mtillmann/chapters'
55
+ import { WebVTT } from '@mtillmann/chapters'
56
+
57
+ const content = '<podcasting 2.0 chapters.json>...'
58
+ const instance = Autoformat.detect(content) // returns an instance of ChaptersJson
59
+ const instance2 = Autoformat.from(content) // returns an instance of ChaptersJson
60
+
61
+ const key = Autoformat.detect(content, 'key') // returns 'chaptersjson'
62
+ const className = Autoformat.detect(content, 'class') // returns ChaptersJson
63
+
64
+ const webVttString = 'WEBVTT...';
65
+
66
+ const autodetectedWebVtt = Autoformat.detect(webVttString) // returns an instance of WebVTT
67
+
68
+ const fail = Autoformat.as('chaptersjson', webVttString) // throws an error
69
+
70
+ const vtt = Autoformat.as('webvtt', webVttString) // returns an instance of WebVTT
71
+ const vtt2 = Autoformat.as(WebVTT, webVttString) // returns an instance of WebVTT
72
+ ```
73
+
74
+ ## API
75
+
76
+ All formats support the following methods:
77
+
78
+ ### `constructor (duration: number = 3600)`
79
+
80
+ Creates a new instance of the class, optionally with a duration in seconds.
81
+
82
+ ```javascript
83
+ const chapters = (new ChaptersJson(3600)).from(input)
84
+ ```
85
+
86
+ > the constructor will not accept any input due to javascript's order of initialization which prevents the parse method
87
+ > from having access to cerain locally defined properties and methods.
88
+
89
+ ### `static create (input?: string | MediaItem): MediaItem`
90
+
91
+ Creates a new media item. This is the suggested way to create a media item from a string:
92
+
93
+ ```javascript
94
+ const chapters = MatroskaXML.create(input)
95
+ // chapters is now an instance of MatroskaXML
96
+
97
+ const chapterString = WebVTT.create(chapters).toString()
98
+ // chapterString is now a string representation of the chapters
99
+ ```
100
+
101
+ ### `from (input?: string | MediaItem): MediaItem`
102
+
103
+ Populates the media item's chapters from the given input.
104
+
105
+ ### `to (className: any): MediaItem`
106
+
107
+ Converts the media item to another format.
108
+
109
+ ### `add (chapter: Chapter): void`
110
+
111
+ Adds a chapter.
112
+
113
+ ### `addChapterAt (index: number, chapter: object = {}): number`
114
+
115
+ Adds a chapter at the given index.
116
+
117
+ ### `addChapterAtTime (time: number | string, chapter: object = {}): boolean`
118
+
119
+ Adds a chapter at the given time.
120
+
121
+ ### `remove (index: number): void`
122
+
123
+ Removes the chapter at the given index.
124
+
125
+ ### `bump (keepDuration: boolean = false): void`
126
+
127
+ Updates the chapters and duration. Called automatically after adding or removing chapters.
128
+
129
+ ### `endTime (index: number): number`
130
+
131
+ Returns the end time for the chapter at the given index.
132
+
133
+ ### `expandFirstToStart (): void`
134
+
135
+ Expands the first chapter to start at 0.
136
+
137
+ ### `applyChapterMinLength (seconds: number): object`
138
+
139
+ Applies a minimum length to the chapters.
140
+
141
+ ### `chapterExistsAtStartTime (time: number): boolean`
142
+
143
+ Checks if a chapter exists at the given start time.
144
+
145
+ ### `updateChapterStartTime (index: number, startTime: number | string): number | 'timeInUse'`
146
+
147
+ Updates the start time for the chapter at the given index.
148
+
149
+ ### `chapterIndexFromStartTime (startTime: number | string): number`
150
+
151
+ Returns the index of the chapter with the given start time.
152
+
153
+ ### `chapterIndexFromTime (time: number | string): null | number`
154
+
155
+ Returns the index of the chapter at the given time.
156
+
157
+ ### `toString([pretty: boolean][, options: object]): string`
158
+
159
+ Convert the chapters to a string.
160
+ If `pretty` is `true`, the output will be formatted for better readability. Only supported by `json` and `xml` formats.
161
+ Some formats support additional options:
162
+
163
+ #### ChapterJson toString() options
164
+
165
+ | option | type | default | description |
166
+ |---------------------|-----------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
167
+ | `imagePrefix` | `string` | `''` | Prefix for image URLs |
168
+ | `writeRedundantToc` | `boolean` | `false` | Write [redundant](https://github.com/Podcastindex-org/podcast-namespace/blob/main/chapters/jsonChapters.md#:~:text=or%20not%20present%20at%20all) TOC attributes |
169
+ | `writeEndTimes` | `boolean` | `false` | Write end times |
170
+
171
+ #### AppleChapters toString() options
172
+
173
+ | option | type | default | description |
174
+ |-----------------|-----------|---------|-----------------------------------------------------------|
175
+ | `acUseTextAttr` | `boolean` | `false` | When set, the text-attribute will be used instead of node textContent |
176
+
177
+ #### PySceneDetect toString() options
178
+
179
+ | option | type | default | description |
180
+ |--------------------|----------|----------|------------------------------------------|
181
+ | `psdFramerate` | `number` | `23.976` | Framerate of the video file |
182
+ | `psdOmitTimecodes` | `boolen` | `false` | When set, the first line will be omitted |
183
+
184
+ #### Scenecut toString() options
185
+
186
+ | option | type | default | description |
187
+ |--------|----------|---------|-----------------------------|
188
+ | `frameRate` | `number` | `30` | Framerate of the video file |
189
+ | `ptsScale` | `number` | `1` | PTS scale (See below) |
190
+ | `score` | `number` | `0.5` | Score threshold |
191
+
192
+ When asked about the `ptsScale`-value, ChatGPT said:
193
+ > The number "1001" in the context of video processing and multimedia, especially in relation to frame rates and timecodes, is often associated with the NTSC color system used in North America and Japan.
194
+ > In this system, the frame rate is often described as "29.97 frames per second", but it's technically 30000/1001 frames per second, which is approximately 29.97 but not exactly. This is known as a "drop frame" rate, and the "1001" comes from this fractional frame rate.
195
+
196
+ When you use `1` the output `pts` will be the same as the `frame` number. When you use `1001` the output `pts` will be the same as the `frame` number multiplied by `1001`.