A bit more for Excel generation

This commit is contained in:
UKDTOM 2020-06-21 20:17:45 +02:00
parent 25d28dd63a
commit ba5a58c9af
8 changed files with 17903 additions and 43 deletions

BIN
ET-Fields-Movies.ods Normal file

Binary file not shown.

37
package-lock.json generated
View file

@ -2642,6 +2642,14 @@
"file-uri-to-path": "1.0.0"
}
},
"biskviit": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/biskviit/-/biskviit-1.0.1.tgz",
"integrity": "sha1-A3oM1LcbnjMf2QoRIt4X3EnkIKc=",
"requires": {
"psl": "^1.1.7"
}
},
"bl": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
@ -5577,6 +5585,14 @@
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=",
"dev": true
},
"encoding": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
"requires": {
"iconv-lite": "~0.4.13"
}
},
"end-of-stream": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
@ -6480,6 +6496,15 @@
"pend": "~1.2.0"
}
},
"fetch": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fetch/-/fetch-1.1.0.tgz",
"integrity": "sha1-CoJ58Gvjf58Ou1Z1YKMKSA2lmi4=",
"requires": {
"biskviit": "1.0.1",
"encoding": "0.1.12"
}
},
"figgy-pudding": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/figgy-pudding/-/figgy-pudding-3.5.2.tgz",
@ -7493,7 +7518,6 @@
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"dev": true,
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
@ -9173,6 +9197,11 @@
"lower-case": "^1.1.1"
}
},
"node-fetch": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz",
"integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA=="
},
"node-forge": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.9.0.tgz",
@ -10715,8 +10744,7 @@
"psl": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==",
"dev": true
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
},
"public-encrypt": {
"version": "4.0.3",
@ -11450,8 +11478,7 @@
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"dev": true
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"sanitize-filename": {
"version": "1.6.3",

View file

@ -26,10 +26,12 @@
"electron-log": "^4.2.0",
"electron-store": "^5.1.1",
"exceljs": "^4.0.1",
"fetch": "^1.1.0",
"file-saver": "^2.0.2",
"is-electron": "^2.2.0",
"jsonpath": "^1.0.2",
"minimist": "^1.2.5",
"node-fetch": "^2.6.0",
"secure-ls": "^1.2.6",
"vue": "^2.6.11",
"vue-i18n": "^8.18.1",

View file

@ -11,12 +11,12 @@
},
"level": {
"testtommy": [
"Sort title",
"View Count", "Last Viewed at",
"Media ID", "Title", "Sort title", "Studio",
"Content Rating", "Year", "Rating",
"View Count",
"Writers",
"Country", "Duration", "Directors",
"Roles", "User Rating"
"Roles"
],
"level1": [
"Media ID", "Title", "Sort title",
@ -228,7 +228,7 @@
},
"Genre":
{
"key": "['Genre']['tag']",
"key": "$.Genre[*].tag",
"call": 1,
"type": "array"
},
@ -258,13 +258,13 @@
},
"Writers":
{
"key": "['Writer']['tag']",
"key": "$.Writer[*].tag",
"call": 1,
"type": "array"
},
"Country":
{
"key": "['Country']['tag']",
"key": "$.Country[*].tag",
"call": 1,
"type": "array"
},
@ -276,13 +276,13 @@
},
"Directors":
{
"key": "['Director']['tag']",
"key": "$.Director[*].tag",
"call": 1,
"type": "array"
},
"Roles":
{
"key": "['Role']['tag']",
"key": "$.Role[*].tag",
"call": 1,
"type": "array"
},
@ -300,19 +300,19 @@
},
"Labels":
{
"key": "['Label']['tag']",
"key": "$.Label[*].tag",
"call": 2,
"type": "array"
},
"Locked Fields":
{
"key": "['Field']['name']",
"key": "$.Field[*].tag",
"call": 2,
"type": "array"
},
"Extras":
{
"key": "['Extras']['size']",
"key": "$.Extras[*].size",
"call": 2,
"type": "array"
},
@ -373,13 +373,13 @@
"Added":
{
"key": "['addedAt']",
"call": 2,
"call": 1,
"type": "datetime"
},
"Updated":
{
"key": "['updatedAt']",
"call": 2,
"call": 1,
"type": "datetime"
},
"Audio Languages":

