mirror of
https://github.com/WebTools-NG/WebTools-NG
synced 2024-11-25 20:40:19 +00:00
#64 refactoring to jsonPath-Plus
This commit is contained in:
parent
18b37915a8
commit
a13166066d
5 changed files with 176 additions and 237 deletions
82
package-lock.json
generated
82
package-lock.json
generated
|
@ -4723,7 +4723,8 @@
|
|||
"deep-is": {
|
||||
"version": "0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
|
||||
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ="
|
||||
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
|
||||
"dev": true
|
||||
},
|
||||
"deepmerge": {
|
||||
"version": "1.5.2",
|
||||
|
@ -5705,26 +5706,6 @@
|
|||
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
|
||||
"dev": true
|
||||
},
|
||||
"escodegen": {
|
||||
"version": "1.14.2",
|
||||
"resolved": "https://registry.npmjs.org/escodegen/-/escodegen-1.14.2.tgz",
|
||||
"integrity": "sha512-InuOIiKk8wwuOFg6x9BQXbzjrQhtyXh46K9bqVTPzSo2FnyMBaYGBMC6PhQy7yxxil9vIedFBweQBMK74/7o8A==",
|
||||
"requires": {
|
||||
"esprima": "^4.0.1",
|
||||
"estraverse": "^4.2.0",
|
||||
"esutils": "^2.0.2",
|
||||
"optionator": "^0.8.1",
|
||||
"source-map": "~0.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"source-map": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"eslint": {
|
||||
"version": "6.8.0",
|
||||
"resolved": "https://registry.npmjs.org/eslint/-/eslint-6.8.0.tgz",
|
||||
|
@ -5914,7 +5895,8 @@
|
|||
"esprima": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
|
||||
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
|
||||
"dev": true
|
||||
},
|
||||
"esquery": {
|
||||
"version": "1.3.1",
|
||||
|
@ -5945,12 +5927,14 @@
|
|||
"estraverse": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz",
|
||||
"integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw=="
|
||||
"integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==",
|
||||
"dev": true
|
||||
},
|
||||
"esutils": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
|
||||
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g=="
|
||||
"integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==",
|
||||
"dev": true
|
||||
},
|
||||
"etag": {
|
||||
"version": "1.8.1",
|
||||
|
@ -6476,7 +6460,8 @@
|
|||
"fast-levenshtein": {
|
||||
"version": "2.0.6",
|
||||
"resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz",
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc="
|
||||
"integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=",
|
||||
"dev": true
|
||||
},
|
||||
"faye-websocket": {
|
||||
"version": "0.10.0",
|
||||
|
@ -6544,6 +6529,11 @@
|
|||
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.2.tgz",
|
||||
"integrity": "sha512-Wz3c3XQ5xroCxd1G8b7yL0Ehkf0TC9oYC6buPFkNnU9EnaPlifeAFCyCh+iewXTyFRcg0a6j3J7FmJsIhlhBdw=="
|
||||
},
|
||||
"file-size": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-size/-/file-size-1.0.0.tgz",
|
||||
"integrity": "sha1-MzgmfV0ga79g9N9gwZ1+04E6Rlc="
|
||||
},
|
||||
"file-uri-to-path": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz",
|
||||
|
@ -8307,22 +8297,10 @@
|
|||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"jsonpath": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/jsonpath/-/jsonpath-1.0.2.tgz",
|
||||
"integrity": "sha512-rmzlgFZiQPc6q4HDyK8s9Qb4oxBnI5sF61y/Co5PV0lc3q2bIuRsNdueVbhoSHdKM4fxeimphOAtfz47yjCfeA==",
|
||||
"requires": {
|
||||
"esprima": "1.2.2",
|
||||
"static-eval": "2.0.2",
|
||||
"underscore": "1.7.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"esprima": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-1.2.2.tgz",
|
||||
"integrity": "sha1-dqD9Zvz+FU/SkmZ9wmQBl1CxZXs="
|
||||
}
|
||||
}
|
||||
"jsonpath-plus": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-4.0.0.tgz",
|
||||
"integrity": "sha512-e0Jtg4KAzDJKKwzbLaUtinCn0RZseWBVRTRGihSpvFlM3wTR7ExSp+PTdeTsDrLNJUe7L7JYJe8mblHX5SCT6A=="
|
||||
},
|
||||
"jsprim": {
|
||||
"version": "1.4.1",
|
||||
|
@ -8429,6 +8407,7 @@
|
|||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
|
||||
"integrity": "sha1-OwmSTt+fCDwEkP3UwLxEIeBHZO4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"prelude-ls": "~1.1.2",
|
||||
"type-check": "~0.3.2"
|
||||
|
@ -9568,6 +9547,7 @@
|
|||
"version": "0.8.3",
|
||||
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz",
|
||||
"integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"deep-is": "~0.1.3",
|
||||
"fast-levenshtein": "~2.0.6",
|
||||
|
@ -10594,7 +10574,8 @@
|
|||
"prelude-ls": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
|
||||
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
|
||||
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=",
|
||||
"dev": true
|
||||
},
|
||||
"prepend-http": {
|
||||
"version": "1.0.4",
|
||||
|
@ -12259,14 +12240,6 @@
|
|||
"integrity": "sha512-QjMLR0A3WwFY2aZdV0okfFEJB5TRjkggXZjxP3A1RsWsNHNu3YPv8btmtc6iCFZ0Rul3FE93OYogvhOUClU+ng==",
|
||||
"dev": true
|
||||
},
|
||||
"static-eval": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/static-eval/-/static-eval-2.0.2.tgz",
|
||||
"integrity": "sha512-N/D219Hcr2bPjLxPiV+TQE++Tsmrady7TqAJugLy7Xk1EumfDWS/f5dtBbkRCGE7wKKXuYockQoj8Rm2/pVKyg==",
|
||||
"requires": {
|
||||
"escodegen": "^1.8.1"
|
||||
}
|
||||
},
|
||||
"static-extend": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz",
|
||||
|
@ -13004,6 +12977,7 @@
|
|||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz",
|
||||
"integrity": "sha1-WITKtRLPHTVeP7eE8wgEsrUg23I=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"prelude-ls": "~1.1.2"
|
||||
}
|
||||
|
@ -13062,11 +13036,6 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"underscore": {
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
|
||||
"integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk="
|
||||
},
|
||||
"unicode-canonical-property-names-ecmascript": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz",
|
||||
|
@ -14718,7 +14687,8 @@
|
|||
"word-wrap": {
|
||||
"version": "1.2.3",
|
||||
"resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz",
|
||||
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ=="
|
||||
"integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==",
|
||||
"dev": true
|
||||
},
|
||||
"wordwrap": {
|
||||
"version": "0.0.3",
|
||||
|
|
|
@ -28,8 +28,9 @@
|
|||
"exceljs": "^4.0.1",
|
||||
"fetch": "^1.1.0",
|
||||
"file-saver": "^2.0.2",
|
||||
"file-size": "^1.0.0",
|
||||
"is-electron": "^2.2.0",
|
||||
"jsonpath": "^1.0.2",
|
||||
"jsonpath-plus": "^4.0.0",
|
||||
"minimist": "^1.2.5",
|
||||
"node-fetch": "^2.6.0",
|
||||
"secure-ls": "^1.2.6",
|
||||
|
|
|
@ -21,10 +21,19 @@
|
|||
},
|
||||
"level": {
|
||||
"tommy": [
|
||||
"Title",
|
||||
"Title",
|
||||
"Part Duration"
|
||||
|
||||
],
|
||||
|
||||
|
||||
|
||||
|
||||
],
|
||||
"Inspect": [
|
||||
"Part Duration"
|
||||
|
||||
|
||||
],
|
||||
"level1": [
|
||||
"Media ID", "Title", "Sort title",
|
||||
"Studio", "Content Rating", "Year",
|
||||
|
@ -187,49 +196,49 @@
|
|||
"fields": {
|
||||
"Media ID":
|
||||
{
|
||||
"key": "ratingKey",
|
||||
"key": "$.ratingKey",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Title":
|
||||
{
|
||||
"key": "title",
|
||||
"key": "$.title",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Sort title":
|
||||
{
|
||||
"key": "titleSort",
|
||||
"key": "$.titleSort",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Studio":
|
||||
{
|
||||
"key": "studio",
|
||||
"key": "$.studio",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Content Rating":
|
||||
{
|
||||
"key": "contentRating",
|
||||
"key": "$.contentRating",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Year":
|
||||
{
|
||||
"key": "year",
|
||||
"key": "$.year",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Rating":
|
||||
{
|
||||
"key": "rating",
|
||||
"key": "$.rating",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
"Summary":
|
||||
{
|
||||
"key": "summary",
|
||||
"key": "$.summary",
|
||||
"call": 1,
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -283,7 +292,7 @@
|
|||
},
|
||||
"Duration":
|
||||
{
|
||||
"key": "$..duration",
|
||||
"key": "$.duration",
|
||||
"call": 1,
|
||||
"type": "time"
|
||||
},
|
||||
|
@ -396,13 +405,13 @@
|
|||
},
|
||||
"Added":
|
||||
{
|
||||
"key": "$..addedAt",
|
||||
"key": "$.addedAt",
|
||||
"call": 1,
|
||||
"type": "datetime"
|
||||
},
|
||||
"Updated":
|
||||
{
|
||||
"key": "$..updatedAt",
|
||||
"key": "$.updatedAt",
|
||||
"call": 1,
|
||||
"type": "datetime"
|
||||
},
|
||||
|
@ -627,6 +636,7 @@
|
|||
"key": "$.Media[*].Part[*]",
|
||||
"call": 2,
|
||||
"type": "array",
|
||||
"postProcess": true,
|
||||
"subtype": "string",
|
||||
"subkey": "$.size"
|
||||
},
|
||||
|
@ -634,8 +644,7 @@
|
|||
{
|
||||
"key": "$.Media[*].Part[*]",
|
||||
"call": 2,
|
||||
"type": "array",
|
||||
"postProcess": true,
|
||||
"type": "array",
|
||||
"subtype": "string",
|
||||
"subkey": "$.size"
|
||||
},
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
var def = JSON.parse(JSON.stringify(require('./definitions.json')));
|
||||
const log = require('electron-log');
|
||||
import {wtconfig, wtutils} from '../../../wtutils'
|
||||
log.transports.console.level = false;
|
||||
|
||||
import {wtconfig, wtutils} from '../../../wtutils'
|
||||
import filesize from 'filesize';
|
||||
var path = require("path");
|
||||
|
||||
const fetch = require('node-fetch');
|
||||
const jp = require('jsonpath')
|
||||
//const {jp} = require('jsonpath');
|
||||
|
||||
const {JSONPath} = require('jsonpath-plus');
|
||||
|
||||
const et = new class ET {
|
||||
constructor() {
|
||||
|
@ -12,7 +17,7 @@ const et = new class ET {
|
|||
|
||||
async getItemData(baseURL, accessToken, element)
|
||||
{
|
||||
const url = baseURL + element + '?checkFiles=1&includeRelated=1&includeExtras=1&includeBandwidths=1&includeChapters=1';
|
||||
const url = baseURL + element + '?checkFiles=1&includeRelated=0&includeExtras=1&includeBandwidths=1&includeChapters=1';
|
||||
var headers = {
|
||||
"Accept": "application/json",
|
||||
"X-Plex-Token": accessToken
|
||||
|
@ -27,8 +32,7 @@ const et = new class ET {
|
|||
|
||||
getRealLevelName(level, libType) {
|
||||
// First get the real name of the level, and not just the display name
|
||||
const levelName = def[libType]['levels'][level]
|
||||
log.debug(`ET LevelName: ${levelName}`)
|
||||
const levelName = def[libType]['levels'][level]
|
||||
return levelName
|
||||
}
|
||||
|
||||
|
@ -136,9 +140,9 @@ const et = new class ET {
|
|||
const result = {}
|
||||
let response = await fetch(url, { method: 'GET', headers: headers});
|
||||
let resp = await response.json();
|
||||
const respJSON = await Promise.resolve(resp)
|
||||
result['size'] = jp.value(respJSON, '$.MediaContainer.totalSize');
|
||||
result['name'] = jp.value(respJSON, '$.MediaContainer.librarySectionTitle');
|
||||
const respJSON = await Promise.resolve(resp)
|
||||
result['size'] = JSONPath({path: '$.MediaContainer.totalSize', json: respJSON});
|
||||
result['name'] = JSONPath({path: '$.MediaContainer.librarySectionTitle', json: respJSON});
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
@ -213,20 +217,49 @@ const excel2 = new class Excel {
|
|||
}
|
||||
|
||||
async postProcess(name, val){
|
||||
log.debug(`Start postProcess. name: ${name} - val: ${val}`)
|
||||
var retVal
|
||||
switch ( String(name) ){
|
||||
|
||||
case "MetaDB Link":
|
||||
retVal = val.split("?")[0];
|
||||
break;
|
||||
case "MetaData Language":
|
||||
retVal = val.split("=")[1];
|
||||
break;
|
||||
default:
|
||||
console.log('Ged NO HIT:' + name + 'END')
|
||||
break;
|
||||
}
|
||||
log.silly(`Start postProcess. name: ${name} - val: ${val}`)
|
||||
const valArray = val.split(wtconfig.get('ET.ArraySep', ' - '))
|
||||
let retArray = []
|
||||
let x, retVal
|
||||
try {
|
||||
switch ( String(name) ){
|
||||
case "MetaDB Link":
|
||||
for (x=0; x<valArray.length; x++) {
|
||||
retArray.push(path.basename(valArray[x].split("?")[0]))
|
||||
}
|
||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
case "MetaData Language":
|
||||
for (x=0; x<valArray.length; x++) {
|
||||
retArray.push(path.basename(valArray[x].split("=")[1]))
|
||||
}
|
||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
case "Part File":
|
||||
for (x=0; x<valArray.length; x++) {
|
||||
retArray.push(path.basename(valArray[x]))
|
||||
}
|
||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
case "Part File Path":
|
||||
for (x=0; x<valArray.length; x++) {
|
||||
retArray.push(path.dirname(valArray[x]))
|
||||
}
|
||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
case "Part Size":
|
||||
for (x=0; x<valArray.length; x++) {
|
||||
retArray.push(filesize(valArray[x]))
|
||||
}
|
||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
default:
|
||||
log.error(`postProcess no hit for: ${name}`)
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
retVal = 'ERROR'
|
||||
}
|
||||
return await retVal;
|
||||
}
|
||||
|
||||
|
@ -234,74 +267,71 @@ const excel2 = new class Excel {
|
|||
log.debug(`Start addRowToSheet. libType: ${libType} - level: ${level}`)
|
||||
// Placeholder for row
|
||||
let row = []
|
||||
let date, year, month, day, hours, minutes, seconds
|
||||
|
||||
const fields = et.getFields( libType, level)
|
||||
|
||||
let date, year, month, day, hours, minutes, seconds
|
||||
const fields = et.getFields( libType, level)
|
||||
const rowentry = {}
|
||||
let lookup, val, array, i, valArray, valArrayVal, subType, subKey
|
||||
|
||||
let lookup, val, array, i, valArray, valArrayVal, subType, subKey
|
||||
for (var x=0; x<fields.length; x++) {
|
||||
var name = Object.keys(fields[x]);
|
||||
lookup = jp.value(fields[x], '$..key')
|
||||
switch(jp.value(fields[x], '$..type')) {
|
||||
case "string":
|
||||
val = jp.value(data, lookup);
|
||||
var name = Object.keys(fields[x]);
|
||||
lookup = JSONPath({path: '$..key', json: fields[x]})[0];
|
||||
switch(String(JSONPath({path: '$..type', json: fields[x]}))) {
|
||||
case "string":
|
||||
val = JSONPath({path: String(lookup), json: data})[0];
|
||||
// Make N/A if not found
|
||||
if (val == null)
|
||||
{
|
||||
val = wtconfig.get('ET.NotAvail', 'N/A')
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "array":
|
||||
array = jp.query(data, lookup);
|
||||
valArray = []
|
||||
for (i=0; i<array.length; i++) {
|
||||
subType = jp.value(fields[x], '$..subtype')
|
||||
subKey = jp.value(fields[x], '$..subkey')
|
||||
//console.log('Ged 1112233 SubType: ' + subType)
|
||||
switch(subType) {
|
||||
case "string":
|
||||
//valArrayVal = jp.value(fields[x], subKey)
|
||||
valArrayVal = jp.value(array[i], subKey)
|
||||
case "array":
|
||||
array = JSONPath({path: lookup, json: data});
|
||||
valArray = []
|
||||
for (i=0; i<array.length; i++) {
|
||||
subType = JSONPath({path: '$..subtype', json: fields[x]});
|
||||
subKey = JSONPath({path: '$..subkey', json: fields[x]});
|
||||
switch(String(subType)) {
|
||||
case "string":
|
||||
valArrayVal = JSONPath({path: String(subKey), json: array[i]})[0];
|
||||
// Make N/A if not found
|
||||
if (valArrayVal == null || valArrayVal == "")
|
||||
{
|
||||
valArrayVal = wtconfig.get('ET.NotAvail', 'N/A')
|
||||
}
|
||||
break
|
||||
case "time":
|
||||
console.log('Ged ARRAY: ' + JSON.stringify(array[i]))
|
||||
valArrayVal = jp.value(array[i], subKey)
|
||||
break;
|
||||
case "time":
|
||||
valArrayVal = JSONPath({path: String(subKey), json: array[i]});
|
||||
// Make N/A if not found
|
||||
if (valArrayVal == null || valArrayVal == "")
|
||||
{
|
||||
valArrayVal = wtconfig.get('ET.NotAvail', 'N/A')
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<valArrayVal.length; i++) {
|
||||
{
|
||||
const total = valArrayVal.length
|
||||
for (let i=0; i<total; i++) {
|
||||
seconds = '0' + (Math.round(valArrayVal[i]/1000)%60).toString();
|
||||
minutes = '0' + (Math.round((valArrayVal[i]/(1000 * 60))) % 60).toString();
|
||||
hours = (Math.trunc(valArrayVal[i] / (1000 * 60 * 60)) % 24).toString();
|
||||
// Will display time in 10:30:23 format
|
||||
val = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
|
||||
valArrayVal = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
|
||||
}
|
||||
}
|
||||
break
|
||||
break;
|
||||
default:
|
||||
log.error('NO ARRAY HIT (addRowToSheet-array)')
|
||||
}
|
||||
valArray.push(valArrayVal)
|
||||
}
|
||||
val = valArray.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
case "array-count":
|
||||
val = jp.query(data, lookup).length;
|
||||
case "array-count":
|
||||
val = JSONPath({path: String(lookup), json: data}).length;
|
||||
break;
|
||||
case "int":
|
||||
val = jp.query(data, lookup)[0];
|
||||
val = JSONPath({path: String(lookup), json: data})[0];
|
||||
break;
|
||||
case "time":
|
||||
val = jp.value(data, lookup);
|
||||
case "time":
|
||||
val = JSONPath({path: String(lookup), json: data});
|
||||
if ( typeof val !== 'undefined' && val )
|
||||
{
|
||||
seconds = '0' + (Math.round(val/1000)%60).toString();
|
||||
|
@ -315,8 +345,8 @@ const excel2 = new class Excel {
|
|||
val = null
|
||||
}
|
||||
break;
|
||||
case "datetime":
|
||||
val = jp.value(data, lookup);
|
||||
case "datetime":
|
||||
val = JSONPath({path: String(lookup), json: data});
|
||||
if ( typeof val !== 'undefined' && val )
|
||||
{
|
||||
// Create a new JavaScript Date object based on the timestamp
|
||||
|
@ -335,97 +365,23 @@ const excel2 = new class Excel {
|
|||
{
|
||||
val = null
|
||||
}
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
log.error(`No Hit addRowToSheet for ${String(JSONPath({path: '$..type', json: fields[x]}))}`)
|
||||
}
|
||||
if ( jp.value(fields[x], '$..postProcess') == true)
|
||||
{
|
||||
val = await this.postProcess(name, val);
|
||||
let doPostProc = JSONPath({path: '$..postProcess', json: fields[x]})
|
||||
if ( doPostProc == 'true')
|
||||
{
|
||||
val = await this.postProcess(name, val);
|
||||
}
|
||||
rowentry[name[0]] = val
|
||||
}
|
||||
}
|
||||
row.push(rowentry)
|
||||
row.forEach(element => {
|
||||
excel2.AddRow(sheet, element)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* console.log('Ged Cava1: ' + JSON.stringify(keyVal))
|
||||
|
||||
for (var i=0; i<keyVal.length; i++) {
|
||||
// Get type
|
||||
|
||||
console.log('Ged Field Type: ' + Object.values(keyVal[i])[0][1]);
|
||||
switch(Object.values(keyVal[i])[0][1]) {
|
||||
case "string":
|
||||
console.log('Ged Item: ' + JSON.stringify(data))
|
||||
val = jp.value(data, Object.values(keyVal[i])[0][0]);
|
||||
console.log('Ged1 Result: ' + val)
|
||||
break;
|
||||
case "array":
|
||||
// Get Items
|
||||
console.log('Ged123 Item: ' + JSON.stringify(data))
|
||||
console.log('Ged123 keyVal: ' + JSON.stringify(keyVal[i]))
|
||||
val = jp.query(data, Object.values(keyVal[i])[0][0]);
|
||||
console.log('Ged123 VAL: ' + JSON.stringify(val))
|
||||
// Seperate as wanted
|
||||
val = val.join(wtconfig.get('ET.ArraySep', ' - '))
|
||||
break;
|
||||
case "int":
|
||||
val = '';
|
||||
break;
|
||||
case "time":
|
||||
val = jp.value(data, Object.values(keyVal[i])[0][0]);
|
||||
if ( typeof val !== 'undefined' && val )
|
||||
{
|
||||
seconds = '0' + (Math.round(val/1000)%60).toString();
|
||||
minutes = '0' + (Math.round((val/(1000 * 60))) % 60).toString();
|
||||
hours = (Math.trunc(val / (1000 * 60 * 60)) % 24).toString();
|
||||
// Will display time in 10:30:23 format
|
||||
val = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = null
|
||||
}
|
||||
break;
|
||||
|
||||
case "datetime":
|
||||
val = jp.value(data, Object.values(keyVal[i])[0][0]);
|
||||
if ( typeof val !== 'undefined' && val )
|
||||
{
|
||||
// Create a new JavaScript Date object based on the timestamp
|
||||
// multiplied by 1000 so that the argument is in milliseconds, not seconds.
|
||||
date = new Date(val * 1000);
|
||||
year = date.getFullYear().toString();
|
||||
month = ('0' + date.getMonth().toString()).substr(-2);
|
||||
day = ('0' + date.getDate().toString()).substr(-2);
|
||||
hours = date.getHours();
|
||||
minutes = "0" + date.getMinutes();
|
||||
seconds = "0" + date.getSeconds();
|
||||
// Will display time in 10:30:23 format
|
||||
val = year+'-'+month+'-'+day+' '+hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = null
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (val == null)
|
||||
{
|
||||
val = wtconfig.get('ET.NotAvail', 'N/A')
|
||||
}
|
||||
rowentry[Object.keys(keyVal[i])] = val
|
||||
}
|
||||
row.push(rowentry)
|
||||
|
||||
//console.log('Entire rows: ' + JSON.stringify(row))
|
||||
row.forEach(element => {
|
||||
excel2.AddRow(sheet, element)
|
||||
});
|
||||
} */
|
||||
});
|
||||
log.silly(`End addRowToSheet. Row: ${JSON.stringify(row)}`)
|
||||
}
|
||||
|
||||
async createOutFile( libName, level, libType, outType, data, baseURL, accessToken )
|
||||
{
|
||||
|
@ -439,27 +395,27 @@ const excel2 = new class Excel {
|
|||
// Now we need to find out how many calls to make
|
||||
const call = await et.getLevelCall(libType, level)
|
||||
if ( call == 1 )
|
||||
{
|
||||
// Single call needed, so simply pass along the individual items
|
||||
const items = jp.nodes(data, '$.MediaContainer.Metadata[*]')
|
||||
for (var x=0; x<items.length; x++) {
|
||||
await excel2.addRowToSheet(sheet, libType, level, items[x]['value'])
|
||||
{
|
||||
// Single call needed, so simply pass along the individual items
|
||||
var items = await JSONPath({path: "$.MediaContainer.Metadata[*]", json: data});
|
||||
for (var x=0; x<items.length; x++) {
|
||||
await excel2.addRowToSheet(sheet, libType, level, items[x])
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get rating key for each item
|
||||
const urls = jp.query(data, '$.MediaContainer.Metadata[*].key');
|
||||
// Get rating key for each item
|
||||
const urls = JSONPath({path: '$.MediaContainer.Metadata[*].key', json: data});
|
||||
log.verbose('Items to lookup are: ' + urls)
|
||||
|
||||
for (const url of urls) {
|
||||
const contents = await et.getItemData(baseURL, accessToken, url);
|
||||
const items = jp.nodes(contents, '$.MediaContainer.Metadata[*]')
|
||||
const contents = await et.getItemData(baseURL, accessToken, url);
|
||||
const items = await JSONPath({path: '$.MediaContainer.Metadata[*]', json: contents});
|
||||
for (var y=0; y<items.length; y++) {
|
||||
excel2.addRowToSheet(sheet, libType, level, items[y]['value'])
|
||||
await excel2.addRowToSheet(sheet, libType, level, items[y])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Save Excel file
|
||||
const result = await excel2.SaveWorkbook(workBook, libName, level, 'xlsx')
|
||||
return result
|
||||
|
|
21
src/main.js
21
src/main.js
|
@ -27,8 +27,10 @@ const log = require('electron-log');
|
|||
log.transports.file.level = wtconfig.get('Log.fileLevel', 'info');
|
||||
// Default console level is Silly, since used by us
|
||||
log.transports.console.level = wtconfig.get('Log.consoleLevel', 'silly');
|
||||
|
||||
|
||||
log.transports.file.fileName = wtutils.AppName;
|
||||
// Set logfile to 1Mb
|
||||
// Set logfile to 10Mb
|
||||
log.transports.file.maxSize = wtconfig.get('Log.maxSize', 1048576);
|
||||
|
||||
|
||||
|
@ -37,11 +39,8 @@ log.info('*********************************')
|
|||
log.info('Starting ' + wtutils.AppName + ' Version:' + wtutils.AppVersion);
|
||||
// Logging ended
|
||||
|
||||
//wtutils.MoveToHome();
|
||||
|
||||
// Get saved language to use, and default to en
|
||||
i18n.locale = wtconfig.get('general.language', 'en')
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
// App Menu Bar
|
||||
|
@ -53,7 +52,7 @@ log.info('App Menu builded')
|
|||
|
||||
|
||||
console.log('*********** Ged CASPER start dialog ************');
|
||||
console.log('Se main.js linie 54 for at lave en dialog i ET, så');
|
||||
console.log('Se main.js linie 61 for at lave en dialog i ET, så');
|
||||
console.log('vi kan gemme std. output dir');
|
||||
console.log('Gemmes med wtconfig.set("ET.OutPath", <sti til dir>)');
|
||||
|
||||
|
@ -75,7 +74,8 @@ if (outDir)
|
|||
|
||||
// We export library named "Ged" of the type movie with a level of "Level 2"
|
||||
const libName = 'Ged'
|
||||
const level = 'Tommy'
|
||||
//const level = 'Tommy'
|
||||
const level = 'Level 6'
|
||||
const libType = 'movie'
|
||||
|
||||
libType
|
||||
|
@ -121,7 +121,7 @@ const testimp3 = require('./components/modules/ExportTools/testimp3.json')
|
|||
const testimp = require('./components/modules/ExportTools/testimp.json')
|
||||
const testimp1 = require('./components/modules/ExportTools/testimp1.json')
|
||||
const AllMovies = require('./components/modules/ExportTools/AllMovies.json')
|
||||
|
||||
const Fast = require('./components/modules/ExportTools/2Fast.json')
|
||||
|
||||
// Just use to avoid errors later
|
||||
testimp4
|
||||
|
@ -129,12 +129,15 @@ testimp3
|
|||
testimp
|
||||
testimp1
|
||||
AllMovies
|
||||
Fast
|
||||
|
||||
// EXCEL Stuff
|
||||
|
||||
// Add a couple of Rows
|
||||
excel2.createOutFile( libName, level, libType, 'xlsx', testimp3, baseURI, accessToken );
|
||||
//excel2.createOutFile( libName, level, libType, 'xlsx', AllMovies, baseURI, accessToken );
|
||||
//excel2.createOutFile( libName, level, libType, 'xlsx', testimp1, baseURI, accessToken );
|
||||
//excel2.createOutFile( libName, level, libType, 'xlsx', testimp3, baseURI, accessToken );
|
||||
//excel2.createOutFile( libName, level, libType, 'xlsx', Fast, baseURI, accessToken );
|
||||
excel2.createOutFile( libName, level, libType, 'xlsx', AllMovies, baseURI, accessToken );
|
||||
|
||||
new Vue({
|
||||
render: h => h(App),
|
||||
|
|
Loading…
Reference in a new issue