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":
|
||||
{
|
||||
"key": "$.Guid[*]",
|
||||
"call": 1,
|
||||
"call": 2,
|
||||
"type": "array",
|
||||
"subtype": "string",
|
||||
"subkey": "$.id",
|
||||
|
@ -1242,7 +1242,7 @@
|
|||
"TMDB Link":
|
||||
{
|
||||
"key": "$.Guid[*]",
|
||||
"call": 1,
|
||||
"call": 2,
|
||||
"type": "array",
|
||||
"subtype": "string",
|
||||
"subkey": "$.id",
|
||||
|
|
|
@ -13,7 +13,13 @@ const csv = new class CSV {
|
|||
|
||||
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
|
||||
await stream.write( strHeader + "\n");
|
||||
log.info(`Added CSV Header as: ${strHeader}`);
|
||||
|
|
|
@ -26,20 +26,44 @@ function isEmptyObj(obj) {
|
|||
return !Object.keys(obj).length > 0;
|
||||
}
|
||||
|
||||
|
||||
// Set Qualifier
|
||||
function setQualifier( {str:str})
|
||||
{
|
||||
const validQ = ["`", "'", "\""];
|
||||
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') == '"')
|
||||
{
|
||||
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
|
||||
{
|
||||
str = `${wtconfig.get('ET.TextQualifierCSV', 'N/A')}${str}${wtconfig.get('ET.TextQualifierCSV', 'N/A')}`
|
||||
|
@ -48,31 +72,6 @@ function setQualifier( {str: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
|
||||
|
||||
const etHelper = new class ETHELPER {
|
||||
|
@ -220,7 +219,9 @@ const etHelper = new class ETHELPER {
|
|||
}
|
||||
|
||||
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 x, retVal, start, strStart, end, result;
|
||||
try {
|
||||
|
@ -240,13 +241,13 @@ const etHelper = new class ETHELPER {
|
|||
}
|
||||
case "Part File":
|
||||
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', ' * '))
|
||||
break;
|
||||
case "Part File Path":
|
||||
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', ' * '));
|
||||
break;
|
||||
|
@ -264,7 +265,7 @@ const etHelper = new class ETHELPER {
|
|||
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;
|
||||
case "Original Title":
|
||||
if (wtconfig.get('ET.OrgTitleNull'))
|
||||
|
@ -277,7 +278,7 @@ const etHelper = new class ETHELPER {
|
|||
// Override with title if not found
|
||||
if (val == compNA)
|
||||
{
|
||||
retVal = title;
|
||||
retVal = setQualifier( {str:title} );
|
||||
}
|
||||
else { retVal = val; }
|
||||
}
|
||||
|
@ -423,8 +424,14 @@ const etHelper = new class ETHELPER {
|
|||
if (end == -1)
|
||||
{ result = strStart.substring(7) }
|
||||
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;
|
||||
case "TVDB ID (Legacy)":
|
||||
if (val == wtconfig.get('ET.NotAvail'))
|
||||
|
@ -476,10 +483,18 @@ const etHelper = new class ETHELPER {
|
|||
end = strStart.indexOf(wtconfig.get('ET.ArraySep'));
|
||||
result = ''
|
||||
if (end == -1)
|
||||
{ result = strStart.substring(7) }
|
||||
{
|
||||
result = strStart.substring(7);
|
||||
}
|
||||
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;
|
||||
case "TMDB Link":
|
||||
if (val == wtconfig.get('ET.NotAvail'))
|
||||
|
@ -495,8 +510,13 @@ const etHelper = new class ETHELPER {
|
|||
{ result = strStart.substring(7) }
|
||||
else
|
||||
{ result = strStart.substring(7, end) }
|
||||
|
||||
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;
|
||||
default:
|
||||
log.error(`postProcess no hit for: ${name}`)
|
||||
|
@ -543,17 +563,7 @@ const etHelper = new class ETHELPER {
|
|||
val = wtconfig.get('ET.NotAvail', 'N/A');
|
||||
}
|
||||
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} );
|
||||
|
||||
|
||||
break;
|
||||
case "array":
|
||||
array = JSONPath({path: key, json: data});
|
||||
|
@ -569,15 +579,7 @@ const etHelper = new class ETHELPER {
|
|||
valArrayVal = String(JSONPath({path: String(subKey), json: array[i]}));
|
||||
// Make N/A if not found
|
||||
valArrayVal = this.isEmpty( { val: 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} );
|
||||
|
||||
//valArrayVal = setQualifier( {str: valArrayVal} );
|
||||
break;
|
||||
case "time":
|
||||
valArrayVal = JSONPath({path: String(subKey), json: array[i]});
|
||||
|
@ -604,6 +606,7 @@ const etHelper = new class ETHELPER {
|
|||
valArray.push(valArrayVal)
|
||||
}
|
||||
val = valArray.join(wtconfig.get('ET.ArraySep', ' * '))
|
||||
val = setQualifier( {str: val} );
|
||||
/* if ( String(subType) == 'string')
|
||||
{
|
||||
val = textSep + val + textSep;
|
||||
|
@ -631,6 +634,7 @@ const etHelper = new class ETHELPER {
|
|||
{
|
||||
val = wtconfig.get('ET.NotAvail', 'N/A')
|
||||
}
|
||||
val = setQualifier( {str: val} );
|
||||
break;
|
||||
case "datetime":
|
||||
//val = JSONPath({path: String(lookup), json: data});
|
||||
|
@ -653,6 +657,7 @@ const etHelper = new class ETHELPER {
|
|||
{
|
||||
val = wtconfig.get('ET.NotAvail', 'N/A')
|
||||
}
|
||||
val = setQualifier( {str: val} );
|
||||
break;
|
||||
}
|
||||
if ( doPostProc )
|
||||
|
@ -889,7 +894,6 @@ const etHelper = new class ETHELPER {
|
|||
// Open a file stream
|
||||
this.Settings.csvFile = await etHelper.getFileName({ Type: 'csv' });
|
||||
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});
|
||||
}
|
||||
try
|
||||
|
@ -1048,7 +1052,6 @@ const etHelper = new class ETHELPER {
|
|||
|
||||
getElement(){
|
||||
let element
|
||||
console.log('Ged 12 element sectype: ' + this.Settings.libTypeSec)
|
||||
switch (this.Settings.libTypeSec) {
|
||||
case this.ETmediaType.Playlist_Photo:
|
||||
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)}`);
|
||||
}
|
||||
Object.keys(levels).forEach(function(key) {
|
||||
|
||||
//out.push(wtconfig.get(`ET.TextQualifierCSV`, "\"") + levels[key] + wtconfig.get(`ET.TextQualifierCSV`, "\""))
|
||||
out.push(levels[key])
|
||||
});
|
||||
resolve(out);
|
||||
|
|
Loading…
Reference in a new issue