From 40fb12039a50fa669a646d43a7595c907837c5ec Mon Sep 17 00:00:00 2001 From: Tommy Mikkelsen Date: Tue, 22 Feb 2022 15:58:01 +0100 Subject: [PATCH] #444 Movies done --- public/locales/en.json | 1 + .../modules/ExportTools/Settings/settings.vue | 7 ++- .../modules/ExportTools/scripts/ethelper.js | 59 +++++++------------ 3 files changed, 26 insertions(+), 41 deletions(-) diff --git a/public/locales/en.json b/public/locales/en.json index 3145168..7169199 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -144,6 +144,7 @@ "OrgTitleNull": "Default \"Original Title\" to \"Title\", if empty", "SortTitleNull": "Default \"Sort Title\" to \"Title\", if empty", "suggestedFileNoExtra": "For suggested filename strip extra info from filenames so only essential info is kept", + "suggestedUseOrigenTitle": "When suggesting file or foldername, use original title", "AutoXLSCol": "Autosize column (xlsx only)", "AutoXLSRow": "Autosize row (xlsx only)", "ExportToExcel": "Export to xlsx", diff --git a/src/components/modules/ExportTools/Settings/settings.vue b/src/components/modules/ExportTools/Settings/settings.vue index 9375f5c..08d7ef3 100644 --- a/src/components/modules/ExportTools/Settings/settings.vue +++ b/src/components/modules/ExportTools/Settings/settings.vue @@ -96,7 +96,8 @@ { text: i18n.t('Modules.ET.Settings.ExportToExcel'), value: 'ExpXLSX', disabled: true }, { text: i18n.t('Modules.ET.Settings.OrgTitleNull'), value: 'OrgTitleNull' }, { text: i18n.t('Modules.ET.Settings.SortTitleNull'), value: 'SortTitleNull' }, - { text: i18n.t('Modules.ET.Settings.suggestedFileNoExtra'), value: 'suggestedFileNoExtra' } + { text: i18n.t('Modules.ET.Settings.suggestedFileNoExtra'), value: 'suggestedFileNoExtra' }, + { text: i18n.t('Modules.ET.Settings.suggestedUseOrigenTitle'), value: 'suggestedUseOrigenTitle' } ], ChReturn: wtconfig.get('ET.ChReturn', ''), ChNewLine: wtconfig.get('ET.ChNewLine', ''), @@ -108,7 +109,7 @@ }, methods: { getDefaults(){ - const cbItems = ["ExpCSV","ExpXLSX", "OrgTitleNull", "SortTitleNull", "suggestedFileNoExtra"]; + const cbItems = ["ExpCSV","ExpXLSX", "OrgTitleNull", "SortTitleNull", "suggestedFileNoExtra", "suggestedUseOrigenTitle"]; for(let i = 0; i < cbItems.length; i++){ if (wtconfig.get("ET." + cbItems[i], false)){ this.cbSelected.push(cbItems[i]); @@ -121,7 +122,7 @@ }, filterTable(){ this.$nextTick(()=>{console.log(this.cbSelected);}) - for( var cbItem of ["ExpCSV","ExpXLSX","OrgTitleNull", "SortTitleNull", "AutoXLSCol", "AutoXLSRow", "suggestedFileNoExtra"]){ + for( var cbItem of ["ExpCSV","ExpXLSX","OrgTitleNull", "SortTitleNull", "AutoXLSCol", "AutoXLSRow", "suggestedFileNoExtra", "suggestedUseOrigenTitle"]){ wtconfig.set("ET." + cbItem, (this.cbSelected.includes(cbItem))) } }, diff --git a/src/components/modules/ExportTools/scripts/ethelper.js b/src/components/modules/ExportTools/scripts/ethelper.js index 7a0b059..33bc9ad 100644 --- a/src/components/modules/ExportTools/scripts/ethelper.js +++ b/src/components/modules/ExportTools/scripts/ethelper.js @@ -67,7 +67,21 @@ function setQualifier( {str:str}) // Returns a suggested title for a media function getSuggestedTitle( data ) { - return String(JSONPath({path: '$.data.title', json: data})).replace(/[/\\?%*:|"<>]/g, ' ').replace(' ', ' '); + let title; + if (wtconfig.get('ET.suggestedUseOrigenTitle', false)) + { + title = String(JSONPath({path: '$.data.originalTitle', json: data})).replace(/[/\\?%*:|"<>]/g, '').replace(' ', ' '); + } + else + { + title = String(JSONPath({path: '$.data.title', json: data})).replace(/[/\\?%*:|"<>]/g, '').replace(' ', ' '); + } + // Original selected, but none exist, we default to named title + if ( title === '') + { + title = String(JSONPath({path: '$.data.title', json: data})).replace(/[/\\?%*:|"<>]/g, '').replace(' ', ' '); + } + return title; } // Returns a suggested year for a media @@ -234,8 +248,10 @@ function stripPartsFromFileName( tmpFileName, title ) { } }); - // Remove partName from tmpFile - tmpFileName = tmpFileName.replace(partName, ''); + // Remove partName from tmpFile + // Get index of partName + const idx = tmpFileName.toUpperCase().indexOf(partName.toUpperCase()); + tmpFileName = tmpFileName.slice(0, idx) + tmpFileName.slice(idx + partName.length); // Remove white spaces tmpFileName = tmpFileName.trim(); if (tmpFileName.length === 1) @@ -408,7 +424,8 @@ const etHelper = new class ETHELPER { const year = getSuggestedYear( data ); const Id = getSuggestedId( data ).selId; // Get current folder name - const curFolderName = path.basename(path.dirname(String(JSONPath({path: "$.data.Media[*].Part[*].file", json: data})))) + //const curFolderName = path.basename(path.dirname(String(JSONPath({path: "$.data.Media[*].Part[*].file", json: data})))) + const curFolderName = path.basename(path.dirname(String(JSONPath({path: "$.data.Media[0].Part[0].file", json: data})))) // Compute suggested foldername let foldername = `${title} (${year}) ${Id}`; if (curFolderName === foldername) { @@ -423,47 +440,13 @@ const etHelper = new class ETHELPER { async getSuggestedFileName( data ) { const title = getSuggestedTitle( data ); - //const year = String(JSONPath({path: '$.data.year', json: data})); const year = getSuggestedYear( data ); - //const Id = getSuggestedId( data ); const Ids = getSuggestedId( data ); const Id = Ids.selId; const imdb = Ids.imdb; const tmdb = Ids.tmdb; const tvdb = Ids.tvdb; - - console.log('Ged 88-0 Suggested ID: ' + Id) - console.log('Ged 88-1 Suggested imdb: ' + imdb) - console.log('Ged 88-2 Suggested tmdb: ' + tmdb) - console.log('Ged 88-3 Suggested tvdb: ' + tvdb) - - -/* - // Sadly need below for stripping later - let imdb; - imdb = String(JSONPath({path: "$.data.Guid[?(@.id.startsWith('imdb'))].id", json: data})); - const tmdb = String(JSONPath({path: "$.data.Guid[?(@.id.startsWith('tmdb'))].id", json: data})); - const tvdb = String(JSONPath({path: "$.data.Guid[?(@.id.startsWith('tvdb'))].id", json: data})); - - - console.log('Ged 55 IMDB: ' + imdb) - if (imdb === ''){ - console.log('Ged 55-5 Maybe Legacy IMDB?') - console.log(JSON.stringify(data)) - imdb = String(JSONPath({path: "$.data.guid", json: data})); - console.log('Ged 55-6 imdb: ' + imdb) - imdb = imdb.substring(26,); - //imdb = imdb.slice(26); - console.log('Ged 55-6-2 imdb: ' + imdb) - imdb = imdb.split('?')[0]; - console.log('Ged 55-7 Legacy IMDB: ' + imdb) - - } - - - */ - // Get current filename const curFileName = path.parse(String(JSONPath({path: '$.data.Media[0].Part[0].file', json: data}))).name;