#398 first attempt

This commit is contained in:
UKDTOM 2022-01-05 23:14:47 +01:00
parent 03bd86c8aa
commit f3d23991b0
4 changed files with 77 additions and 147 deletions

View file

@ -366,6 +366,9 @@
case et.ETmediaType.Track:
reqType = et.ETmediaType.Artist;
break;
case et.ETmediaType.Playlist:
reqType = et.ETmediaType.Playlist;
break;
default:
reqType = this.selMediaType
}
@ -373,10 +376,8 @@
this.selLibrary = "";
await this.$store.dispatch('fetchSections')
const sections = await this.$store.getters.getPmsSections;
//const pListType = this.$store.getters.getSelectedPListType;
if (Array.isArray(sections) && sections.length) {
sections.forEach(req => {
//if (req.type == this.selMediaType) {
if (req.type == reqType) {
if (reqType == 'playlist')
{

View file

@ -4,25 +4,17 @@ var defFields = JSON.parse(JSON.stringify(require('./../defs/def-Fields.json')))
const log = require('electron-log');
console.log = log.log;
//const defpostURI = '?checkFiles=1&includeRelated=0&includeExtras=1&includeBandwidths=1&includeChapters=1'
import {wtconfig, wtutils} from '../../General/wtutils';
//import {etHelper} from './ethelper';
//import i18n from '../../../../i18n';
import i18n from '../../../../i18n'
import {ipcRenderer} from 'electron';
//const fs = require('fs');
var path = require("path");
const fetch = require('node-fetch');
const {JSONPath} = require('jsonpath-plus');
import axios from 'axios'
//import store from '../../../../store';
const et = new class ET {
constructor() {
@ -156,29 +148,7 @@ const et = new class ET {
},
this.StartTime = null,
this.EndTime = null,
this.OutFile = null,
this.revRawMsgTypeOLDDELGED = {
1: 'Status',
2: 'Info',
3: 'Chuncks',
4: 'Items',
5: 'OutFile',
6: 'StartTime',
7: 'EndTime',
8: '1TimeElapsed',
9: 'RunningTime'
},
this.msgTypeOLDDELGED = {
1: i18n.t("Modules.ET.Status.Names.Status"),
2: i18n.t("Modules.ET.Status.Names.Info"),
3: i18n.t("Modules.ET.Status.Names.Chuncks"),
4: i18n.t("Modules.ET.Status.Names.Items"),
5: i18n.t("Modules.ET.Status.Names.OutFile"),
6: i18n.t("Modules.ET.Status.Names.StartTime"),
7: i18n.t("Modules.ET.Status.Names.EndTime"),
8: i18n.t("Modules.ET.Status.Names.TimeElapsed"),
9: i18n.t("Modules.ET.Status.Names.RunningTime")
}
this.OutFile = null
}
@ -258,7 +228,7 @@ const et = new class ET {
return levelName;
}
async getSections(address, accessToken)
async DELOLD_getSections(address, accessToken)
{
// Returns an array of json, as:
// [{"title":"DVR Movies","key":31,"type":"movie"}]
@ -733,102 +703,6 @@ const excel2 = new class Excel {
}
}
async OLDDELforceDownload(url, target) {
const _this = this;
return new Promise((resolve, reject) => {
try
{
_this.isDownloading = true;
ipcRenderer.send('downloadFile', {
item: url,
filePath: target
})
}
catch (error)
{
log.error(`Exception in et.js forceDownload was: ${error}`);
}
ipcRenderer.on('downloadEnd', () => {
try
{
ipcRenderer.removeAllListeners('downloadEnd');
ipcRenderer.removeAllListeners('downloadError');
resolve(target);
}
catch (error)
{
log.error(`Exception in et.js forceDownload-downloadEnd was: ${error}`);
}
})
ipcRenderer.on('downloadError', (event, error) => {
ipcRenderer.removeAllListeners('downloadEnd');
ipcRenderer.removeAllListeners('downloadError');
reject(error);
})
})
}
async OLD_DELexportPics( { type: extype, data, baseURL, accessToken} ) {
let ExpDir, picUrl, resolutions;
log.verbose(`Going to export ${extype}`);
try
{
if (extype == 'posters')
{
picUrl = String(JSONPath({path: '$.thumb', json: data})[0]);
resolutions = wtconfig.get('ET.Posters_Dimensions', '75*75').split(',');
ExpDir = path.join(
wtconfig.get('General.ExportPath'),
wtutils.AppName,
'ExportTools', 'Posters');
}
else
{
picUrl = String(JSONPath({path: '$.art', json: data})[0]);
resolutions = wtconfig.get('ET.Art_Dimensions', '75*75').split(',');
ExpDir = path.join(
wtconfig.get('General.ExportPath'),
wtutils.AppName,
'ExportTools', 'Art');
}
}
catch (error)
{
log.error(`Exception in exportPics is: ${error}`);
}
log.verbose(`picUrl is: ${picUrl}`);
log.verbose(`resolutions is: ${JSON.stringify(resolutions)}`);
log.verbose(`ExpDir is: ${ExpDir}`);
// Create export dir
var fs = require('fs');
if (!fs.existsSync(ExpDir)){
fs.mkdirSync(ExpDir);
}
let key = String(JSONPath({path: '$.ratingKey', json: data})[0]);
let title = String(JSONPath({path: '$.title', json: data})[0]);
// Get resolutions to export as
for(let res of resolutions) {
const fileName = key + '_' + title.replace(/[/\\?%*:|"<>]/g, ' ').trim() + '_' + res.trim().replace("*", "x") + '.jpg';
let outFile = path.join(
ExpDir,
fileName
);
// Build up pic url
const width = res.split('*')[1].trim();
const hight = res.split('*')[0].trim();
let URL = baseURL + '/photo/:/transcode?width=';
URL += width + '&height=' + hight;
URL += '&minSize=1&url=';
URL += picUrl;
log.verbose(`Url for ${extype} is ${URL}`);
log.verbose(`Outfile is ${outFile}`);
URL += '&X-Plex-Token=' + accessToken;
await this.forceDownload(URL, outFile);
}
}
async sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);

View file

@ -813,18 +813,6 @@ const etHelper = new class ETHELPER {
return resp
}
async OLDDELGed_getItemData({ postURI=this.#_defpostURI })
{
log.debug(`etHelper (getItemData): Element is: ${this.Settings.element}`)
const url = this.Settings.baseURL + this.Settings.element + postURI;
this.PMSHeader["X-Plex-Token"] = this.Settings.accessToken;
log.verbose(`etHelper (getItemData): Calling url in getItemData: ${url}`)
let response = await fetch(url, { method: 'GET', headers: this.PMSHeader});
let resp = await response.json();
log.debug(`etHelper (getItemData): Response in getItemData: ${JSON.stringify(resp)}`)
return resp
}
async getLevelCall () {
if (this.Settings.libType == this.ETmediaType.Playlist)
{
@ -1087,6 +1075,10 @@ const etHelper = new class ETHELPER {
// Generate the filename for an export
async getFileName({ Type }){
if (this.Settings.libTypeSec == this.ETmediaType.Playlists)
{
this.Settings.LibName = 'All Playlists';
}
const dateFormat = require('dateformat');
const OutDir = wtconfig.get('General.ExportPath');
const timeStamp=dateFormat(new Date(), "yyyy.mm.dd_h.MM.ss");
@ -1114,8 +1106,71 @@ const etHelper = new class ETHELPER {
return outFileWithPath;
}
async getSections(address, accessToken)
{
// Returns an array of json, as:
// [{"title":"DVR Movies","key":31,"type":"movie"}]
const result = [];
let url = address + '/library/sections/all'
console.log('Ged 5-4 Type: ' + this.Settings.selType)
/*
if ([this.ETmediaType.Playlist_Audio, this.ETmediaType.Playlist_Video].includes(this.Settings.selType))
{
url = address + '/library/sections/all?type=15&sort=lastViewedAt:desc&playlistType=video,audio'
}
else
{
url = address + '/library/sections/all'
}
*/
this.PMSHeader["X-Plex-Token"] = accessToken;
let response = await fetch(url, { method: 'GET', headers: this.PMSHeader});
let resp = await response.json();
let respJSON = await Promise.resolve(resp);
let sections = await JSONPath({path: '$..Directory', json: respJSON})[0];
let section;
for (section of sections){
const subItem = {}
subItem['title'] = JSONPath({path: '$..title', json: section})[0];
subItem['key'] = parseInt(JSONPath({path: '$..key', json: section})[0]);
subItem['type'] = JSONPath({path: '$..type', json: section})[0];
subItem['scanner'] = JSONPath({path: '$..scanner', json: section})[0];
subItem['agent'] = JSONPath({path: '$..agent', json: section})[0];
result.push(subItem)
}
await Promise.resolve(result);
if ([this.ETmediaType.Playlist_Audio, this.ETmediaType.Playlist_Video].includes(this.Settings.selType))
{
url = address + '/playlists/all?type=15&sort=lastViewedAt:desc&playlistType=video,audio'
}
else
{
url = address + '/playlists'
}
response = await fetch(url, { method: 'GET', headers: this.PMSHeader});
resp = await response.json();
respJSON = await Promise.resolve(resp);
if (JSONPath({path: '$..size', json: respJSON})[0] > 0)
{
sections = await JSONPath({path: '$..Metadata', json: respJSON})[0];
for (section of sections){
const subItem = {}
subItem['title'] = JSONPath({path: '$..title', json: section})[0];
subItem['key'] = parseInt(JSONPath({path: '$..ratingKey', json: section})[0]);
subItem['type'] = JSONPath({path: '$..type', json: section})[0];
subItem['playlistType'] = JSONPath({path: '$..playlistType', json: section})[0];
result.push(subItem)
}
}
return result
}
getElement(){
let element
console.log('Ged 11 SecType: ' + this.Settings.libTypeSec)
switch (this.Settings.libTypeSec) {
case this.ETmediaType.Playlist_Photo:
element = `/playlists/${this.Settings.selLibKey}/items`;

View file

@ -1,6 +1,6 @@
//import {et, excel2} from '../../components/modules/ExportTools/scripts/et'
import {et} from '../../components/modules/ExportTools/scripts/et'
//import { etHelper } from '../../components/modules/ExportTools/scripts/ethelper'
//import {et} from '../../components/modules/ExportTools/scripts/et'
import { etHelper } from '../../components/modules/ExportTools/scripts/ethelper'
const log = require('electron-log');
console.log = log.log;
@ -49,7 +49,7 @@ const actions = {
log.info("fetchSections called")
var baseURL = getters.getSelectedServerAddress
var accessToken = getters.getSelectedServerToken
commit('UPDATE_SECTIONS', await et.getSections(baseURL, accessToken))
commit('UPDATE_SECTIONS', await etHelper.getSections(baseURL, accessToken))
}
}