diff --git a/src/checker/checker-nightmare.js b/src/checker/checker-nightmare.js index 6fc6de4b..119a2292 100644 --- a/src/checker/checker-nightmare.js +++ b/src/checker/checker-nightmare.js @@ -67,10 +67,18 @@ function checkSingle(spineItem, epub, nightmare) { if (!Array.isArray(results.data[key])) return; results.data[key].forEach((item) => { if (item.src !== undefined) { - const fullpath = path.resolve(path.dirname(spineItem.filepath), item.src); - const relpath = path.relative(epub.basedir, fullpath); - item.path = fullpath; - item.src = relpath; + if (Array.isArray(item.src)) { + item.src = item.src.map((srcItem) => { + if (srcItem.src !== undefined) { + srcItem.path = path.resolve(path.dirname(spineItem.filepath), srcItem.src.toString()); + srcItem.src = path.relative(epub.basedir, srcItem.path); + } + return srcItem; + }); + } else { + item.path = path.resolve(path.dirname(spineItem.filepath), item.src.toString()); + item.src = path.relative(epub.basedir, item.path); + } if (item.cfi !== undefined) { item.location = `${spineItem.relpath}#epubcfi(${item.cfi})`; delete item.cfi; diff --git a/tests/__tests__/report_json.test.js b/tests/__tests__/report_json.test.js index 01d8bf35..b0eea078 100644 --- a/tests/__tests__/report_json.test.js +++ b/tests/__tests__/report_json.test.js @@ -121,4 +121,13 @@ describe('check data', () => { }], }); }); + + test('extract videos with sources', async () => { + const report = await ace(path.join(__dirname, '../data/feat-video-sources')); + expect(report.data).toMatchObject({ + videos: [{ + src: [{ src: 'EPUB/video_001.mp4' }, { src: 'EPUB/video_002.mp4' }], + }], + }); + }); }); diff --git a/tests/data/feat-video-sources/EPUB/content_001.xhtml b/tests/data/feat-video-sources/EPUB/content_001.xhtml new file mode 100644 index 00000000..6a3aad64 --- /dev/null +++ b/tests/data/feat-video-sources/EPUB/content_001.xhtml @@ -0,0 +1,14 @@ + + +Minimal EPUB + + +

Loomings

+

Call me Ishmael.

+ + + diff --git a/tests/data/feat-video-sources/EPUB/nav.xhtml b/tests/data/feat-video-sources/EPUB/nav.xhtml new file mode 100644 index 00000000..1d538c19 --- /dev/null +++ b/tests/data/feat-video-sources/EPUB/nav.xhtml @@ -0,0 +1,12 @@ + + +Minimal Nav + + + + + diff --git a/tests/data/feat-video-sources/EPUB/package.opf b/tests/data/feat-video-sources/EPUB/package.opf new file mode 100644 index 00000000..e0362d54 --- /dev/null +++ b/tests/data/feat-video-sources/EPUB/package.opf @@ -0,0 +1,25 @@ + + + + Minimal EPUB 3.0 + en + NOID + 2017-01-01T00:00:01Z + structuralNavigation + everything OK! + noFlashingHazard + noSoundHazard + noMotionSimulationHazard + textual + textual + + + + + + + + + + + diff --git a/tests/data/feat-video-sources/EPUB/video_001.mp4 b/tests/data/feat-video-sources/EPUB/video_001.mp4 new file mode 100644 index 00000000..dcbfedee --- /dev/null +++ b/tests/data/feat-video-sources/EPUB/video_001.mp4 @@ -0,0 +1 @@ +fake video diff --git a/tests/data/feat-video-sources/EPUB/video_002.mp4 b/tests/data/feat-video-sources/EPUB/video_002.mp4 new file mode 100644 index 00000000..dcbfedee --- /dev/null +++ b/tests/data/feat-video-sources/EPUB/video_002.mp4 @@ -0,0 +1 @@ +fake video diff --git a/tests/data/feat-video-sources/META-INF/container.xml b/tests/data/feat-video-sources/META-INF/container.xml new file mode 100644 index 00000000..2cf00654 --- /dev/null +++ b/tests/data/feat-video-sources/META-INF/container.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/data/feat-video-sources/mimetype b/tests/data/feat-video-sources/mimetype new file mode 100644 index 00000000..57ef03f2 --- /dev/null +++ b/tests/data/feat-video-sources/mimetype @@ -0,0 +1 @@ +application/epub+zip \ No newline at end of file