Skip to content

Commit

Permalink
fix: properly set paths to media elems with sources children
Browse files Browse the repository at this point in the history
When a media element (video, source) has sources children, the `src`
property of the reported object now contains an array of objects,
each of which having a `src` property.

Closes #48
  • Loading branch information
rdeltour committed Oct 5, 2017
1 parent 999ebe8 commit 4d816fe
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/checker/checker-nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/__tests__/report_json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
}],
});
});
});
14 changes: 14 additions & 0 deletions tests/data/feat-video-sources/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<video>
<source src="video_001.mp4" type="video/mp4"/>
<source src="video_002.mp4" type="video/mp4"/>
<div>fallback</div>
</video>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/feat-video-sources/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
25 changes: 25 additions & 0 deletions tests/data/feat-video-sources/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
<item id="video_001" href="video_001.mp4" media-type="video/mp4"/>
<item id="video_002" href="video_002.mp4" media-type="video/mp4"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
1 change: 1 addition & 0 deletions tests/data/feat-video-sources/EPUB/video_001.mp4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fake video
1 change: 1 addition & 0 deletions tests/data/feat-video-sources/EPUB/video_002.mp4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fake video
6 changes: 6 additions & 0 deletions tests/data/feat-video-sources/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/feat-video-sources/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip

0 comments on commit 4d816fe

Please sign in to comment.