This commit is contained in:
Tommy Mikkelsen 2022-06-21 00:26:08 +02:00
parent cee0d362f3
commit ed56a6e960
4 changed files with 253 additions and 56 deletions

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "webtools-ng",
"version": "0.3.17",
"version": "0.3.18",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "webtools-ng",
"version": "0.3.17",
"version": "0.3.18",
"hasInstallScript": true,
"license": "MPL-2.0",
"dependencies": {

View file

@ -26,9 +26,15 @@ const pms = new class PMS {
sections.forEach(req => {
if ( libTypes.includes(req.type)){
log.debug(`[pms.js] (getPMSSections) - pushing library: ${req.title} to results`);
console.log('Ged 22-4: ' + JSON.stringify(req))
let item = [];
let itemVal = {};
itemVal['key'] = JSONPath({path: '$..key', json: req})[0];
itemVal['location'] = JSONPath({path: '$..path', json: req.location});
itemVal['type'] = JSONPath({path: '$..type', json: req})[0];
item['text']=req.title;
item['value']=JSONPath({path: '$..path', json: req.location});
//item['value']=JSONPath({path: '$..path', json: req.location});
item['value']=itemVal;
result.push(Object.assign({}, item));
}
});

View file

@ -29,6 +29,14 @@
</div>
</div>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<statusDiv /> <!-- Status Div -->
</b-container>
</template>
@ -38,13 +46,16 @@
import { dialog } from '../../General/wtutils';
import { pms } from '../../General/pms';
import { findMedia } from './scripts/FindMedia.js';
import statusDiv from '../../General/status.vue';
i18n
const log = require("electron-log");
export default {
components: {
statusDiv
},
data() {
return {
serverIsSelected: false,
@ -79,7 +90,7 @@
async runFM() {
log.info(`[FindMedia.vue] (runFM) starting`);
// Check if we have all lib paths mapped
const mappedPathOK = await findMedia.checkPathMapping( this.selLib );
const mappedPathOK = await findMedia.checkPathMapping( this.selLib["location"] );
if ( mappedPathOK === 'WTNG_ERROR_WTNG')
{
log.error(`[FindMedia.vue] (runFM) - Missing mapped path for: ${mappedPathOK}`);
@ -87,7 +98,10 @@
}
else{
log.info(`[FindMedia.vue] (runFM) mappedPath is okay`);
await findMedia.scanFileSystemPaths( this.selLib );
//await findMedia.scanFileSystemPaths( this.selLib );
console.log('Ged 333-3 selLibOptions: ' + JSON.stringify(this.selLibOptions))
await findMedia.findMedia( this.selLib["location"], this.selLib["key"], this.selLib["type"] );
console.log('Ged 333-7 ended')
}
},

View file

@ -5,9 +5,44 @@ console.log = log.log;
const fs = require("fs");
const path = require("path");
const {JSONPath} = require('jsonpath-plus');
//var recursive = require("recursive-readdir");
//import { resolve } from 'core-js/fn/promise';
import store from '../../../../../store';
import { wtconfig } from '../../../General/wtutils';
import { wtutils,wtconfig } from '../../../General/wtutils';
import { status } from '../../../General/status';
import i18n from '../../../../../i18n';
import { resolve } from 'path';
import axios from 'axios';
/*
Recursive scanning of a filepath
Takes dirPath and orgDirPath as parameter
for the starting dir. (Should be the same)
Will return an raw array, as well as populate
findMedia.filesFound array
*/
const getAllFiles = function( dirPath, orgDirPath, arrayOfFiles ) {
var files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function(curFile) {
if (fs.statSync(dirPath + "/" + curFile).isDirectory()) {
arrayOfFiles = getAllFiles(path.join(dirPath, curFile), orgDirPath, arrayOfFiles)
} else {
if (findMedia.validExt.includes(path.extname(curFile).slice(1)))
{
arrayOfFiles.push(path.join(dirPath, curFile));
log.silly(`[FindMedia.js] (getAllFiles) - Adding ${path.join(dirPath, curFile).slice(orgDirPath.length + 1)}: ${ path.join(dirPath, curFile) }`);
findMedia.filesFound[path.join(dirPath, curFile).slice(orgDirPath.length + 1)] = path.join(dirPath, curFile);
}
}
})
return arrayOfFiles
}
const findMedia = new class FINDMEDIA {
constructor() {
@ -19,6 +54,33 @@ const findMedia = new class FINDMEDIA {
];
this.libPaths = [];
this.filePath = [];
this.ignoreExt = ["*.cs", "*.html", "*.mkvfixed", "*.srt", "*.metathumb"];
this.currentLibPathLength;
this.filesFound = {};
this.libFiles = [];
this.PMSLibPaths = [];
}
async findMedia( libpaths, libKey, libType ){
console.log('Ged 54-4 libpaths: ' + libpaths)
console.log('Ged 54-5 libkey: ' + libKey)
console.log('Ged 54-6 libkey: ' + libType)
status.updateStatusMsg( status.RevMsgType.Status, i18n.t('Common.Status.Msg.Processing'));
// await findMedia.scanFileSystemPaths( libpaths );
console.log('Ged 54-10: ' + this.filePath.length )
console.log('Ged 54-11: ' + JSON.stringify( this.filesFound ) )
await findMedia.scanPMSLibrary(libKey, libType);
status.clearStatus();
status.updateStatusMsg( status.RevMsgType.Status, i18n.t('Common.Status.Msg.Finished'));
}
/*
@ -49,34 +111,6 @@ const findMedia = new class FINDMEDIA {
}
resolve (retVal);
});
}
/*
Reqursive scanning of a filepath
Takes dirPath as parameter
Will store output in this.filePath
*/
doScanPath( dirPath, arrayOfFiles ){
//return new Promise((resolve) => {
console.log('Ged 13-0 start')
console.log('Ged 13-1 dirPath: ' + dirPath)
console.log('Ged 13-2 arrayOfFiles: ' + arrayOfFiles)
fs, path
// resolve();
// });
}
/// This will scan the filesystem for medias
@ -84,27 +118,117 @@ const findMedia = new class FINDMEDIA {
return new Promise((resolve) => {
log.info(`[FindMedia.js] (scanFileSystemPaths) - Starting`);
log.debug(`[FindMedia.js] (scanFileSystemPaths) - We will scan the following filePaths: ${ JSON.stringify(paths)}`);
let retVal = [];
status.updateStatusMsg( status.RevMsgType.Info, 'GED Scanning FileSystem');
// Reset output
this.filePath = [];
// First we need to check if libPath Mappings has been defined, and if not, alert user
// To do this, we need the selected servers ID
// Get ServerID
findMedia.filePath = [];
const serverID = store.getters.getSelectedServer.clientIdentifier;
// Check that all paths are mapped
paths.forEach(libPath => {
//this.filePath = [];
//Walk each paths
paths.forEach(async libPath => {
let mappedLibPath = wtconfig.get(`PMS.LibMapping.${serverID}.${libPath}`, 'WTNG_ERROR_WTNG');
status.updateStatusMsg( status.RevMsgType.Info, `Now Scanning ${mappedLibPath}`);
log.debug(`[FindMedia.js] (scanFileSystemPaths) - PMS path is: ${libPath}`);
log.debug(`[FindMedia.js] (scanFileSystemPaths) - Wkstn path is: ${mappedLibPath}`);
this.filePath.push('Gummiged')
this.doScanPath( mappedLibPath, this.filePath );
console.log('Ged 55: ' + JSON.stringify( this.filePath ))
findMedia.filePath.push(...getAllFiles( mappedLibPath, mappedLibPath ));
});
log.info(`[FindMedia.js] (scanFileSystemPaths) - End`);
resolve();
});
}
/*
This will scan the PMS library, and add result to this.libPaths,
if not present in this.filePath.
If present, then pop it from this.filePath
*/
async scanPMSLibrary( library, libType ){
log.info(`[FindMedia.js] (scanPMSLibrary) - Starting`);
log.verbose(`[FindMedia.js] (scanPMSLibrary) - We will scan library with a key of: ${ library } and a type of: ${libType}`);
status.updateStatusMsg( status.RevMsgType.Info, 'GED Scanning PMS Library');
await findMedia.getPMSPathArr();
findMedia.libFiles = [];
// We need to find type of lib, and total count as well
let index = 0;
let step = 0;
let size = 0;
let totalSize = 0;
let mediaType = 1;
if ( libType === 'show'){
mediaType = 4;
}
let url = `${store.getters.getSelectedServerAddress}/library/sections/${library}/all?excludeElements=Genre,Director,Writer,Country,Role,Producer,Collections&excludeFields=summary,tagline,rating,contentRating,audienceRatingImage&X-Plex-Container-Start=${index}&X-Plex-Container-Size=${step}&type=${mediaType}`
let header = wtutils.PMSHeader;
header['X-Plex-Token'] = store.getters.getSelectedServer.accessToken;
await axios({
method: 'get',
url: url,
headers: header
})
.then((response) => {
log.debug('[FindMedia.js] (scanPMSLibrary) - Response recieved');
log.silly(`[FindMedia.js] (scanPMSLibrary) - Response returned as: ${JSON.stringify(response.data)}`);
totalSize = JSONPath({path: `$.MediaContainer.totalSize`, json: response.data})[0];
if ( JSONPath({path: `$.MediaContainer.viewGroup`, json: response.data})[0] === 'show'){
mediaType = 4;
}
})
.catch(function (error) {
if (error.response) {
log.error(`[FindMedia.js] (scanPMSLibrary) - ${JSON.stringify(error.response.data)}`);
alert(error.response.data.errors[0].code + " " + error.response.data.errors[0].message);
} else if (error.request) {
log.error(`[FindMedia.js] (scanPMSLibrary) - ${JSON.stringify(error.request)}`);
} else {
log.error(`[FindMedia.js] (scanPMSLibrary) - ${JSON.stringify(error.message)}`);
}
});
resolve(retVal);
});
// step = wtconfig.get("PMS.ContainerSize." + mediaType, 20);
step = 4;
console.log('Ged 10-6 step: ' + step)
let metaData;
do {
url = `${store.getters.getSelectedServerAddress}/library/sections/${library}/all?excludeElements=Genre,Director,Writer,Country,Role,Producer,Collections&excludeFields=summary,tagline,rating,contentRating,audienceRatingImage&X-Plex-Container-Start=${index}&X-Plex-Container-Size=${step}&type=${mediaType}`;
console.log('Ged 77-1 index: ' + index)
status.updateStatusMsg( status.RevMsgType.Items, i18n.t('Common.Status.Msg.ProcessItem_0_1', {count: index, total: totalSize}));
log.verbose(`[FindMedia.js] (scanPMSLibrary) - Calling url: ${ url } `);
await axios({
method: 'get',
url: url,
headers: header
})
.then((response) => {
log.debug('[FindMedia.js] (scanPMSLibrary) - Response recieved');
log.silly(`[FindMedia.js] (scanPMSLibrary) - Response returned as: ${JSON.stringify(response.data)}`);
size = JSONPath({path: `$.MediaContainer.size`, json: response.data})[0];
metaData = JSONPath({path: `$.MediaContainer.Metadata`, json: response.data})[0];
for (var idxMetaData in metaData)
{
//console.log('Ged 13-3 media: ' + JSON.stringify(metaData[parseInt(x)]))
var title = JSONPath({path: `$..title`, json: metaData[parseInt(idxMetaData)]})[0];
var files = JSONPath({path: `$..Part[*].file`, json: metaData[parseInt(idxMetaData)]});
console.log('Ged 13-5 title: ' + title)
// console.log('Ged 13-6 files: ' + files)
for (var idxFiles in files){
console.log('Ged 13-4 file: ' + files[idxFiles])
console.log('Ged 11-2 path.length: ' + this.PMSLibPaths.length)
for (var idxPMSLibPaths in this.PMSLibPaths){
console.log('Ged 11-3 path: ' + this.PMSLibPaths[idxPMSLibPaths])
}
@ -112,6 +236,59 @@ const findMedia = new class FINDMEDIA {
}
index += step;
})
.catch(function (error) {
if (error.response) {
log.error(`[FindMedia.js] (scanPMSLibrary) - ${JSON.stringify(error.response.data)}`);
alert(error.response.data.errors[0].code + " " + error.response.data.errors[0].message);
} else if (error.request) {
log.error(`[FindMedia.js] (scanPMSLibrary) - ${JSON.stringify(error.request)}`);
} else {
log.error(`[FindMedia.js] (scanPMSLibrary) - ${JSON.stringify(error.message)}`);
}
});
console.log('Ged 99-20: ' + size + ' * ' + step)
} while ( size == step );
console.log('Ged 99-30 LibFiles: ' + JSON.stringify(findMedia.libFiles))
log.info(`[FindMedia.js] (scanPMSLibrary) - End`);
resolve();
}
/*
This will populate this.PMSLibPaths
with an array of library paths used
*/
async getPMSPathArr(){
// Reset property
this.PMSLibPaths = [];
// Start by getting Server ID
const serverID = store.getters.getSelectedServer.clientIdentifier;
// Now lookup defined mappings, so we can add them to the array
let mappedLibPaths = wtconfig.get(`PMS.LibMapping.${serverID}`, 'WTNG_ERROR_WTNG');
//this.PMSLibPaths.push(Object.keys(mappedLibPaths));
console.log('Ged 7-3 mappedLibPaths: ' + mappedLibPaths)
console.log('Ged 7-4 keys: ' + Object.keys(mappedLibPaths))
for (var idxPath in Object.keys(mappedLibPaths)){
console.log('Ged 7-10 item: ' + Object.keys(mappedLibPaths)[idxPath])
}
this.PMSLibPaths.push(Object.keys(mappedLibPaths).split(","));
resolve();
}
}
export { findMedia };