@pixwel/pixwel-sdk 1.1.0
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/.babelrc +3 -0
- package/.editorconfig +36 -0
- package/.vs/slnx.sqlite +0 -0
- package/.vscode/launch.json +0 -0
- package/coverage/clover.xml +7 -0
- package/coverage/coverage-final.json +1 -0
- package/coverage/lcov-report/Ass.js.html +651 -0
- package/coverage/lcov-report/Asset.js.html +129 -0
- package/coverage/lcov-report/Filename.js.html +849 -0
- package/coverage/lcov-report/Ingest.js.html +591 -0
- package/coverage/lcov-report/IngestFile.js.html +87 -0
- package/coverage/lcov-report/IngestFileDrop.js.html +540 -0
- package/coverage/lcov-report/Order.js.html +162 -0
- package/coverage/lcov-report/Srt.js.html +333 -0
- package/coverage/lcov-report/Sub.js.html +177 -0
- package/coverage/lcov-report/TimeFormat.js.html +210 -0
- package/coverage/lcov-report/base.css +223 -0
- package/coverage/lcov-report/block-navigation.js +63 -0
- package/coverage/lcov-report/index.html +84 -0
- package/coverage/lcov-report/lib/Filename.js.html +720 -0
- package/coverage/lcov-report/lib/index.html +97 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +1 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +158 -0
- package/coverage/lcov-report/test/index.html +97 -0
- package/coverage/lcov-report/test/mocks.js.html +423 -0
- package/coverage/lcov.info +0 -0
- package/dist/index.js +61 -0
- package/dist/src/Ass.js +200 -0
- package/dist/src/Asset.js +41 -0
- package/dist/src/Filename.js +252 -0
- package/dist/src/Ingest.js +200 -0
- package/dist/src/IngestFile.js +17 -0
- package/dist/src/IngestFileDrop.js +178 -0
- package/dist/src/Order.js +58 -0
- package/dist/src/Srt.js +102 -0
- package/dist/src/Sub.js +42 -0
- package/dist/src/TimeFormat.js +48 -0
- package/index.js +6 -0
- package/package.json +26 -0
- package/src/Ass.js +195 -0
- package/src/Asset.js +20 -0
- package/src/Filename.js +260 -0
- package/src/Ingest.js +175 -0
- package/src/IngestFile.js +6 -0
- package/src/IngestFileDrop.js +157 -0
- package/src/Order.js +31 -0
- package/src/Srt.js +89 -0
- package/src/Sub.js +37 -0
- package/src/TimeFormat.js +48 -0
- package/src/docs.json +1 -0
- package/test/Ass.spec.js +150 -0
- package/test/Asset.spec.js +24 -0
- package/test/Filename.spec.js +728 -0
- package/test/Ingest.spec.js +95 -0
- package/test/Srt.spec.js +111 -0
- package/test/Sub.spec.js +75 -0
- package/test/TimeFormat.spec.js +84 -0
- package/test/mocks/mediainfo.mock.js +67 -0
- package/test/mocks/mediainfo.png.mock.js +22 -0
- package/test/mocks/mocks.js +118 -0
- package/test/mocks/prores.mock.js +71 -0
- package/test/parse.spec.ts +927 -0
- package/tsconfig.json +11 -0
package/src/Sub.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
parse: function(lines) {
|
|
3
|
+
var result = [],
|
|
4
|
+
current = {
|
|
5
|
+
text: ""
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
lines.forEach(function(line) {
|
|
9
|
+
line = line.replace(/^\s+|\s+$/g, '');
|
|
10
|
+
var subTime = line.match(/^([0-9:\.]+),([0-9:\.]+)$/);
|
|
11
|
+
|
|
12
|
+
if (subTime) {
|
|
13
|
+
if (current.text) {
|
|
14
|
+
result.push(current);
|
|
15
|
+
}
|
|
16
|
+
current = {
|
|
17
|
+
startTime: subTime[1],
|
|
18
|
+
stopTime: subTime[2],
|
|
19
|
+
text: ""
|
|
20
|
+
};
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (line) {
|
|
25
|
+
if (current.startTime === undefined || current.stopTime === 'undefined') {
|
|
26
|
+
throw new Error('Malformed SUB file');
|
|
27
|
+
}
|
|
28
|
+
current.text += (current.text) ? "\n" + line : line;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (current.text) {
|
|
33
|
+
result.push(current);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
var stringRegex = /^(\d+):(\d+):(\d+)[,|.](\d{2,3})?$/;
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
isValidTime: function(time) {
|
|
5
|
+
return !!time.match(stringRegex);
|
|
6
|
+
},
|
|
7
|
+
timeToTimestamp: function(time) {
|
|
8
|
+
var match = time.match(stringRegex);
|
|
9
|
+
if (!match) {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
var precision = match[4].length === 2 ? 100 : 1000;
|
|
13
|
+
return (
|
|
14
|
+
(parseInt(match[1], 10) * 60 * 60) +
|
|
15
|
+
(parseInt(match[2], 10) * 60) +
|
|
16
|
+
parseInt(match[3], 10) +
|
|
17
|
+
(parseInt(match[4], 10) / precision)
|
|
18
|
+
);
|
|
19
|
+
},
|
|
20
|
+
timestampToTime: function(second, decimalMark) {
|
|
21
|
+
var hours = ~~(second / 3600);
|
|
22
|
+
var min = ~~(second / 60) % 60;
|
|
23
|
+
var sec = second % 60;
|
|
24
|
+
var fixedSec = sec.toFixed(3).replace('.', decimalMark ? decimalMark : ',');
|
|
25
|
+
return (hours < 10 ? '0' + hours : hours) + ":" + (min < 10 ? '0' + min : min) + ':' + (sec < 10 ? '0' + fixedSec : fixedSec);
|
|
26
|
+
},
|
|
27
|
+
timeDiff: function(time1, time2) {
|
|
28
|
+
if (time1 === undefined || time2 === undefined) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
return this.timestampDiff(this.timeToTimestamp(time1), this.timeToTimestamp(time2));
|
|
32
|
+
},
|
|
33
|
+
timestampDiff: function(time1, time2) {
|
|
34
|
+
if (time1 === undefined || time2 === undefined || time1 === time2) {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
var diff = time2 - time1;
|
|
38
|
+
return Math.round(Math.max(-1, Math.min(1, diff)) * 10) / 10;
|
|
39
|
+
},
|
|
40
|
+
startTime: function(line) {
|
|
41
|
+
var timestamp = this.timeToTimestamp(line.startTime) + (line.inOffset || 0);
|
|
42
|
+
return this.timestampToTime(timestamp);
|
|
43
|
+
},
|
|
44
|
+
stopTime: function(line) {
|
|
45
|
+
var timestamp = this.timeToTimestamp(line.stopTime) + (line.outOffset || 0);
|
|
46
|
+
return this.timestampToTime(timestamp);
|
|
47
|
+
}
|
|
48
|
+
};
|
package/src/docs.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"language":"javascript","client_name":"inchjs","args":[],"client_version":"0.4.1","git_repo_url":"git@github.com:Pixwel/platform.git","branch_name":"599-alt","objects":[{"comment":"","meta":{"range":[64,128],"filename":"Ass.js","lineno":4,"columnno":0,"path":"","code":{"id":"astnode100000010","name":"trim","type":"FunctionDeclaration","paramnames":["str"]}},"undocumented":true,"name":"trim","longname":"trim","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[130,410],"filename":"Ass.js","lineno":8,"columnno":0,"path":"","code":{"id":"astnode100000021","name":"searchIndex","type":"FunctionDeclaration","paramnames":["lines","pattern","startIndex"]},"vars":{"len":"searchIndex~len","startIndex":"searchIndex~startIndex","i":"searchIndex~i","line":"searchIndex~line"}},"undocumented":true,"name":"searchIndex","longname":"searchIndex","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[412,1818],"filename":"Ass.js","lineno":21,"columnno":0,"path":"","code":{"id":"astnode100000067","name":"extractStyles","type":"FunctionDeclaration","paramnames":["lines"]},"vars":{"line":"extractStyles~line","styles":"extractStyles~styles","currentIndex":"extractStyles~currentIndex","fields":"extractStyles~fields","nameIndex":"extractStyles~nameIndex","alignmentIndex":"extractStyles~alignmentIndex","pattern":"extractStyles~pattern","parts":"extractStyles~parts","style":"extractStyles~style","alignmentNumber":"extractStyles~alignmentNumber","style.alignment":"extractStyles~style.alignment","styles[undefined]":"extractStyles~styles.undefined]"}},"undocumented":true,"name":"extractStyles","longname":"extractStyles","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[1841,4468],"filename":"Ass.js","lineno":70,"columnno":4,"path":"","code":{"id":"astnode100000270","name":"parse","type":"FunctionExpression"},"vars":{"line":"module.exports.parse~line","currentIndex":"module.exports.parse~currentIndex","normalizeTime":"module.exports.parse~normalizeTime","normalizeText":"module.exports.parse~normalizeText","styles":"module.exports.parse~styles","fields":"module.exports.parse~fields","startIndex":"module.exports.parse~startIndex","endIndex":"module.exports.parse~endIndex","styleIndex":"module.exports.parse~styleIndex","textIndex":"module.exports.parse~textIndex","result":"module.exports.parse~result","pattern":"module.exports.parse~pattern","parts":"module.exports.parse~parts","entry":"module.exports.parse~entry","style":"module.exports.parse~style","entry.alignment":"module.exports.parse~entry.alignment"}},"undocumented":true,"name":"parse","longname":"module.exports.parse","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[4474,6251],"filename":"Ass.js","lineno":143,"columnno":4,"path":"","code":{"id":"astnode100000604","name":"export","type":"FunctionExpression"},"vars":{"result":"module.exports.export~result","options":"module.exports.export~options","font":"module.exports.export~font","normalizeTime":"module.exports.export~normalizeTime","normalizeText":"module.exports.export~normalizeText","":null}},"undocumented":true,"name":"export","longname":"module.exports.export","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[0,598],"filename":"Asset.js","lineno":1,"columnno":0,"path":"","code":{"id":"astnode100000842","name":"module.exports","type":"ClassDeclaration"}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"","meta":{"range":[15,598],"filename":"Asset.js","lineno":1,"columnno":15,"path":"","code":{"id":"astnode100000843","name":"module.exports","type":"ClassDeclaration","paramnames":[]}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"","meta":{"range":[33,596],"filename":"Asset.js","lineno":2,"columnno":4,"path":"","code":{"id":"astnode100000846","name":"mapFromOrder","type":"MethodDefinition","paramnames":["order"]},"vars":{"":null}},"undocumented":true,"name":"mapFromOrder","longname":"mapFromOrder","kind":"function","scope":"global","params":[]},{"comment":"/**\n* The Filename class parses a filename into tokens, and can also take a set of\n* tokens and create a valid Pixwel filename.\n* @type class\n*/","meta":{"range":[174,7418],"filename":"Filename.js","lineno":8,"columnno":0,"path":"","code":{"id":"astnode100000928","name":"module.exports","type":"ClassDeclaration"}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"/**\n* The Filename class parses a filename into tokens, and can also take a set of\n* tokens and create a valid Pixwel filename.\n* @type class\n*/","meta":{"range":[189,7418],"filename":"Filename.js","lineno":8,"columnno":15,"path":"","code":{"id":"astnode100000929","name":"module.exports","type":"ClassDeclaration","paramnames":[]}},"classdesc":"The Filename class parses a filename into tokens, and can also take a set of\ntokens and create a valid Pixwel filename.","type":{"names":["class"]},"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"/**\n* Renders a valid filename given all tags, all types, an asset, and metadata\n* options likely parsed from the file itself.\n* @param {Array} [allTags=[]] Collection of all known tags\n* @param {Array} [allTypes=[]] Collection of all known types\n* @param {Object} [asset={}] A Platform Asset\n* @param {Object} [options={}] options containing metadata about file\n* @return {String} A valid filename\n*/","meta":{"range":[680,7416],"filename":"Filename.js","lineno":18,"columnno":4,"path":"","code":{"id":"astnode100000932","name":"render","type":"MethodDefinition","paramnames":["allTags","allTypes","asset","options"]},"vars":{"":null}},"description":"Renders a valid filename given all tags, all types, an asset, and metadata\noptions likely parsed from the file itself.","params":[{"type":{"names":["Array"]},"optional":true,"defaultvalue":"[]","description":"Collection of all known tags","name":"allTags"},{"type":{"names":["Array"]},"optional":true,"defaultvalue":"[]","description":"Collection of all known types","name":"allTypes"},{"type":{"names":["Object"]},"optional":true,"defaultvalue":"{}","description":"A Platform Asset","name":"asset"},{"type":{"names":["Object"]},"optional":true,"defaultvalue":"{}","description":"options containing metadata about file","name":"options"}],"returns":[{"type":{"names":["String"]},"description":"A valid filename"}],"name":"render","longname":"render","kind":"function","scope":"global"},{"comment":"/**\n* [video description]\n* @type {[type]}\n*/","meta":{"range":[74,4621],"filename":"Ingest.js","lineno":7,"columnno":0,"path":"","code":{"id":"astnode100001807","name":"module.exports","type":"ClassDeclaration"}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"/**\n* [video description]\n* @type {[type]}\n*/","meta":{"range":[89,4621],"filename":"Ingest.js","lineno":7,"columnno":15,"path":"","code":{"id":"astnode100001808","name":"module.exports","type":"ClassDeclaration","paramnames":[]}},"classdesc":"[video description]","name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"/**\n* [mapMetaToTags description]\n* @param {[type]} info [description]\n* @return {[type]} [description]\n*/","meta":{"range":[245,3023],"filename":"Ingest.js","lineno":13,"columnno":4,"path":"","code":{"id":"astnode100001811","name":"mapMetaToTags","type":"MethodDefinition","paramnames":["info"]},"vars":{"":null}},"description":"[mapMetaToTags description]","params":[{"name":"info"}],"returns":[{}],"name":"mapMetaToTags","longname":"mapMetaToTags","kind":"function","scope":"global"},{"comment":"","meta":{"range":[3028,4618],"filename":"Ingest.js","lineno":114,"columnno":4,"path":"","code":{"id":"astnode100002176","name":"mapFromOrder","type":"MethodDefinition","paramnames":["order","tags","watermarks"]},"vars":{"":null}},"undocumented":true,"name":"mapFromOrder","longname":"mapFromOrder","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[0,120],"filename":"IngestFile.js","lineno":1,"columnno":0,"path":"","code":{"id":"astnode100002336","name":"module.exports","type":"ClassDeclaration"}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"","meta":{"range":[15,120],"filename":"IngestFile.js","lineno":1,"columnno":15,"path":"","code":{"id":"astnode100002337","name":"module.exports","type":"ClassDeclaration","paramnames":["file","order"]}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"","meta":{"range":[35,84],"filename":"IngestFile.js","lineno":2,"columnno":1,"path":"","code":{"id":"astnode100002340","name":"module.exports","type":"MethodDefinition","paramnames":["file","order"]},"vars":{"":null}},"undocumented":true,"name":"exports","longname":"module.exports#module.exports","kind":"class","memberof":"module.exports#module","scope":"static","params":[]},{"comment":"/**\n* Collects file handles from HTML5, full paths from Aspera, inspects\n* the dropped file using mediainfo, then renames the file according to\n* the data from Mediainfo and the Order and submits it for upload.\n* @type {Object}\n*/","meta":{"range":[318,4278],"filename":"IngestFileDrop.js","lineno":9,"columnno":0,"path":"","code":{"id":"astnode100002366","name":"module.exports","type":"ClassDeclaration"}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"/**\n* Collects file handles from HTML5, full paths from Aspera, inspects\n* the dropped file using mediainfo, then renames the file according to\n* the data from Mediainfo and the Order and submits it for upload.\n* @type {Object}\n*/","meta":{"range":[333,4278],"filename":"IngestFileDrop.js","lineno":9,"columnno":15,"path":"","code":{"id":"astnode100002367","name":"module.exports","type":"ClassDeclaration","paramnames":["scope","Mediainfo","IngestUpload"]}},"classdesc":"Collects file handles from HTML5, full paths from Aspera, inspects\nthe dropped file using mediainfo, then renames the file according to\nthe data from Mediainfo and the Order and submits it for upload.","type":{"names":["Object"]},"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static","description":"Map that contains data from HTML5 file drop and Aspera file drop","params":[]},{"comment":"/**\n* Map that contains data from HTML5 file drop and Aspera file drop\n* @type {Object}\n*/","meta":{"range":[470,810],"filename":"IngestFileDrop.js","lineno":14,"columnno":4,"path":"","code":{"id":"astnode100002370","name":"module.exports","type":"MethodDefinition","paramnames":["scope","Mediainfo","IngestUpload"]},"vars":{"":null}},"description":"Map that contains data from HTML5 file drop and Aspera file drop","type":{"names":["Object"]},"name":"exports","longname":"module.exports#module.exports","kind":"class","memberof":"module.exports#module","scope":"static","params":[],"undocumented":true},{"comment":"/**\n* HTML file drop handler\n* @param {[type]} e [description]\n* @return {[type]} [description]\n*/","meta":{"range":[961,1153],"filename":"IngestFileDrop.js","lineno":27,"columnno":4,"path":"","code":{"id":"astnode100002425","name":"htmlDropHandler","type":"MethodDefinition","paramnames":["e"]},"vars":{"":null}},"description":"HTML file drop handler","params":[{"name":"e"}],"returns":[{}],"name":"htmlDropHandler","longname":"htmlDropHandler","kind":"function","scope":"global"},{"comment":"/**\n* Aspera drop handler\n* @param {[type]} data [description]\n* @return {[type]} [description]\n*/","meta":{"range":[1307,1815],"filename":"IngestFileDrop.js","lineno":38,"columnno":4,"path":"","code":{"id":"astnode100002459","name":"asperaDropHandler","type":"MethodDefinition","paramnames":["data"]},"vars":{"":null}},"description":"Aspera drop handler","params":[{"name":"data"}],"returns":[{}],"name":"asperaDropHandler","longname":"asperaDropHandler","kind":"function","scope":"global"},{"comment":"/**\n* Registers and HTML file drop\n* @param {[type]} file [description]\n* @return {[type]} [description]\n*/","meta":{"range":[1978,2052],"filename":"IngestFileDrop.js","lineno":58,"columnno":4,"path":"","code":{"id":"astnode100002535","name":"registerHtmlFile","type":"MethodDefinition","paramnames":["file"]},"vars":{"":null}},"description":"Registers and HTML file drop","params":[{"name":"file"}],"returns":[{}],"name":"registerHtmlFile","longname":"registerHtmlFile","kind":"function","scope":"global"},{"comment":"/**\n* Registers and Aspera file drop\n* @param {[type]} file [description]\n* @return {[type]} [description]\n*/","meta":{"range":[2217,2356],"filename":"IngestFileDrop.js","lineno":66,"columnno":4,"path":"","code":{"id":"astnode100002550","name":"registerAsperaFile","type":"MethodDefinition","paramnames":["file"]},"vars":{"":null}},"description":"Registers and Aspera file drop","params":[{"name":"file"}],"returns":[{}],"name":"registerAsperaFile","longname":"registerAsperaFile","kind":"function","scope":"global"},{"comment":"/**\n* Gets correct basename for MacOS and Windows\n* @param {[type]} file [description]\n* @return {[type]} [description]\n*/","meta":{"range":[2534,2665],"filename":"IngestFileDrop.js","lineno":75,"columnno":4,"path":"","code":{"id":"astnode100002575","name":"getBasename","type":"MethodDefinition","paramnames":["file"]},"vars":{"":null}},"description":"Gets correct basename for MacOS and Windows","params":[{"name":"file"}],"returns":[{}],"name":"getBasename","longname":"getBasename","kind":"function","scope":"global"},{"comment":"/**\n* Renames and generates ingest record for internal filemap\n* @return {[type]} [description]\n*/","meta":{"range":[2804,2948],"filename":"IngestFileDrop.js","lineno":82,"columnno":4,"path":"","code":{"id":"astnode100002609","name":"export","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"description":"Renames and generates ingest record for internal filemap","returns":[{}],"name":"export","longname":"export","kind":"function","scope":"global","params":[]},{"comment":"/**\n* Renames the file and decorates it with ingest data using data from\n* mediainfo and the Order\n* @param {[type]} file [description]\n* @return {[type]} [description]\n*/","meta":{"range":[3160,4276],"filename":"IngestFileDrop.js","lineno":94,"columnno":4,"path":"","code":{"id":"astnode100002637","name":"rename","type":"MethodDefinition","paramnames":["file"]},"vars":{"":null}},"description":"Renames the file and decorates it with ingest data using data from\nmediainfo and the Order","params":[{"name":"file"}],"returns":[{}],"name":"rename","longname":"rename","kind":"function","scope":"global"},{"comment":"","meta":{"range":[63,589],"filename":"Order.js","lineno":4,"columnno":0,"path":"","code":{"id":"astnode100002819","name":"module.exports","type":"ClassDeclaration"}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"","meta":{"range":[78,589],"filename":"Order.js","lineno":4,"columnno":15,"path":"","code":{"id":"astnode100002820","name":"module.exports","type":"ClassDeclaration","paramnames":["data"]}},"undocumented":true,"name":"exports","longname":"module.exports","kind":"class","memberof":"module","scope":"static"},{"comment":"","meta":{"range":[96,379],"filename":"Order.js","lineno":5,"columnno":4,"path":"","code":{"id":"astnode100002823","name":"module.exports","type":"MethodDefinition","paramnames":["data"]},"vars":{"":null}},"undocumented":true,"name":"exports","longname":"module.exports#module.exports","kind":"class","memberof":"module.exports#module","scope":"static","params":[]},{"comment":"","meta":{"range":[384,489],"filename":"Order.js","lineno":17,"columnno":4,"path":"","code":{"id":"astnode100002854","name":"isDub","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"undocumented":true,"name":"isDub","longname":"isDub","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[494,587],"filename":"Order.js","lineno":20,"columnno":4,"path":"","code":{"id":"astnode100002874","name":"isSub","type":"MethodDefinition","paramnames":[]},"vars":{"":null}},"undocumented":true,"name":"isSub","longname":"isSub","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[64,482],"filename":"Srt.js","lineno":4,"columnno":0,"path":"","code":{"id":"astnode100002904","name":"stripTags","type":"FunctionDeclaration","paramnames":["input","allowed"]},"vars":{"allowed":"stripTags~allowed","tags":"stripTags~tags","commentsAndPhpTags":"stripTags~commentsAndPhpTags","":null}},"undocumented":true,"name":"stripTags","longname":"stripTags","kind":"function","scope":"global","params":[]},{"comment":"","meta":{"range":[608,1980],"filename":"Srt.js","lineno":19,"columnno":4,"path":"","code":{"id":"astnode100002987","name":"parse","type":"FunctionExpression"},"vars":{"result":"module.exports.parse~result","state":"module.exports.parse~state","subText":"module.exports.parse~subText","subTime":"module.exports.parse~subTime","time":"module.exports.parse~time","":null}},"undocumented":true,"name":"parse","longname":"module.exports.parse","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[1986,2787],"filename":"Srt.js","lineno":67,"columnno":4,"path":"","code":{"id":"astnode100003129","name":"export","type":"FunctionExpression"},"vars":{"result":"module.exports.export~result","i":"module.exports.export~i","":null}},"undocumented":true,"name":"export","longname":"module.exports.export","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[21,1005],"filename":"Sub.js","lineno":2,"columnno":4,"path":"","code":{"id":"astnode100003215","name":"parse","type":"FunctionExpression"},"vars":{"result":"module.exports.parse~result","current":"module.exports.parse~current","":null}},"undocumented":true,"name":"parse","longname":"module.exports.parse","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[78,155],"filename":"TimeFormat.js","lineno":4,"columnno":4,"path":"","code":{"id":"astnode100003336","name":"isValidTime","type":"FunctionExpression"}},"undocumented":true,"name":"isValidTime","longname":"module.exports.isValidTime","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[161,566],"filename":"TimeFormat.js","lineno":7,"columnno":4,"path":"","code":{"id":"astnode100003348","name":"timeToTimestamp","type":"FunctionExpression"},"vars":{"match":"module.exports.timeToTimestamp~match","precision":"module.exports.timeToTimestamp~precision"}},"undocumented":true,"name":"timeToTimestamp","longname":"module.exports.timeToTimestamp","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[572,956],"filename":"TimeFormat.js","lineno":20,"columnno":4,"path":"","code":{"id":"astnode100003415","name":"timestampToTime","type":"FunctionExpression"},"vars":{"hours":"module.exports.timestampToTime~hours","min":"module.exports.timestampToTime~min","sec":"module.exports.timestampToTime~sec","fixedSec":"module.exports.timestampToTime~fixedSec"}},"undocumented":true,"name":"timestampToTime","longname":"module.exports.timestampToTime","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[962,1185],"filename":"TimeFormat.js","lineno":27,"columnno":4,"path":"","code":{"id":"astnode100003491","name":"timeDiff","type":"FunctionExpression"}},"undocumented":true,"name":"timeDiff","longname":"module.exports.timeDiff","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[1191,1449],"filename":"TimeFormat.js","lineno":33,"columnno":4,"path":"","code":{"id":"astnode100003522","name":"timestampDiff","type":"FunctionExpression"},"vars":{"diff":"module.exports.timestampDiff~diff"}},"undocumented":true,"name":"timestampDiff","longname":"module.exports.timestampDiff","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[1455,1621],"filename":"TimeFormat.js","lineno":40,"columnno":4,"path":"","code":{"id":"astnode100003569","name":"startTime","type":"FunctionExpression"},"vars":{"timestamp":"module.exports.startTime~timestamp"}},"undocumented":true,"name":"startTime","longname":"module.exports.startTime","kind":"function","memberof":"module.exports","scope":"static"},{"comment":"","meta":{"range":[1627,1792],"filename":"TimeFormat.js","lineno":44,"columnno":4,"path":"","code":{"id":"astnode100003595","name":"stopTime","type":"FunctionExpression"},"vars":{"timestamp":"module.exports.stopTime~timestamp"}},"undocumented":true,"name":"stopTime","longname":"module.exports.stopTime","kind":"function","memberof":"module.exports","scope":"static"}]}
|
package/test/Ass.spec.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import ASS from '../lib/Ass';
|
|
2
|
+
|
|
3
|
+
let translation = {
|
|
4
|
+
"_id": "translation-wwz",
|
|
5
|
+
"status": "complete",
|
|
6
|
+
"workRequest": "wr1",
|
|
7
|
+
"asset": "assetA",
|
|
8
|
+
"language": "ENG",
|
|
9
|
+
"lines": [{
|
|
10
|
+
"number": 1,
|
|
11
|
+
"startTime": "00:00:00,840",
|
|
12
|
+
"stopTime": "00:00:04,880",
|
|
13
|
+
"range": [0.84, 4.88],
|
|
14
|
+
"text": "They've brought you\nthe most <i>unforgettable</i> families of all time.",
|
|
15
|
+
"alignment": "bottom",
|
|
16
|
+
"inOffset": 0.1,
|
|
17
|
+
"outOffset": -0.1
|
|
18
|
+
}, {
|
|
19
|
+
"number": 2,
|
|
20
|
+
"startTime": "00:00:05,580",
|
|
21
|
+
"stopTime": "00:00:07,400",
|
|
22
|
+
"range": [5.580, 7.4],
|
|
23
|
+
"text": "Da, da, da!",
|
|
24
|
+
"alignment": "top"
|
|
25
|
+
}, {
|
|
26
|
+
"number": 3,
|
|
27
|
+
"startTime": "00:00:07,400",
|
|
28
|
+
"stopTime": "00:00:11,750",
|
|
29
|
+
"range": [7.4, 11.75],
|
|
30
|
+
"text": "Now from DreamWorks Animation\ncomes the most unexpected family of all:",
|
|
31
|
+
"alignment": "bottom",
|
|
32
|
+
"inOffset": -0.1,
|
|
33
|
+
"outOffset": 0.1
|
|
34
|
+
}]
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe("ASS", function() {
|
|
38
|
+
|
|
39
|
+
let testDataAss = "[Script Info]\n" +
|
|
40
|
+
"ScriptType: v4.00+\n" +
|
|
41
|
+
"\n" +
|
|
42
|
+
"[V4+ Styles]\n" +
|
|
43
|
+
"Format: Name, Fontname, Fontsize, PrimaryColour,Shadow,MarginV,Alignment\n" +
|
|
44
|
+
"Style: Bottom,Arial,20,&H00FFFFFF,1,20,2\n" +
|
|
45
|
+
"Style: Top,Arial,20,&H00FFFFFF,1,20,8\n" +
|
|
46
|
+
"\n" +
|
|
47
|
+
"[Events]\n" +
|
|
48
|
+
"Format: Layer, Start, End, Style, Text\n" +
|
|
49
|
+
"Dialogue: 0,0:00:00.94,0:00:04.78,Bottom,They've brought you\\Nthe most {\\i1}unforgettable{\\i0} families of all time.\n" +
|
|
50
|
+
"Dialogue: 0,0:00:05.58,0:00:07.40,Top,Da, da, da!\n" +
|
|
51
|
+
"Dialogue: 0,0:00:07.30,0:00:11.85,Bottom,Now from DreamWorks Animation\\Ncomes the most unexpected family of all:\n";
|
|
52
|
+
|
|
53
|
+
describe("parse()", function() {
|
|
54
|
+
it("should parse an ASS file to a collection", function() {
|
|
55
|
+
var lines = ASS.parse(testDataAss.split('\n'));
|
|
56
|
+
expect(lines[0].startTime).toEqual('00:00:00,940');
|
|
57
|
+
expect(lines[0].stopTime).toEqual('00:00:04,780');
|
|
58
|
+
expect(lines[0].text).toEqual("They've brought you\nthe most <i>unforgettable</i> families of all time.");
|
|
59
|
+
expect(lines[0].alignment).toEqual('bottom');
|
|
60
|
+
|
|
61
|
+
expect(lines[1].startTime).toEqual('00:00:05,580');
|
|
62
|
+
expect(lines[1].stopTime).toEqual('00:00:07,400');
|
|
63
|
+
expect(lines[1].text).toEqual('Da, da, da!');
|
|
64
|
+
expect(lines[1].alignment).toEqual('top');
|
|
65
|
+
|
|
66
|
+
expect(lines[2].startTime).toEqual('00:00:07,300');
|
|
67
|
+
expect(lines[2].stopTime).toEqual('00:00:11,850');
|
|
68
|
+
expect(lines[2].text).toEqual('Now from DreamWorks Animation\ncomes the most unexpected family of all:');
|
|
69
|
+
expect(lines[2].alignment).toEqual('bottom');
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("export()", function() {
|
|
74
|
+
it("should export data back to a plain ASS format", function() {
|
|
75
|
+
var out = ASS.export(translation.lines);
|
|
76
|
+
expect(out).toEqual(testDataAss);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should export data back to a plain ASS format using some custom font config", function() {
|
|
80
|
+
var out = ASS.export(translation.lines, {
|
|
81
|
+
font: {
|
|
82
|
+
face: 'Courrier',
|
|
83
|
+
size: 13
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
expect(out).toEqual(testDataAss.replace(/Arial,20,&H00FFFFFF/g, 'Courrier,13,&H00FFFFFF'));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("takes in/out offset into account to build startTime/stopTime", function() {
|
|
90
|
+
var lines = ASS.parse(ASS.export(translation.lines).split('\n'));
|
|
91
|
+
expect(lines[0].startTime).toEqual('00:00:00,940');
|
|
92
|
+
expect(lines[0].stopTime).toEqual('00:00:04,780');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("supports top based alignment", function() {
|
|
96
|
+
var lines = ASS.parse(ASS.export(translation.lines).split('\n'));
|
|
97
|
+
expect(lines[0].alignment).toEqual('bottom');
|
|
98
|
+
expect(lines[1].alignment).toEqual('top');
|
|
99
|
+
expect(lines[2].alignment).toEqual('bottom');
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('with malformed ASS data', function() {
|
|
104
|
+
describe('parse()', function() {
|
|
105
|
+
|
|
106
|
+
function parse(data) {
|
|
107
|
+
return function() {
|
|
108
|
+
ASS.parse(data.split('\n'));
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
it('throws an exception on missing `[Events]` section', function() {
|
|
113
|
+
var data = '[Script Info]\n';
|
|
114
|
+
expect(parse(data)).toThrow(new Error('Error, missing `[Events]` section'));
|
|
115
|
+
|
|
116
|
+
data = '[Script Info]\nFormat: Layer, Start, End, Style, Text\n';
|
|
117
|
+
expect(parse(data)).toThrow(new Error('Error, missing `[Events]` section'));
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('throws an exception on missing `Format` entries', function() {
|
|
121
|
+
var data = '[Script Info]\n[Events]\n';
|
|
122
|
+
expect(parse(data)).toThrow(new Error('Error, missing `Format` entry'));
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('throws an exception on missing fields in `Style` entries', function() {
|
|
126
|
+
var data = '[Script Info]\n';
|
|
127
|
+
data += 'ScriptType: v4.00+\n';
|
|
128
|
+
data += '\n';
|
|
129
|
+
data += '[V4+ Styles]\n';
|
|
130
|
+
data += 'Format: Name, Fontname, Fontsize, PrimaryColour,Shadow,MarginV,Alignment\n';
|
|
131
|
+
data += 'Style: Default,Arial,20\n';
|
|
132
|
+
expect(parse(data)).toThrow(new Error('Error, missing fields in a `Style` entry'));
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('throws an exception on missing fields in `Dialogue` entries', function() {
|
|
136
|
+
var data = '[Script Info]\n';
|
|
137
|
+
data += 'ScriptType: v4.00+\n';
|
|
138
|
+
data += '\n';
|
|
139
|
+
data += '[V4+ Styles]\n';
|
|
140
|
+
data += 'Format: Name, Fontname, Fontsize, PrimaryColour,Shadow,MarginV,Alignment\n';
|
|
141
|
+
data += 'Style: Default,Arial,20,&H00FFFFFF,1,10,2\n';
|
|
142
|
+
data += '\n';
|
|
143
|
+
data += '[Events]\n';
|
|
144
|
+
data += 'Format: Layer, Start, End, Style, Text\n';
|
|
145
|
+
data += 'Dialogue: They\'ve brought you\\Nthe most unforgettable families of all time.\n';
|
|
146
|
+
expect(parse(data)).toThrow(new Error('Error, missing fields in a `Dialogue` entry'));
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Asset from '../lib/Asset';
|
|
2
|
+
import Order from '../lib/Order';
|
|
3
|
+
|
|
4
|
+
describe('Asset', () => {
|
|
5
|
+
describe('mapFromOrder', () => {
|
|
6
|
+
it('should correctly map an order to an asset', () => {
|
|
7
|
+
let order = new Order({
|
|
8
|
+
asset: {
|
|
9
|
+
|
|
10
|
+
},
|
|
11
|
+
project: {
|
|
12
|
+
slug: 'sluggy'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
let asset = Asset.mapFromOrder(order);
|
|
16
|
+
expect(asset).toEqual({
|
|
17
|
+
"project": {
|
|
18
|
+
"filePrefix": "SLUGGY",
|
|
19
|
+
"slug": "sluggy"
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|