View file

@ -1,8 +1,25 @@
var def = JSON.parse(JSON.stringify(require('./definitions.json')));
const log = require('electron-log');
import {wtconfig, wtutils} from '../../../wtutils'
const fetch = require('node-fetch');
const jp = require('jsonpath')
/* async function getSectionNameAndSize(baseURI, accessToken, sectionID)
{
const url = baseURI + '/library/sections/' + sectionID + '/all?X-Plex-Container-Start=0&X-Plex-Container-Size=0'
var headers = {
"Accept": "application/json",
"X-Plex-Token": accessToken
}
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');
console.log('GED RESULT: ' + JSON.stringify(result))
return result
} */
const et = new class ET {
constructor() {
@ -62,6 +79,10 @@ const et = new class ET {
return def[libType]['fields'][fieldName]['key']
}
getFieldType(libType, fieldName) {
return def[libType]['fields'][fieldName]['type']
}
getFieldsKeyVal( libType, level) {
// Get fields for level
const fields = et.getLevelFields(level, libType)
@ -73,6 +94,38 @@ const et = new class ET {
});
return out
}
getFieldsKeyValType( libType, level) {
// Get field and type for level
const fields = et.getLevelFields(level, libType)
const out = []
fields.forEach(element => {
const item = {}
const vals = []
vals.push(et.getFieldKey(libType, element))
vals.push(et.getFieldType(libType, element))
item[element] = vals
out.push(item)
});
return out
}
async getSectionNameSize(baseURI, accessToken, sectionID) {
//getSectionNameAndSize(baseURI, accessToken, sectionID)
const url = baseURI + '/library/sections/' + sectionID + '/all?X-Plex-Container-Start=0&X-Plex-Container-Size=0'
var headers = {
"Accept": "application/json",
"X-Plex-Token": accessToken
}
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');
console.log('GED RESULT: ' + JSON.stringify(result))
return result
}
}
const excel = new class Excel {
@ -92,10 +145,8 @@ const excel = new class Excel {
//let key
// Get level fields
const fields = et.getLevelFields(Level, libType)
for (var i=0; i<fields.length; i++) {
//key = et.getFieldKey(libType, fields[i])
//log.debug('Column: ' + fields[i] + ' - ' + key)
log.debug('Column: ' + fields[i] + ' - ' + fields[i])
for (var i=0; i<fields.length; i++) {
//log.debug('Column: ' + fields[i] + ' - ' + fields[i])
//let column = { header: Level[i], key: 'id', width: 10 }
let column = { header: fields[i], key: fields[i] }
columns.push(column)
@ -145,33 +196,108 @@ const excel = new class Excel {
}
addToSheet(sheet, libType, level, data) {
console.log('Start AddToSheet')
const jp = require('jsonpath')
console.log('Start AddToSheet')
// Placeholder for row
let row = []
let date, year, month, day, hours, minutes, seconds
// Need to find the fields and keys we'll
// query the data for
const keyVal = et.getFieldsKeyVal( libType, level)
const keyVal = et.getFieldsKeyValType( libType, level)
// Now get the medias
const nodes = jp.nodes(data, '$.MediaContainer.Metadata[*]')
for (var x=0; x<nodes.length; x++) {
const mediaItem = nodes[x].value
const rowentry = {}
for (var i=0; i<keyVal.length; i++) {
let val = jp.value(mediaItem, Object.values(keyVal[i]))
for (var i=0; i<keyVal.length; i++) {
const monthsArr = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
// Get type
let val
switch(Object.values(keyVal[i])[0][1]) {
case "string":
val = jp.value(mediaItem, Object.values(keyVal[i])[0][0]);
break;
case "array":
// Get Items
val = jp.query(mediaItem, Object.values(keyVal[i])[0][0]);
// Seperate as wanted
val = val.join(wtconfig.get('ET.ArraySep', ' - '))
break;
case "int":
val = '';
break;
case "time":
val = jp.value(mediaItem, 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(mediaItem, 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();
month = monthsArr[date.getMonth()];
day = date.getDate();
hours = date.getHours();
minutes = "0" + date.getMinutes();
seconds = "0" + date.getSeconds();
// Will display time in 10:30:23 format
val = month+'-'+day+'-'+year+' '+hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
}
else
{
val = null
}
break;
}
//console.log('Ged Value: ' + val)
if (val == null)
{
val = wtconfig.get('ET.NotAvail', 'N/A')
}
console.log('Media Item: ' + Object.keys(keyVal[i]) + ' has a value of: ' + val)
//console.log('Media Item: ' + Object.keys(keyVal[i]) + ' has a value of: ' + val)
rowentry[Object.keys(keyVal[i])] = val
}
row.push(rowentry)
}
console.log('Entire rows: ' + JSON.stringify(row))
//console.log('Entire rows: ' + JSON.stringify(row))
row.forEach(element => {
excel.AddRow(sheet, element)
});
}
exportMedia(baseURI, accessToken, level, sectionID) {
console.log('GED exportMedia Start');
console.log('GED exportMedia baseURI: ' + baseURI);
// Get section name and size
let result
//var ged = et.getSectionNameSize(baseURI, accessToken, sectionID)
et.getSectionNameSize(baseURI, accessToken, sectionID)
.then(function(values) {
console.log('GED Result returned: ' + JSON.stringify(values));
result = values
}).catch(function(error) {
console.error(error);
});
console.log('GED Result Outside returned: ' + JSON.stringify(result))
level
}
}

View file

@ -123,6 +123,7 @@
"originallyAvailableAt": "2007-04-26",
"addedAt": 1186162396,
"updatedAt": 1575678555,
"lastViewedAt": 1575678555,
"audienceRatingImage": "rottentomatoes://image.rating.upright",
"chapterSource": "agent",
"primaryExtraKey": "/library/metadata/9454",

File diff suppressed because it is too large Load diff

View file

@ -67,26 +67,25 @@ if (outDir)
// ET-EXCEL STUFF
// We export library named "Ged" of the type movie with a level of "Level 1"
// We export library named "Ged" of the type movie with a level of "Level 2"
const libName = 'Ged'
//const level = 'Test Tommy'
const level = 'Level 2'
const libType = 'movie'
// Real stuff to use
// ET Stuff
import {et, excel} from './components/modules/ExportTools/et'
// Get possible levels for movie
console.log('Possible levels key/val are: ' + JSON.stringify(et.getLevels(libType)))
console.log('Possible levels key only names: ' + et.getLevelKeys(libType))
console.log('RealLevelName: ' + et.getRealLevelName(level, libType))
console.log('Fields in this level: ' + JSON.stringify(et.getLevelFields(level, libType)))
console.log('Fields in this level sorted: ' + JSON.stringify(et.getLevelFields(level, libType).sort()))
console.log('GetLevel calls: ' + et.getLevelCall(libType, level) )
import {excel} from './components/modules/ExportTools/et'
const testimp3 = require('./components/modules/ExportTools/testimp3.json')
const testimp = require('./components/modules/ExportTools/testimp.json')
const testimp1 = require('./components/modules/ExportTools/testimp1.json')
// Just use to avoid errors later
testimp3
testimp
testimp1
// EXCEL Stuff
@ -97,10 +96,19 @@ const Sheet = excel.NewSheet(WorkBook, libName, level)
// Now add the header column
excel.AddHeader(Sheet, level, libType)
// Add a couple of Rows
excel.addToSheet(Sheet, libType, level, testimp)
//excel.addToSheet(Sheet, libType, level, testimp3)
//excel.addToSheet(Sheet, libType, level, testimp)
excel.addToSheet(Sheet, libType, level, testimp1)
// Save Excel file
excel.SaveWorkbook(WorkBook, libName, level, 'xlsx')
//const baseURI = wtconfig.get('Developer.baseURI', 'NO SERVER URI');
//const accessToken = wtconfig.get('Developer.accessToken', 'NO SERVER TOKEN');
//const sectionID = 4;
//excel.exportMedia(baseURI, accessToken, level, sectionID)
new Vue({
render: h => h(App),
router: router,