mirror of
https://github.com/WebTools-NG/WebTools-NG
synced 2024-11-26 21:10:19 +00:00
WIP, and fiex #418
This commit is contained in:
parent
7db9879551
commit
b3a166793d
3 changed files with 76 additions and 65 deletions
|
@ -1233,7 +1233,7 @@
|
||||||
"TMDB ID":
|
"TMDB ID":
|
||||||
{
|
{
|
||||||
"key": "$.Guid[*]",
|
"key": "$.Guid[*]",
|
||||||
"call": 1,
|
"call": 2,
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"subtype": "string",
|
"subtype": "string",
|
||||||
"subkey": "$.id",
|
"subkey": "$.id",
|
||||||
|
@ -1242,7 +1242,7 @@
|
||||||
"TMDB Link":
|
"TMDB Link":
|
||||||
{
|
{
|
||||||
"key": "$.Guid[*]",
|
"key": "$.Guid[*]",
|
||||||
"call": 1,
|
"call": 2,
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"subtype": "string",
|
"subtype": "string",
|
||||||
"subkey": "$.id",
|
"subkey": "$.id",
|
||||||
|
|
|
@ -13,7 +13,13 @@ const csv = new class CSV {
|
||||||
|
|
||||||
async addHeaderToTmp({ stream: stream, item: item})
|
async addHeaderToTmp({ stream: stream, item: item})
|
||||||
{
|
{
|
||||||
const strHeader = item.join(wtconfig.get('ET.ColumnSep', ','));
|
// Walk each item, and add Qualifier
|
||||||
|
let headerArray = [];
|
||||||
|
let x = 0;
|
||||||
|
for (x=0; x<item.length; x++) {
|
||||||
|
headerArray.push(wtconfig.get('ET.TextQualifierCSV', "\"") + item[x] + wtconfig.get('ET.TextQualifierCSV', "\""));
|
||||||
|
}
|
||||||
|
const strHeader = headerArray.join(wtconfig.get('ET.ColumnSep', ','));
|
||||||
// Add the header
|
// Add the header
|
||||||
await stream.write( strHeader + "\n");
|
await stream.write( strHeader + "\n");
|
||||||
log.info(`Added CSV Header as: ${strHeader}`);
|
log.info(`Added CSV Header as: ${strHeader}`);
|
||||||
|
|
|
@ -26,20 +26,44 @@ function isEmptyObj(obj) {
|
||||||
return !Object.keys(obj).length > 0;
|
return !Object.keys(obj).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set Qualifier
|
// Set Qualifier
|
||||||
function setQualifier( {str:str})
|
function setQualifier( {str:str})
|
||||||
{
|
{
|
||||||
|
const validQ = ["`", "'", "\""];
|
||||||
log.silly(`etHelper (setQualifier): String is: ${str}`);
|
log.silly(`etHelper (setQualifier): String is: ${str}`);
|
||||||
|
//str = str.replaceAll(wtconfig.get('ET.TextQualifierCSV', 'N/A'),``);
|
||||||
|
|
||||||
|
//var count = str.indexOf(wtconfig.get('ET.TextQualifierCSV'))
|
||||||
|
if (str.indexOf(wtconfig.get('ET.TextQualifierCSV', 'N/A')) > 0)
|
||||||
|
{
|
||||||
|
let selectedQ;
|
||||||
|
|
||||||
|
for(const val of validQ) {
|
||||||
|
if ( val != wtconfig.get('ET.TextQualifierCSV', 'N/A'))
|
||||||
|
{
|
||||||
|
selectedQ = val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
log.silly(`etHelper (setQualifier) string contained Qualifier`);
|
||||||
|
console.log('Ged 2-0 str now: ' + str)
|
||||||
|
console.log('Ged 2-1 str after: ' + str.replaceAll(wtconfig.get('ET.TextQualifierCSV'), selectedQ))
|
||||||
|
|
||||||
|
str = str.replaceAll(wtconfig.get('ET.TextQualifierCSV'), selectedQ);
|
||||||
|
|
||||||
|
|
||||||
|
console.log('Ged 2-2 str Now: ' + str)
|
||||||
|
//console.log('Ged 3-0 Count: ' + count)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (wtconfig.get('ET.TextQualifierCSV', 'N/A') == '"')
|
if (wtconfig.get('ET.TextQualifierCSV', 'N/A') == '"')
|
||||||
{
|
{
|
||||||
str = `"${str}"`
|
str = `"${str}"`
|
||||||
}
|
}
|
||||||
else if (wtconfig.get('ET.TextQualifierCSV', 'N/A') == wtconfig.get('ET.NotAvail', 'N/A'))
|
|
||||||
{
|
|
||||||
console.log('Ged 6 We got N/A')
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
str = `${wtconfig.get('ET.TextQualifierCSV', 'N/A')}${str}${wtconfig.get('ET.TextQualifierCSV', 'N/A')}`
|
str = `${wtconfig.get('ET.TextQualifierCSV', 'N/A')}${str}${wtconfig.get('ET.TextQualifierCSV', 'N/A')}`
|
||||||
|
@ -48,31 +72,6 @@ function setQualifier( {str:str})
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Adds the String Qualifier if needed
|
|
||||||
function setStrSeperator( {str: str})
|
|
||||||
{
|
|
||||||
if ( wtconfig.get('ET.TextQualifierCSV') )
|
|
||||||
{
|
|
||||||
if ( wtconfig.get('ET.TextQualifierCSV') != ' ')
|
|
||||||
{
|
|
||||||
log.silly(`etHelper (setStrSeperator): Returning: ${wtconfig.get('ET.TextQualifierCSV')}${str}${wtconfig.get('ET.TextQualifierCSV')}`);
|
|
||||||
return wtconfig.get('ET.TextQualifierCSV') + str + wtconfig.get('ET.TextQualifierCSV');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.silly(`etHelper (setStrSeperator) No sep, so returning ${str}`);
|
|
||||||
return str; }
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
log.error(`etHelper (setStrSeperator): UPS no qualifier, so returning nothing`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
const etHelper = new class ETHELPER {
|
const etHelper = new class ETHELPER {
|
||||||
|
@ -220,7 +219,9 @@ const etHelper = new class ETHELPER {
|
||||||
}
|
}
|
||||||
|
|
||||||
async postProcess( {name, val, title=""} ){
|
async postProcess( {name, val, title=""} ){
|
||||||
log.silly(`ETHelper(postProcess): Val is: ${JSON.stringify(val)}`)
|
log.silly(`ETHelper(postProcess): Val is: ${JSON.stringify(val)}`);
|
||||||
|
log.silly(`ETHelper(postProcess): name is: ${name}`);
|
||||||
|
log.silly(`ETHelper(postProcess): title is: ${title}`);
|
||||||
let retArray = [];
|
let retArray = [];
|
||||||
let x, retVal, start, strStart, end, result;
|
let x, retVal, start, strStart, end, result;
|
||||||
try {
|
try {
|
||||||
|
@ -240,13 +241,13 @@ const etHelper = new class ETHELPER {
|
||||||
}
|
}
|
||||||
case "Part File":
|
case "Part File":
|
||||||
for (x=0; x<valArray.length; x++) {
|
for (x=0; x<valArray.length; x++) {
|
||||||
retArray.push(path.basename(valArray[x]).slice(0, -1))
|
retArray.push(setQualifier( {str:path.basename(valArray[x]).slice(0, -1)}));
|
||||||
}
|
}
|
||||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' * '))
|
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' * '))
|
||||||
break;
|
break;
|
||||||
case "Part File Path":
|
case "Part File Path":
|
||||||
for (x=0; x<valArray.length; x++) {
|
for (x=0; x<valArray.length; x++) {
|
||||||
retArray.push(path.dirname(valArray[x]).substring(1));
|
retArray.push(setQualifier( {str:path.dirname(valArray[x]).substring(1)}));
|
||||||
}
|
}
|
||||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' * '));
|
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' * '));
|
||||||
break;
|
break;
|
||||||
|
@ -264,7 +265,7 @@ const etHelper = new class ETHELPER {
|
||||||
log.error(`Error getting Part Size was ${error} for ${theSize}`);
|
log.error(`Error getting Part Size was ${error} for ${theSize}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retVal = retArray.join(wtconfig.get('ET.ArraySep', ' * '))
|
retVal = setQualifier( {str:retArray.join(wtconfig.get('ET.ArraySep', ' * '))} );
|
||||||
break;
|
break;
|
||||||
case "Original Title":
|
case "Original Title":
|
||||||
if (wtconfig.get('ET.OrgTitleNull'))
|
if (wtconfig.get('ET.OrgTitleNull'))
|
||||||
|
@ -277,7 +278,7 @@ const etHelper = new class ETHELPER {
|
||||||
// Override with title if not found
|
// Override with title if not found
|
||||||
if (val == compNA)
|
if (val == compNA)
|
||||||
{
|
{
|
||||||
retVal = title;
|
retVal = setQualifier( {str:title} );
|
||||||
}
|
}
|
||||||
else { retVal = val; }
|
else { retVal = val; }
|
||||||
}
|
}
|
||||||
|
@ -423,8 +424,14 @@ const etHelper = new class ETHELPER {
|
||||||
if (end == -1)
|
if (end == -1)
|
||||||
{ result = strStart.substring(7) }
|
{ result = strStart.substring(7) }
|
||||||
else
|
else
|
||||||
{ result = strStart.substring(7, end) }
|
{
|
||||||
retVal = result;
|
result = strStart.substring(7, end)
|
||||||
|
}
|
||||||
|
if (result.endsWith(wtconfig.get('ET.TextQualifierCSV')))
|
||||||
|
{
|
||||||
|
result = result.slice(0,-1);
|
||||||
|
}
|
||||||
|
retVal = setQualifier( {str:result} );
|
||||||
break;
|
break;
|
||||||
case "TVDB ID (Legacy)":
|
case "TVDB ID (Legacy)":
|
||||||
if (val == wtconfig.get('ET.NotAvail'))
|
if (val == wtconfig.get('ET.NotAvail'))
|
||||||
|
@ -476,10 +483,18 @@ const etHelper = new class ETHELPER {
|
||||||
end = strStart.indexOf(wtconfig.get('ET.ArraySep'));
|
end = strStart.indexOf(wtconfig.get('ET.ArraySep'));
|
||||||
result = ''
|
result = ''
|
||||||
if (end == -1)
|
if (end == -1)
|
||||||
{ result = strStart.substring(7) }
|
{
|
||||||
|
result = strStart.substring(7);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{ result = strStart.substring(7, end) }
|
{
|
||||||
retVal = result;
|
result = strStart.substring(7, end)
|
||||||
|
}
|
||||||
|
if (result.endsWith(wtconfig.get('ET.TextQualifierCSV')))
|
||||||
|
{
|
||||||
|
result = result.slice(0,-1);
|
||||||
|
}
|
||||||
|
retVal = setQualifier( {str:result} );
|
||||||
break;
|
break;
|
||||||
case "TMDB Link":
|
case "TMDB Link":
|
||||||
if (val == wtconfig.get('ET.NotAvail'))
|
if (val == wtconfig.get('ET.NotAvail'))
|
||||||
|
@ -495,8 +510,13 @@ const etHelper = new class ETHELPER {
|
||||||
{ result = strStart.substring(7) }
|
{ result = strStart.substring(7) }
|
||||||
else
|
else
|
||||||
{ result = strStart.substring(7, end) }
|
{ result = strStart.substring(7, end) }
|
||||||
|
|
||||||
result = 'https://www.themoviedb.org/movie/' + result;
|
result = 'https://www.themoviedb.org/movie/' + result;
|
||||||
retVal = result;
|
if (result.endsWith(wtconfig.get('ET.TextQualifierCSV')))
|
||||||
|
{
|
||||||
|
result = result.slice(0,-1);
|
||||||
|
}
|
||||||
|
retVal = setQualifier( {str:result} );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log.error(`postProcess no hit for: ${name}`)
|
log.error(`postProcess no hit for: ${name}`)
|
||||||
|
@ -543,17 +563,7 @@ const etHelper = new class ETHELPER {
|
||||||
val = wtconfig.get('ET.NotAvail', 'N/A');
|
val = wtconfig.get('ET.NotAvail', 'N/A');
|
||||||
}
|
}
|
||||||
val = etHelper.isEmpty( { "val": val } );
|
val = etHelper.isEmpty( { "val": val } );
|
||||||
// Remove CR, LineFeed ' and " from the
|
|
||||||
// string if present, and replace with a space
|
|
||||||
console.log('Ged 1 SANITIZE STRING')
|
|
||||||
//val = val.replace(/'|"|\r|\n/g, ' ');
|
|
||||||
|
|
||||||
|
|
||||||
//val = setStrSeperator( {str: val} );
|
|
||||||
|
|
||||||
val = setQualifier( {str: val} );
|
val = setQualifier( {str: val} );
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "array":
|
case "array":
|
||||||
array = JSONPath({path: key, json: data});
|
array = JSONPath({path: key, json: data});
|
||||||
|
@ -569,15 +579,7 @@ const etHelper = new class ETHELPER {
|
||||||
valArrayVal = String(JSONPath({path: String(subKey), json: array[i]}));
|
valArrayVal = String(JSONPath({path: String(subKey), json: array[i]}));
|
||||||
// Make N/A if not found
|
// Make N/A if not found
|
||||||
valArrayVal = this.isEmpty( { val: valArrayVal });
|
valArrayVal = this.isEmpty( { val: valArrayVal });
|
||||||
|
//valArrayVal = setQualifier( {str: valArrayVal} );
|
||||||
|
|
||||||
/* // Remove CR, LineFeed ' and " from the string if present
|
|
||||||
valArrayVal = valArrayVal.replace(/'|"|\r|\n/g, ' ');
|
|
||||||
valArrayVal = setStrSeperator( {str: valArrayVal}); */
|
|
||||||
|
|
||||||
console.log('Ged 2 SANITIZE STRING')
|
|
||||||
valArrayVal = setQualifier( {str: valArrayVal} );
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case "time":
|
case "time":
|
||||||
valArrayVal = JSONPath({path: String(subKey), json: array[i]});
|
valArrayVal = JSONPath({path: String(subKey), json: array[i]});
|
||||||
|
@ -604,6 +606,7 @@ const etHelper = new class ETHELPER {
|
||||||
valArray.push(valArrayVal)
|
valArray.push(valArrayVal)
|
||||||
}
|
}
|
||||||
val = valArray.join(wtconfig.get('ET.ArraySep', ' * '))
|
val = valArray.join(wtconfig.get('ET.ArraySep', ' * '))
|
||||||
|
val = setQualifier( {str: val} );
|
||||||
/* if ( String(subType) == 'string')
|
/* if ( String(subType) == 'string')
|
||||||
{
|
{
|
||||||
val = textSep + val + textSep;
|
val = textSep + val + textSep;
|
||||||
|
@ -631,6 +634,7 @@ const etHelper = new class ETHELPER {
|
||||||
{
|
{
|
||||||
val = wtconfig.get('ET.NotAvail', 'N/A')
|
val = wtconfig.get('ET.NotAvail', 'N/A')
|
||||||
}
|
}
|
||||||
|
val = setQualifier( {str: val} );
|
||||||
break;
|
break;
|
||||||
case "datetime":
|
case "datetime":
|
||||||
//val = JSONPath({path: String(lookup), json: data});
|
//val = JSONPath({path: String(lookup), json: data});
|
||||||
|
@ -653,6 +657,7 @@ const etHelper = new class ETHELPER {
|
||||||
{
|
{
|
||||||
val = wtconfig.get('ET.NotAvail', 'N/A')
|
val = wtconfig.get('ET.NotAvail', 'N/A')
|
||||||
}
|
}
|
||||||
|
val = setQualifier( {str: val} );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( doPostProc )
|
if ( doPostProc )
|
||||||
|
@ -889,7 +894,6 @@ const etHelper = new class ETHELPER {
|
||||||
// Open a file stream
|
// Open a file stream
|
||||||
this.Settings.csvFile = await etHelper.getFileName({ Type: 'csv' });
|
this.Settings.csvFile = await etHelper.getFileName({ Type: 'csv' });
|
||||||
this.Settings.csvStream = fs.createWriteStream(this.Settings.csvFile, {flags:'a'});
|
this.Settings.csvStream = fs.createWriteStream(this.Settings.csvFile, {flags:'a'});
|
||||||
//await this.getFileName({ Library: libName, Level: level, Type: 'tmp', Module: i18n.t('Modules.ET.Name'), exType: exType });
|
|
||||||
await csv.addHeaderToTmp({ stream: this.Settings.csvStream, item: this.Settings.fields});
|
await csv.addHeaderToTmp({ stream: this.Settings.csvStream, item: this.Settings.fields});
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
|
@ -1048,7 +1052,6 @@ const etHelper = new class ETHELPER {
|
||||||
|
|
||||||
getElement(){
|
getElement(){
|
||||||
let element
|
let element
|
||||||
console.log('Ged 12 element sectype: ' + this.Settings.libTypeSec)
|
|
||||||
switch (this.Settings.libTypeSec) {
|
switch (this.Settings.libTypeSec) {
|
||||||
case this.ETmediaType.Playlist_Photo:
|
case this.ETmediaType.Playlist_Photo:
|
||||||
element = `/playlists/${this.Settings.selLibKey}/items`;
|
element = `/playlists/${this.Settings.selLibKey}/items`;
|
||||||
|
@ -1188,6 +1191,8 @@ const etHelper = new class ETHELPER {
|
||||||
log.silly(`etHelper (getLevelFields) Custom level detected as: ${JSON.stringify(levels)}`);
|
log.silly(`etHelper (getLevelFields) Custom level detected as: ${JSON.stringify(levels)}`);
|
||||||
}
|
}
|
||||||
Object.keys(levels).forEach(function(key) {
|
Object.keys(levels).forEach(function(key) {
|
||||||
|
|
||||||
|
//out.push(wtconfig.get(`ET.TextQualifierCSV`, "\"") + levels[key] + wtconfig.get(`ET.TextQualifierCSV`, "\""))
|
||||||
out.push(levels[key])
|
out.push(levels[key])
|
||||||
});
|
});
|
||||||
resolve(out);
|
resolve(out);
|
||||||
|
|
Loading…
Reference in a new issue