Skip to content

Commit

Permalink
bump version to 0.1.3, update MKVMergeXML to handle timestamp precisi…
Browse files Browse the repository at this point in the history
…on, and add tests for chaptertool issue #18
  • Loading branch information
Mtillmann committed Jan 11, 2025
1 parent a264706 commit e4f2faf
Showing 5 changed files with 162 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mtillmann/chapters",
"version": "0.1.2",
"version": "0.1.3",
"description": "library that manages and converts chapters of multiple formats",
"main": "dist/index.js",
"types": "dist/index.d.ts",
1 change: 1 addition & 0 deletions src/Formats/MKVMergeXML.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ export class MKVMergeXML extends MatroskaXML {
chapterStringNodeName = 'ChapterString'

inputTimeToSeconds (string: string): number {
string = string.replace(/\.(\d{3}).*$/, '.$1')
return timestampToSeconds(string)
}

10 changes: 10 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,10 @@ import { WebVTT } from './Formats/WebVTT'
import { Youtube } from './Formats/Youtube'
import * as Util from './util'

import { MediaItem } from './Types/MediaItem'
import { Chapter } from './Types/Chapter'
import { MediaItemMeta } from './Types/MediaItemMeta'

export {
AutoFormat,
AppleChapters,
@@ -39,3 +43,9 @@ export {
Youtube,
Util
}

export type {
MediaItem,
Chapter,
MediaItemMeta
}
31 changes: 31 additions & 0 deletions tests/format_mkvmergexml-chaptertool-issue-18.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import {readFileSync} from "fs";
import {sep} from "path";
import {MKVMergeXML} from "../src/Formats/MKVMergeXML";

describe('MKVMergeXML Format Handler --- chaptertool issue #18', () => {


const content = readFileSync(module.path + sep + 'samples' + sep + 'mkvmerge-chaptertool-issue-18.xml', 'utf-8');

it('parses well-formed input', () => {
expect(() => {
MKVMergeXML.create(content);
}).not.toThrow(Error);
});

const instance = MKVMergeXML.create(content);

it('has the correct number of chapters from content', () => {
expect(instance.chapters.length).toEqual(10);
});

it('has parsed the timestamps correctly', () => {
expect(instance.chapters[1].startTime).toBe(600.516)
});


it('has parsed the chapter titles correctly', () => {
expect(instance.chapters[1].title).toBe('Chapter 02')
});
});
119 changes: 119 additions & 0 deletions tests/samples/mkvmerge-chaptertool-issue-18.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE Chapters SYSTEM "matroskachapters.dtd"> -->
<Chapters>
<EditionEntry>
<EditionUID>18199911203212776794</EditionUID>
<EditionFlagHidden>0</EditionFlagHidden>
<EditionFlagDefault>1</EditionFlagDefault>
<ChapterAtom>
<ChapterUID>967610324052188741</ChapterUID>
<ChapterTimeStart>00:00:00.000000000</ChapterTimeStart>
<ChapterTimeEnd>00:10:00.516583333</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 01</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>9982692933481321716</ChapterUID>
<ChapterTimeStart>00:10:00.516583333</ChapterTimeStart>
<ChapterTimeEnd>00:20:01.658791666</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 02</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>10100638270006970476</ChapterUID>
<ChapterTimeStart>00:20:01.658791666</ChapterTimeStart>
<ChapterTimeEnd>00:30:22.070250000</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 03</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>7618622075668223579</ChapterUID>
<ChapterTimeStart>00:30:22.070250000</ChapterTimeStart>
<ChapterTimeEnd>00:40:02.149750000</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 04</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>2970456447067052416</ChapterUID>
<ChapterTimeStart>00:40:02.149750000</ChapterTimeStart>
<ChapterTimeEnd>00:50:02.666333333</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 05</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>4580233962780638856</ChapterUID>
<ChapterTimeStart>00:50:02.666333333</ChapterTimeStart>
<ChapterTimeEnd>01:00:03.474875000</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 06</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>12392132750035924820</ChapterUID>
<ChapterTimeStart>01:00:03.474875000</ChapterTimeStart>
<ChapterTimeEnd>01:10:03.824625000</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 07</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>4981921100376706990</ChapterUID>
<ChapterTimeStart>01:10:03.824625000</ChapterTimeStart>
<ChapterTimeEnd>01:20:04.424625000</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 08</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>8971296671021847156</ChapterUID>
<ChapterTimeStart>01:20:04.424625000</ChapterTimeStart>
<ChapterTimeEnd>01:30:05.483416666</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 09</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
<ChapterAtom>
<ChapterUID>938349414182508344</ChapterUID>
<ChapterTimeStart>01:30:05.483416666</ChapterTimeStart>
<ChapterTimeEnd>01:35:01.987958333</ChapterTimeEnd>
<ChapterFlagHidden>0</ChapterFlagHidden>
<ChapterFlagEnabled>1</ChapterFlagEnabled>
<ChapterDisplay>
<ChapterString>Chapter 10</ChapterString>
<ChapterLanguage>eng</ChapterLanguage>
</ChapterDisplay>
</ChapterAtom>
</EditionEntry>
</Chapters>

0 comments on commit e4f2faf

Please sign in to comment.